hello I've wrote this code parts of it I've copied and pasted from online sources.
My problem is that when i press the button that ring the buzzer it will ring then it will not accept pressing any more buttons on the IR remote unless i restart the device any suggestions what could be the reason?
#include <IRremote.h>
#include <Servo.h>
const byte IR_RECEIVE_PIN = 2;
#define LED1 8
#define LED2 9
#define LED3 3
#define LED4 13
Servo myservo;
int pos = 0;
int buzzer = 7;
void setup()
{
Serial.begin(9600);
Serial.println("IR Receive test");
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
myservo.attach(5);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
}
void loop()
{
if (IrReceiver.decode())
{
String ir_code = String(IrReceiver.decodedIRData.command, HEX);
Serial.println(ir_code);
if(ir_code == "16")
{digitalWrite(LED1, HIGH);}
else if(ir_code == "19")
{digitalWrite(LED1, LOW);}
if(ir_code == "c")
{digitalWrite(LED2, HIGH);}
else if(ir_code == "18")
{digitalWrite(LED2, LOW);}
if(ir_code == "8")
{digitalWrite(LED3, HIGH);}
else if(ir_code == "1c")
{digitalWrite(LED3, LOW);}
if(ir_code == "42")
{digitalWrite(LED4, HIGH);}
else if(ir_code == "52")
{digitalWrite(LED4, LOW);}
if (ir_code == "5e") // change according to your IR remote button number
{
for (pos = 0; pos <= 180; pos += 5) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
else if (ir_code == "5a") // change according to your IR remote button number
{
for (pos = 180; pos >= 0; pos -= 5) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
if (ir_code == "4a"){
int i=0;
do {
i++;
tone (buzzer, 450);
delay (200);
noTone (buzzer);
delay (200);
}while(i<3);}
else if(ir_code =="52"){
int i=0;
do {
i++;
tone (buzzer, 450);
delay (200);
noTone (buzzer);
delay (200);
}while(i<5);}
IrReceiver.resume();
}}