I am fairly new to Arduinos. I have an Aruino Mega 2560 (Amazon.com: KEYESTUDIO Mega 2560 R3 Board for Arduino Projects with USB Cable : Electronics ). I bought a set of IR receivers and transmitters (Amazon.com: Gikfun Digital 38khz Ir Receiver Ir Transmitter Sensor Module Kit for Arduino (Pack of 3 sets) EK8477 : Electronics ). For now I am just interested in using the receiver. I have a couple of IR remote controllers that I use for things like lights and a electronic fire place. I am using hte 5v on the board to power a receiver. This is my code (found How to Set Up an IR Remote and Receiver on an Arduino - Circuit Basics )
#include <IRremote.h>
const int RECV_PIN = 42;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
}
void loop(){
if (irrecv.decode(&results)){
Serial.println(results.value, HEX);
irrecv.resume();
}
}
I have tried various pins instead of 42.
When I press a button on a remote, then an led on the receiver module does light up. In the serial monitor on the computer I either get nothing, a zero (0), or a string of characters.
I have verified that the serial monitor is also set to the baud rate 9600.
What might I be doing wrong?
EDIT: I have doubled checked that group and 5v are connected right. I have tried different wires.
Why do you think you are doing something wrong? Your description seems perfectly normal.
I guess I was expecting the outputs to be like the website (How to Set Up an IR Remote and Receiver on an Arduino - Circuit Basics ) describes. And I am not seeing that. Does that make sense?
They show more than one program listing. Which one are you using? Are your components 100% like the web site?
The program I used was the one I quoted above. So the code is
#include <IRremote.h>
const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
}
void loop(){
if (irrecv.decode(&results)){
Serial.println(results.value, HEX);
irrecv.resume();
}
}
The website says this should produce something like
Instead I am getting either (1) nothing, (2) a zero (0), or (3) a string of random characters.
My connections are like they show here
The only difference is that I am using an Arduino Mega 2560. I am using pin 42 (since I assumed pin 7 being PWM wouldn't work).
Does this make sense?
Try this code at loop():
void loop() {
if (IrReceiver.decode()) {
Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
irrecv.resume();
}
}
ruilviana:
Try this code at loop():
This seemed to do it. I am now getting something like what is shown. I am still getting a zero on a line and then the code below.
Thank you!
Complete code:
Simulated at :
Run IoT and embedded projects in your browser: ESP32, STM32, Arduino, Pi Pico, and more. No installation required!
#include <IRremote.h>
const int RECV_PIN = 42;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
}
void loop() {
if (IrReceiver.decode()) {
Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
irrecv.resume();
}
}
Awesome. Thank you so much for this.