2

i'm trying to play a passive buzzer with an IR reciver

My Code


#include <IRremote.h>
IRrecv irrecv(10);
decode_results results;
void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);
 pinMode(11, OUTPUT);//buzzer
 irrecv.enableIRIn();//Ir reciver at pin 10
}
int cmdex = 0;
void loop() {
 // put your main code here, to run repeatedly:
 if(irrecv.decode(&results)){
 cmdex = 1;
 Serial.println(results.value);
 unsigned long data = results.value;
 switch(data){
 case 0xFF30CF:
 noTone(11);
 tone(11, 1056);
 break;
 case 0xFF18E7:
 noTone(11);
 tone(11, 571);
 break;
 case 0xFF6897:
 noTone(11);
 break;
 }
 irrecv.resume();
 }
}

Issue

My problem is that if i use any button instead of 1 (FF30CF) 0 (FF6897) or 2 (FF18E7) the serilal port give me the right data, then when i pusch 1 the buzzer starts to play but when i push another button, the data keep changing at every push.

Serial Output FF10EF (here I push 4)

FF38C7 (here I push 5)

FF5AA5 (here I push 6)

FF30CF (here I finally push 1 and the buzzer starts to play)

(then I push 3 times 0, but the output is different from the expected FF6897 and the buzzer doesn't stop)

D965AA42

EB670632

AB03A967

Note

  • I'm using the IRremote.h library
asked Sep 5, 2021 at 19:29
2

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.