Using IR Remote Con...
 
Notifications
Clear all

Using IR Remote Controls with the Arduino

27 Posts
6 Users
2 Likes
3,653 Views
(@dronebot-workshop)
Workshop Guru Admin
Joined: 5 years ago
Posts: 1075
Topic starter  

Learn to decode, emulate, and use infrared remote controls in your next Arduino project.

Get all the code at https://dbot.ws/irarduino

Infrared remote controls are everywhere, you probably have several of them in your home. These handy devices work by sending coded signals with pulses of infrared light to control appliances. We take them for granted but just imagine using your television or Blu-Ray player without one!

In this video, I’ll show you how these handy devices work and how you can capture and decode their codes with an Arduino and some very inexpensive parts. You’ll also learn how to repurpose the remote controls you already own so that you can put those unused buttons to work controlling devices like lights and fans.

I’ll also show you how you can use an Arduino to build your own custom IR Remote Control. Control everything in your room with one button (if that's what you want to do).

Finally, we will see how to use those inexpensive remotes that you can get on eBay to add remote control capabilities to your own Arduino projects. I’ll present a simple project that uses one of those controls to adjust the position of a servo motor. It even uses the “repeat” function that isn’t very well documented.

Here is a breakdown of what we will cover in the video:

00:00 - Introduction
02:20 - How IR Remotes work
03:37 - How to “see” Infrared Light
04:56 - The IR Sensor
06:29 - Decoding IR Remote codes
10:07 - Getting Manufacturers Codes
13:22 - Repurposing an IR Remote
20:37 - Building a Custom IR Control
28:19 - Control a Servo

As always you’ll find an article with all of the code used here on the DroneBot Workshop website at https://dbot.ws/irarduino. The site also has links to resources you may need when working with IR Remote controls.

Now go ahead and start controlling your world!

 

"Never trust a computer you can’t throw out a window." — Steve Wozniak


   
Quote
(@groove)
Member
Joined: 3 years ago
Posts: 6
 

I relatively new to Arduino (and programming in general) and these videos are FANTASTIC!

I'm trying to find the 'codes' that my IR Remote is sending.  

I've started by using the first simple Ardunio sketch 'IR-Rcv-Demo1.ino' which uses the <IRremote.h> library.

The sketch seems to compile/upload successfully, but the serial output is always '0' no matter which button is pressed on the remote.

example:
14:00:02.933 -> 0
14:00:03.034 -> 0
14:00:03.171 -> 0
14:00:03.272 -> 0
14:00:03.374 -> 0
14:00:03.475 -> 0
14:00:04.089 -> 0
14:00:04.123 -> 0
14:00:04.261 -> 0
14:00:04.364 -> 0
14:00:04.467 -> 0
14:00:05.676 -> 0

I've tried several similar sketches and I've tried different remotes but all end with the same results.

Any ideas as to what might be the issue?

Note: My board is Mega2560 (though I've tried using an Arduino Nano board with the same results).

 

Thanks,

-Groove


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@groove

Can you send a copy of your code?  Hard to know what is going wrong from "the output is always 0!"

SteveG


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@groove

And by the way, Welcome to the Forum!  You are almost guaranteed to learn a lot here. 

SteveG


   
ReplyQuote
(@groove)
Member
Joined: 3 years ago
Posts: 6
 

@codecage

 

Hi There, Thanks for getting back to me!  Here's my code; note it's exactly the same as the first example in the video, except for the data pin:

 

/*
IR Receiver Demonstration 1
IR-Rcv-Demo1.ino
Demonstrates IR codes with IR Receiver
Displays results on Serial Monitor

DroneBot Workshop 2017
http://dronebotworkshop.com
*/

// Include IR Remote Library by Ken Shirriff
#include <IRremote.h>

// Define sensor pin
const int RECV_PIN = 7;

// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup(){
// Serial Monitor @ 9600 baud
Serial.begin(9600);
// Enable the IR Receiver
irrecv.enableIRIn();
}

void loop(){
if (irrecv.decode(&results)){
// Print Code in HEX
Serial.println(results.value, HEX);
irrecv.resume();
}
}

 

 

 

 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@groove

Check all your hardware connections?

Use webcam or digital camera to look at the remote output to see if it is working.

Previous thread on topic,
https://forum.dronebotworkshop.com/arduino/ir-modual/#post-11780

For nicer looking code,
https://forum.dronebotworkshop.com/question-suggestion/sticky-post-for-editing/#post-4939

 

/*
IR Receiver Demonstration 1
IR-Rcv-Demo1.ino
Demonstrates IR codes with IR Receiver
Displays results on Serial Monitor

DroneBot Workshop 2017
 http://dronebotworkshop.com 
*/

// Include IR Remote Library by Ken Shirriff
#include <IRremote.h>

// Define sensor pin
const int RECV_PIN = 7;

// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup(){
  // Serial Monitor @ 9600 baud
  Serial.begin(9600);
  // Enable the IR Receiver
  irrecv.enableIRIn();
}

void loop(){
  if (irrecv.decode(&results)){
  // Print Code in HEX
  Serial.println(results.value, HEX);
  irrecv.resume();
  }
}

 

 

 

 


   
ReplyQuote
(@groove)
Member
Joined: 3 years ago
Posts: 6
 

Hmmmm.  This is very strange.

FYI:  I have now found/tried several versions of an 'IR Reading' sketch and they all have the same results. 

-They all give me a default value of '0' ; (or using the example that was referenced in the previous message I get a value of 'default').

The actual 'hardware' setup is very straight forward. The Arduino controller is seeing the data pin as I am getting some feedback showing me that a button was pressed on the remote.  I'm not sure what else to look for.

 

I'm starting to wonder if it might be the IR Sensor itself? (or maybe the bit count issue)?  It's as if the sketch can't translate the value being received by the IR Sensor.

From the examples that I've seen on the Web & Youtube - this should be a pretty straight forward and easy thing to accomplish.

 

I really appreciate any insights that you might come up with. Thanks again.


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@groove

Well it certainly looks identical!  Except the pin number.  I need to ask just in case, you did wire your signal out of the IR sensor to Pin 7 of your UNO didn't you?  Sorry, but I had to ask.

I'm really busy at the moment, so if I'm able I'll try to set this up and try it.  I did it sometime ago and it worked fine as best I remember it, but maybe someone else can chime it here if it takes me too long to give it a try.

What IR receiver are you using and also what type of transmitter?

SteveG


   
ReplyQuote
(@groove)
Member
Joined: 3 years ago
Posts: 6
 

Hi Steve,

Yeah, the 'wiring' is correct (as I'm getting some feedback to the Serial Monitor when I press a button on the remote).  The sketch is seeing something from the IR Sensor, it just can process it.

-For the IR Sensor - there are no real distinguishing markings except for the '1838' (so I'm assuming it's a 38bit). The IR Sensor came with the Arduino Starter Kit that I bought when I first started trying to learn Ardunio.

-I've tried several different handheld Remote Control units. (2 Sony TV Remotes as well as 2 different Comcast Remotes).

Also, just for fun - I changed the sensor pin back to '11' just in case - same results. 

I appreciate you taking a look at it for me when you can.  

Thanks,

 

-Groove on.

 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@groove

This setup works fine.

Note I use pin 9

 

/*
  IR Receiver Demonstration 1
  IR-Rcv-Demo1.ino
  Demonstrates IR codes with IR Receiver
  Displays results on Serial Monitor
 
  DroneBot Workshop 2017
   http://dronebotworkshop.com 
*/
 
// Include IR Remote Library by Ken Shirriff
#include <IRremote.h>
 
// Define sensor pin
const int RECV_PIN = 9;
 
// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;
 
 
void setup(){
  // Serial Monitor @ 9600 baud
  Serial.begin(9600);
  // Enable the IR Receiver
  irrecv.enableIRIn();
}
 
void loop(){
  if (irrecv.decode(&results)){
    // Print Code in HEX
        Serial.println(results.value, HEX);
        irrecv.resume();
  }
}

IR ModuleReceiver

 

 

 


   
ReplyQuote
(@groove)
Member
Joined: 3 years ago
Posts: 6
 

Thanks for ALL the help today with this IR Remote Sensor issue!

I tried the code/setup from robotBuilder tonight and it resulted in the same Serial Monitor output (nothing but '0').

I went ahead and ordered a couple more IR Sensors today from Amazon (delivery on Weds 01/20/21).

I will update this post once I try a new IR Sensor as it seems to be the obvious next thing to change.

Once again, thanks for the input everyone!

-Groove Out

 


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@robotbuilder @groove

Thanks for giving it a try Robotbuilder and verifying everything works!  Might have been a day or two before I could have gotten to it.  And Groove it looks like it might be the sensor as you have now surmised,  Good luck with the new ones you have ordered.

SteveG


   
ReplyQuote
(@groove)
Member
Joined: 3 years ago
Posts: 6
 

Hello Everyone,

I finally had a chance to work on this issue again this morning and I eventually found the problem.

To recap: I was trying to simply read the 'codes' that were being sent by a TV Remote Control using the <IRremote.h> library.  No matter which sketch or Ardunio controller I used I would always get the same results; nothing but '0' being displayed in the Serial Monitor.  🙁

I tried several different configurations to no avail:

- Multiple sketches - nope

- 3 x different Arduino controllers - nope.

- 3 x different IR Sensors - nope.

- I even installed the Arduino IDE onto a new computer and set it up from scratch to see if it was a corrupt installation - nope.

It turns out the issue was with the version of the <IRremote.h> library!   I originally had the most recent version installed (2.8.1). 

The fix was to roll back the <IRremote.h> version.  I'm now using 2.0.1 and it's working perfectly.

Thanks again for everyone's help in trying to solve this issue!

Onward and Upward.

 

This post was modified 3 years ago by Groove

   
Centari reacted
ReplyQuote
(@alain)
Member
Joined: 3 years ago
Posts: 3
 

@ Groove

Hi, thanks for posting your problem and the solution.

The last 2 weeks I was struggling with exact the same problem

I Tried several pins, boards, programs always with result 0 in the serial monitor.

After reverting the library to version 2.0.1 all is working well !

 

Still, as a point of interest, If I used the latest version 2.8.1 and the sample code from the library I also would get only zeros as a result. Isn't that Strange ?

 


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@groove and @alain

I see there have been 7 revision changes from 2.0.1 and 2.8.1.  Did either of you walk through all the revision changes from 2.0.1 up to 2.8.1 to see at what point things quit working?

Might make an interesting day's work!  Then compare what is different between the last working version and the first version where the code quits working.  Then the real issue might be in the IRremote.cpp file.

 

SteveG


   
ReplyQuote
Page 1 / 2