I am using the IR sensor on my Arduino to turn on/off LED's and make 2 short beeps with the buzzer and I am having an issue. So I have all my code working fine so far except at the bottom where the buzzer comes into play. The buzzer beeps , but won't stop until another button is hit or I reset/reupload the code. I have tried to use noTone() but I can't get it to work. Maybe someone can point out where I'm going wrong? Code is below:
/*
Date: Nov 7/2018
IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
An IR detector/demodulator must be connected to the input RECV_PIN.
Version 0.1 July, 2009
Copyright 2009 Ken Shirriff
http://arcfn.com
*/
#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
/*
COLOUR VALUES
(Turn on RedLED) = 16724175
(Turn off RedLED) = 16713975
(Turn on BlueLED) = 16756815
(Turn off BlueLED) = 16746615
(Buzzer Sound) = 4294967295
*/
int RECV_PIN = 6;
int blueLedPin = 13;
int redLedPin = 12;
int buzzerPin = 5 ; //The buzzerPin is connected to pin 5 of the Arduino.
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
// In case the interrupt driver crashes on setup, give a clue
// to the user what's going on.
Serial.println("Enabling IRin");
irrecv.enableIRIn(); // Start the receiver
Serial.println("Enabled IRin");
pinMode(blueLedPin, OUTPUT); //Setup Blue LED pin as an output pin.
pinMode(redLedPin, OUTPUT); //Setup Red LED pin as an output pin.
pinMode(buzzerPin, OUTPUT); //Setup Buzzer pin as an output pin.
}
void loop() {
if (irrecv.decode(&results))
{
Serial.println(results.value, DEC);
irrecv.resume(); // Receive the next value
}
delay(100);
if (results.value == 16724175)// turn on RedLED.
{
digitalWrite(12, HIGH);
}
if (results.value == 16713975)// turn off RedLED.
{
digitalWrite(12, LOW);
}
if (results.value == 16756815)// turn on BlueLED.
{
digitalWrite(13, HIGH);
}
if (results.value == 16746615)// turn off BlueLED.
{
digitalWrite(13, LOW);
}
if (results.value == 4294967295)//BUZZER SOUND.
{
tone(buzzerPin, 1000, 100);
delay(100);
noTone(buzzerPin);
}
}
As you can see, I want the beeping to stop after the delay...