int flame=A0;
int buzz=2;
void setup()
{
pinMode(flame,INPUT);
pinMode(buzz, OUTPUT);
Serial.begin(9600);
}
void loop()
{
// These constants should match the photoresistor's "gamma" and "rl10" attributes
const float GAMMA = 0.7;
const float RL10 = 50;
// Convert the analog value into lux value:
int analogValue = analogRead(flame);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.println(lux);
if(lux>=1000.0)
{
tone(buzz, 31);
}
else if ( lux < 1000.0)
{
noTone(buzz);
}
}