IR Remotes & Microc...
 
Notifications
Clear all

IR Remotes & Microcontrollers - Arduino & ESP32

37 Posts
7 Users
7 Reactions
1,506 Views
(@dronebot-workshop)
Workshop Guru Admin
Joined: 5 years ago
Posts: 1088
Topic starter  

Everything you need to know about using IR Remote Controls with Arduino and ESP32.

We have looked at infrared remote controls before, but the library has changed in the five years since we did, and the technology has advanced. So it’s time to pay this topic another visit.

First, we’ll see how these gizmos work and get into the details of the NEC IR Protocol, which about 80% of consumer devices use. We’ll even hook a recover and IR diode to an oscilloscope to take a look at the invisible infrared signal.

Then, we’ll get up to date with the latest IRremote Library updates and look at another library that supports three times as many IR protocols. I’ll also show you how to handle those “stubborn” remote controls, like the ones used with air conditioners.

And, of course, we’ll have plenty of “hands-on,” with experiments based around both a classic Arduino Uno and an ESP32.

And I couldn’t have you watch an hour and a half of video without building something practical. So, we’ll finish up by putting together a custom IR remote control with an ESP32. It uses a web-based interface, so you can add as many buttons as you need and control your world from your phone or tablet.

Here is the table of contents for today's huge video:

00:00 - Introduction
02:53 - IR Remote Controls
10:42 - Sensors, Emitters & Scope Test
15:40 - The Arduino-IRremote Library
17:43 - Arduino Uno Hookup
24:44 - SimpleReceiver Example
30:52 - SimpleSender Example
35:31 - The IRMP Library
37:38 - Arduino & LCD Hookup
42:10 - AllProtocols Code & Demo
46:04 - Emulating Transmitters and Receivers
47:06 - Receiver Code & Demo
52:52 - Transmitter Code & Demo
1:00:30 - Capturing IR Remote Codes
1:01:19 - ReceiveAndSend Code & Demo
1:10:58 - ReceiveAndSendDistanceWidth Code & Demo
1:16:18 - ESP32 Remote Control & Hookup
1:19:06 - ESP32 Remote Control Code & Demo
1:28:53 - ESP32 IR Receiver Hookup
1:29:48 - Conclusion

Believe it or not, there is more material, but I had to stop somewhere! So keep your eyes peeled for another video with three really cool IR projects.

And make sure that you check out the accompanying article on the DroneBot Workshop website. It has more information and links to many IR remote control-related websites.

Hope you enjoy the (long) video!

Bill

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


   
robotBuilder reacted
Quote
JimJtron
(@jimjtron)
Member
Joined: 3 years ago
Posts: 15
 

Hey Bill! You have a circuit showing an NPN transistor. You show 2 choices to use. A 2n2222 and a 2n3906. BUT the latter is a PNP type. I am guessing you mean a 2n3904 which is the NPN complement of the PNP. I’m really impressed with the video as I have a number of projects where I need to generate (and aim) a IR code at an air conditioner at a remote house via the internet. Cheers for now! Regards Jim.

https://en.wikipedia.org/wiki/2N3906

IR Transistors

   
ReplyQuote
 Bert
(@shunt)
Member
Joined: 5 months ago
Posts: 15
 

Hello, 

was glad to try the more recent IRremote library . Really like the fact we can get an address and a button code instead of a huge number.

I tried the ir-remote-receive sketch you show  about two/third of the article.

My led will turn ON when lampPower goes HIGH but stays ON when lampPower is LOW.

Was wondering if others have experienced the same issue.

For reference, I am using an esp32 and a Panasonic Remote.

tks.

Bert ( @shunt ) from Montreal


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7115
 

@shunt Perhaps some code, and if you just copied someone else's, a link to their code.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
 Bert
(@shunt)
Member
Joined: 5 months ago
Posts: 15
 

Ron, 

please slide up where this topic start , dronebot article on IRremote . Refer to time 47:06 in the article. The code is called ir-remote-receive. I can add a link later

Thank you

 

Bert ( @shunt ) from Montreal


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7115
 

@shunt A video is useless in terms of code. Did you try to copy the code from the video? There is a link to the article that shows the code in addition to a downloadable zip file with all the materials.. After every one of Bill's videos is a ...more link, click it and you will see more. Usually the first link is to the article where you can study and learn.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
 Bert
(@shunt)
Member
Joined: 5 months ago
Posts: 15
 

Hi , here is the link to the IR remotes ZIP files

https://s3.amazonaws.com/download.dronebotworkshop.com/IR-Remote-DroneBot-Workshop.zip

As previously mention , the file is ir-remote-receive.ino

I have changed lines below to adapt to my remote and esp32 suggested pins

13 #defineDECODE_PANASONIC
20 #define IR_RECEIVE_PIN 15
23 #define LED_PIN 4
33 uint16_t codePower =0x10;
34 uint16_t codeMinus =0x11;
35 uint16_t codePlus =0x12;
 
remote buttons 1-2-3 for 0x10-0x11-0x12
push the button 1 once, serial monitor shows lampPower=1 , gpio 4 is high, led is ON
push the button 1 again, serial monitor shows lampPower=0 , gpio 4 is high, led is ON
 
I was just wondering If I was the only one seeing this with the proposed code.
 
tks

Bert ( @shunt ) from Montreal


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1723
 

Hi @shunt,

   I have not looked at this project/video, and have not tried it, but I had a quick 'eyeball' at the code. I am not sure if I am missing the point (which is always easy at a quick glance), or there is a mistake.

    // Set LED Power and Level
    if (lampPower) {
      // Lamp is powered, set level
      analogWrite(LED_PIN, lampLevel);
    } else {
      // Lamp is off
      digitalWrite(LED_PIN, LOW);
    }

I was surprised to see an analogWrite ... shouldn't both writes be digitalWrite?

And although it may work, why is lampLevel used in one case, and the 'specific' LOW in the other.

Apologies if I have missed the point.

Best wishes, Dave

 


   
Bert reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2542
 

Posted by: @davee

And although it may work, why is lampLevel used in one case, and the 'specific' LOW in the other.

Since the comment says to set LED power and level, it seems that this code is setting a specified intensity instead of just on/off.

So, it appears that the sketch's author us setting a specific intensity on the LED using analogWrite and just digitalWrite to turn it off. This may be slightly more efficient since there's no rescaling required to map zero to zero.

 

Anything seems possible when you don't know what you're talking about.


   
Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7115
 

@davee You did, but @will got it

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7115
 

@shunt We seem to have a bit of a communication problem. When I asked for a link, giving me an amazon link to a dronebot link to the zip file is a little off the point. You didn't need the amazon link, just post the dronebot link. However in this case, simply saying you used the file named 'some file' from the article zip would have been the first step, then post your version of the code. By typing in code into a forum p[ost you introduce another chance of transcription error. Next time just copy your code into a <> source box and say it is a modified version of Bill's code in [provide link to article] 

Will (@will) provided the solution only because he is very good at reading code and seeing things most don't.

I like to teach people how to troubleshoot and/or be good at communicating about their errors.

Be sure to follow up with Will and thank him for fixing your problem if in fact what Will said is the issue. 

There is a chance that is not the issue and in that case post all your code plus links to where you got the values from that you changed.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
 Bert
(@shunt)
Member
Joined: 5 months ago
Posts: 15
 

Tks Ron for the feedback , appreciated.

You could be right about the communication issue.  I am not asking for a fix. Only asking if others are seeing the same problem I am seeing.

Sorry about the amazones, i just copied the link you were asking for.

hope you were able to get the code with the link.

tks

Bert ( @shunt ) from Montreal


   
ReplyQuote
 Bert
(@shunt)
Member
Joined: 5 months ago
Posts: 15
 

@davee Hello DaveE, in reference to your 1553 post , the intensity of the led ( or pwm output ) is controlled with analogWrite function. This portion works fine for me with 2 of the 3 buttons of my remote control used for that. Was reluctant about analogWrite on my esp32, had better luck in the past with ledC but like I said, intensity up and down works fine with proposed sketch.  DigitalWrite is only used to turn the led ( output ) totally Off, with a third button.  

Can we turn off an output using digitalWrite LOW if that output was turned on with analogWrite , not sure, will try this in a new sketch  on my esp32...

tks

Bert ( @shunt ) from Montreal


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1723
 

Hi @shunt,

  I only glanced at the code, but mixing analog and digital write commands just didn't 'feel' like the right approach. I would not have expected a program to send both commands to the same GPIO pin, and hence, this might be an 'untested' situation for the authors of the underlying libraries and the chip designers. It might even work with one chip design/library and not with another, due to subtle implementation differences.

I would hope it was only necessary to use one of the commands, probably analogWrite with appropriate values for all circumstances, including when the LED is required to be 'off', but I haven't examined the circuit and software in enough detail to be completely sure that is feasible.

------

The code you have might work perfectly well, depending on the underlying code and chip design, but as you had an issue to solve, it seemed like it was a point worth checking.

Apologies if it is not the problem ... My experience of fault-finding on unfamiliar circuits with 'odd' behaviour, has tended to involve lots of speculation, checking out several possible problems, before finally discovering the culprit. A little patience and a lot of coffee (or your preferred beverage) is the best advice I can give!

Best wishes and good luck, Dave


   
ReplyQuote
 Bert
(@shunt)
Member
Joined: 5 months ago
Posts: 15
 

good day to all of you ,

 

 @davee @will , as you pointed out , and thank you for this, mixing Digital and Analog Write is the issue.

Actually, I have created a new very simple sketch for my esp32 that only have digitalWrite and analogWrite commands in it and I can confirm that analogWrite is the only one to have control. 

Also, while being there, was curious about using ledC ( for pwm control ) instead of analogWrite. As for using ledC with digitalWrite on the same output, digitalWrite is the only one to have control.

Appear that I will have to rewrite part of the proposed code to use it on my lamps if I want to use my esp32.

tks for your time and enjoy this wonderfull day

 

Bert ( @shunt ) from Montreal


   
DaveE reacted
ReplyQuote
Page 1 / 3