Paso 2: codificación
float sinVal; int toneVal; void setup(){ pinMode(8, OUTPUT); //Set the buzzer pin as output Serial.begin(9600); //Set the baud to 9600}void loop(){ int sensorValue = analogRead(0);//Read the Analog value from Flame sensorSerial.println(sensorValue); delay(1); if(sensorValue < 1023){ // If the value is less than 1023, the fire exists and let the buzzer run. for(int x=0; x<180; x++){ //Change from degree to radian using sin() function sinVal = (sin(x*(3.1412/180))); //Create the frequency for the buzzer. toneVal = 2000+(int(sinVal*1000)); //Run the buzzer. tone(8, toneVal); delay(2); } } else { // If the value is more than 1023, the fire doesn’t exists and let the buzzer stop. noTone(8); //Turn off the buzzer }}
Intente mover el encendedor cerca del sensor de llama y saber si va a funcionar el timbre.