#171 Arduino Guide to Infrared (IR) Communication also for ESP32 and ESP8266

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
everybody talks about Bluetooth and Wi-Fi but one heavily used technology is often forgotten infrared today we will remember this technology and bring it to the today's world of microcontrollers like the ESP 32 and the esp8266 and 2 technologies like MQTT and node-red and as usual we will take a little into the basics create see youtubers here is the guy with the Swiss accent with a new episode around sensors and microcontrollers today we will use infrared rays to detect objects and find a way to make the detector immune against interference from daylight we will use standard photo diodes as well as IR receivers to detect signals and see the difference then we will use infrared instead of Laura or Wi-Fi to transport information over the air we will enable an Arduino Uno to receive learn and send infrared codes we will port the infrared or IR library to the ESP 32 and implement MQTT finally we will build a device which can't control our home appliances like TVs or lights this device should be able to receive signals from an IR remote controller and transfer them by a mqtt to node red light is the radio frequency with the shortest wavelength you can use as a hobbyist to transport your information over a distance Laura for example has a wavelength of 30 centimeters Wi-Fi 1 of 12 or 5 centimeters and infrared light only 960 nano meters which is very very short this is why we do not use antennas to send or receive IR we usually use LEDs to send and photo transistors or photo diodes to receive infrared unfortunately these parts are dirt cheap and simple to use much easier than antennas and this is the reason why many many devices in our homes use IR for communication if we want to steer the TV or the newly purchased LED lighting system often the simplest way to control them is IR and IR has another nice feature because it's light is invisible to our eyes it is handy to detect the presence of things so let's start with the detecting presence application first as I said before we have to have a transmitter and a receiver the transmitter is a simple 5 millimeter LED which emits IR as a receiver we use a simple photo transistor or photodiode I leave a link in the description if you are interested in the difference between the two we could also use light dependent resistors to detect IR but because their reaction time is too slow we will not use them today by the way you can easily distinguish between the sender and the receiver even if their form factor is similar the sender is transparent and the receiver is black this black color blocks the visible light from the chip unfortunately not entirely as we will see later on and you find many other forms of photo transistors or diodes let's start to play with these parts we have to add these two resistors to limit the current to both parts and place the sender and the receiver in an opposite position the receivers voltage is low as soon as the transmitter is switched on as soon as we interrupt the infrared ray the receiver gets no light anymore and its output voltage goes to high this is a simple detector for things of course light is also reflected by many surfaces so we can all so place a transmitter and the receiver close to each other and direct them in the same direction now the receiver is low if nothing is in front and high if the IR is reflected by something in a reasonable distance like that we can detect presence not distance if you want to measure range using this method you have to watch video number 119 emitters and receivers in this layout can be bought as one part and are called reflective IR sensors unfortunately the receiver quickly can't be fooled if we take my torch for example we can fake the presence of something because as I said before the filter is not 100% and the IR diode also reacts to strong other light sources like daylight let's use our TV cupboard as an example I want that the TV automatically switches off when somebody closes the door I place such a reflective sensor behind the door to detect a closed door unfortunately the sensor did not switch on when the door was opened do you know why correct because it recognized the ambient light and was not able to distinguish it from the reflected light it thought the door is still closed and the light is the reflected light from the LED disappointing but we will see later on how I solve the problem as mentioned before IR can be used to transport information through the air let's do that I connect my Marcy key to the sending diode and the visible LED is a receiver and really we can transmit data over the air the receiver gets the Morse code of course we can also transmit much faster signals if I connect a square wave of 5 kilohertz we see it coming through to the receiver no problem unfortunately also here we have to deal with ambient light especially daylight includes a fair share of IR which is superimposed on the IR of the sending LED what to do we have to find a way for the receiver to distinguish between ambient light and light sent by the sender the easiest way to do that is to switch the sender off and on because the ambient light is stable we easily can distinguish the two by adding a high pass filter to the receiver and filter the DC component out all ir remote controllers use this approach they switch with frequencies from 30 to 40 kilohertz most common is 38 kilohertz TV remotes became very common in the 80s and 90s this is why we can buy complete receiver devices with built-in amplifiers filters and detectors for example for 38 kilohertz and they are very cheap I added an ne555 to the sending LED and replaced the receiving photodiode with a 38 kilohertz receiver the sender sends now a 38 kilohertz signal ambient light is no more able to disturb my system and in our living room the TV switch works perfectly when the door is opened so my wife was happy until she wanted to switch the TV channel can you imagine what happened as I said I used an ordinary 38 kilohertz receiver and the remote she used sent a 38 kilohertz signal in the direction of my receiver as soon as she pressed the key my receiver assumed the IR from the remote controller is part of the reflected light from the closed door and it switched the TV off I can assure you she was not amused and if I remember right I even heard the word nerds so back to the drawing board we will lay to see why I'm still married back to our more Sakhi of course we still can transmit Morse code over the 38 kilohertz link also here it is safe against ambient light and it works over a longer distance to Morse is fun but hard to learn this is probably why the manufacturers of TVs choose a different way to talk to their TVs they invented a code for each button on the remote control and transmitted these commands from the remote to the home appliance this fact had an additional effect because each manufacturer invented his own code the customers had to have many different remote controllers laying on their living room tables if they bought devices from different manufacturers and with the introduction of more and more remote controls each with different buttons and different codes for these buttons a channel developed let's now look at the signal sent by a remote I have here two receivers in parallel one plain vanila IR photodiode or transistor and a dedicated IR receiver for 38 kilohertz the photodiode detects the 38 kilohertz carrier frequency including the code whereas the IR receiver only delivers the demodulated digital signal as expected we have now everything to build a sender to control our appliances and we know enough to create a receiver to control our home automation system through for example node rate but we still have to deal with this channel of different codes if we want to mimic remote controls or want to understand the buttons pressed on a remote control fortunately we can use different or we know libraries to deal with this situation these libraries usually have two distinct functions send IR codes and receive IR codes to receive coats you have to connect an IR receiver to a pin not a standard photodiode for the transmitter an ordinary IR diode is okay if I use an Arduino Uno I have to connect the sending diode to pin three why is that because generating a frequency of 38 kilo Hertz is not easy for an Arduino it is quite fast for this technology the simplest way is to use a PWM port and set its frequency to thirty-eight kilohertz and the duty cycle to fifty percent then the processor itself only has to switch the port on and off this switching is done with a much slower speed but let's look at the codes most of them have a preamble or leader code and address bits followed by data bits and we can look them up in large databases but we can use a more straightforward method we use our receiver to lock the data sent by our remote controller then we do not have to deal too much with protocols and look-up tables this simple Arduino sketch for example receives many different codes and shows it in serial monitor if you point this remote control towards the IR receiver on the Arduino and press the for example on button the Arduino shows the code in serial if we push this button on the Arduino it sends the received code via its IR diode to the appliance and you can check if it reacts and switches on in my lab I have new LED lights which can be switched by this IR remote control of course we do not want to do this manually all the time we want to have this done by MQTT and connect our IR sender to node red so we need at least an esp8266 or better and ESP 32 for those who are interested why I'm still married I did the same thing as the manufacturers of TVs I invented my own code of course entirely different from all existing codes and completely new why that because I can I had to replace the ne555 with an 80 tiny 85 this microcontroller creates the signal and checks if the received signal carries my code only then it knows that the light was reflected and the door is closed and I was astonished when our friends came next time my wife proudly presented her unique automated tour somebody please explain me women before I lose the thread we wanted to get our SPS to behave like an IR receiver and sender if we go to the arduino library and to its description we see that ESP 32 is not supported for sending codes but this is precisely what we need if we want to control our devices using and qtt bad luck at least somebody already ported the library to the esp8266 but of course this is not good enough the ESP 32 seems to have even a built-in handling of IR codes but this feature is not well documented you find a short sketch on my github if you want to experiment with it it seems that you switch serial tool into a mode where it speaks I are code instead of serial then you just connect an ir LED to this pin but i wanted to stick to the arduino library and decided to port the sending part to the ESP 32 if you use a library from my github it should work for the ESP 32 at least our example sketch from before works without problems now we have to take notes of the codes for the on and off commands of the leds and add mqtt support to our device if you watched my last video about Laura you know how easy this can be done we even add a reverse channel and at an IR receiver diode to the ESP and send all incoming signals as an amputee t message back to note red now we either can use a remote controller to control aspects for our home automation system or control our IR controlled appliances using node-red what do we want more we even could distribute several such devices in our living room to cover all angles and if all of them subscribe to the same topic they also will send out the same command maybe you have to add a small addressing scheme to avoid that all devices send the same code at the same time because then our IR controlled appliances would see an undetectable clutter summarized we built a setup within redlight and detected the presence of objects we found a way to make the detector immune against interference from daylight but we had to make it also immune against signals from the TV remote we saw the difference in signals if we used regular photo diodes and dedicated IR receiver chips we used IR as a carrier to transport Morsi and other codes through the air without Laura or Wi-Fi first we used an Arduino Uno to receive learn and send out IR codes like that we had the proof of concept that our idea works then we used the ported IR library to build an mqtt enabled a SP 32 device finally by connecting this device to node rate we were able to control our lab lights with no threat we could also use this device to receive signals from an IR remote controller and influence node read with these messages for example we could start the low light if we switch our TV on and the best my wife is happy with her new device I hope this video was useful or at least interesting for you if true then like pi you
Info
Channel: Andreas Spiess
Views: 158,711
Rating: undefined out of 5
Keywords: esp8266, arduino, infrared, technology, esp32, electronics, eevblog, Project, Arduino project, Arduino IR, Arduino IR communication, ESP32 IR, ESP8266 IR, Reflective IR, IR sensor, MQTT, Wi-Fi, IR library, ESP32 IR library, diy, IR receiver, Arduino IR rsensor, IR Sensor, Arduino remote, remote control, ir remote control, tv remote control, IR MQTT, arduino projects, arduino project, programming, top 10 arduino projects, make, led, microcontroller, tutorial, diy projects, easy, how to
Id: gADIb1Xw8PE
Channel Id: undefined
Length: 18min 19sec (1099 seconds)
Published: Sat Nov 25 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.