Simple homemade IR control for switching TV channels (555, K561IE9)

At the end of the USSR, domestic semiconductor televisions of the USCT series appeared and were very popular, some of them are still in service. TVs with a screen size of 51 cm diagonally were especially durable (the kinescope was very reliable). Of course, they no longer meet modern requirements at all, but as a “dacha option” they are still quite suitable.

Somehow, out of nothing to do, a desire arose to improve the old, already “dacha” “Raduga-51ТЦ315”, adding a remote control system to it. Now it is impossible to purchase a “native” module, so it was decided to make a simplified single-command system that allows at least switching programs “in a ring”. Microcontrollers and special microcircuits were immediately rejected due to unprofitability, and the system was made from what was available.

Namely, integrated timer 555, IR LED LD271, integrated photodetector TSOP4838, counter K561IE9 and plus some other little things.

Control panel diagram

The remote control is a pulse generator with a frequency of 38 kHz, at the output of which an infrared LED is switched on via a key. The generator is built on the basis of the “555” microcircuit, the so-called “integrated timer”. The generation frequency depends on the C1-R1 circuit; when setting up, by selecting resistor R1, you need to set the frequency at the output of the microcircuit (pin 3) to 38 kHz.

Fig.1. Schematic diagram of an IR transmitter for remote control of a TV.

Rectangular pulses with a frequency of 38 kHz are supplied to the base of transistor VT1 through resistor R2. Diodes VD1 and VD2 together with resistor R3 form a current control circuit through the IR LED HL1.

With increased current, the voltage on R3 increases, and the voltage on the emitter VT1 increases accordingly. And when the voltage at the emitter approaches the drop voltage across the diodes VD1 and VD2, the voltage at the base of VT1 decreases relative to the emitter, and the transistor closes.

Pulses of IR light, following with a frequency of 38 kHz, are emitted by the HL1 infrared LED.

Control is by one button S1, which supplies power to the remote control circuit. While the button is pressed by the remote control, infrared pulses are emitted.

IR receiver device. Principle of operation

Infrared radiation receivers are widely used in electronic technology due to their affordable price, simplicity and ease of use. These devices allow you to control devices using a remote control and can be found in almost any type of equipment.

The operating principle of an IR receiver. Processing the signal from the remote control

The IR receiver on Arduino is capable of receiving and processing an infrared signal in the form of pulses of a given duration and frequency. Typically, an IR receiver has three legs and consists of the following elements: a PIN photodiode, an amplifier, a bandpass filter, an amplitude detector, an integrating filter, and an output transistor.

Under the influence of infrared radiation in a photodiode, in which between p

and
n
regions, an additional region of semiconductor is created (
i
-region), current begins to flow. The signal goes to an amplifier and then to a bandpass filter, which protects the receiver from interference. Interference can be caused by any household appliance.

The bandpass filter is set to a fixed frequency: 30; 33; 36; 38; 40 and 56 kilohertz. In order for the signal from the remote control to be received by the Arduino IR receiver, the remote control must be at the same frequency as the filter in the IR receiver is set to. After the filter, the signal goes to an amplitude detector that integrates the filter and the output transistor.

Receiving block diagram

The receiver is installed inside the TV, it is supplied with + 12V power from the TV's power supply, and the cathodes of the VD2-VD9 diodes are connected to the contacts of the buttons of the USU-1-10 program selection module.

Fig.2. Schematic diagram of an IR receiver for remote control of a TV.

IR pulses emitted by the remote control are received by an integrated photodetector HF1 type TSOP4838. This photodetector is widely used in remote control systems for various household electronic equipment. When a signal is received, there is a logical zero at its pin 1, and a logical one when there is no received signal.

Thus, when the remote control button is pressed, its output is zero, and when not pressed, its output is one.

TSOP4838 should be powered by a voltage of 4.5-5.5V, and no more. But, to control the TV program selection module, you need to apply 12V voltage to the buttons of the transistor 8-phase trigger. Therefore, a voltage of 12V is supplied to the D1 chip, and a voltage of 4.7-5V is supplied to the photodetector HF1 through a parametric stabilizer on the zener diode VD10 and resistor R4.

Transistor VT1 serves as a cascade matching the levels of logical units. In doing so, it inverts the logic levels. The voltage from the collector VT1 through the circuit R3-C2 is supplied to the counting input of the counter D1, designed to receive positive pulses. The R3-C2 circuit is used to suppress errors from bouncing contacts of the S1 button on the control panel.

Counter D1 K561IE9 is a three-digit binary counter, with a decimal decoder circuit at the output. It can be in one of eight states from 0 to 7, while a logical one is present at only one output corresponding to its state. The remaining outputs are zeros.

Each time you press or release the remote control button, the counter moves one state up, and the logical unit of its outputs switches. If the countdown started from zero, then after eight presses of the button, on the ninth, the counter will return to the zero position. And then, the process of switching the logical unit along its outputs will be repeated.

The LD271 IR LED can be replaced with any IR LED suitable for household appliance remote controls. The TSOP4838 photodetector can be replaced with any complete or functional analogue.

Electronics for everyone

The beginning or “How the device began”
... When I arrived, Victoria was sitting on the sofa, staring at the TV. It had been a hard day, so she didn't want to do anything. We watched some pop series for a few minutes, then it ended and Vika turned off the TV. The room became dark. It was raining outside, and this made it seem like it was cold at home too. Vika got up from the sofa and began, by touch, to look for the light switch. For some reason, the wall lamp hung not by the sofa, but on another wall, and I had to stomp across the room to turn on the light. When she finally turned it on, the room was filled with the warm glow of an incandescent bulb. Next to me, on a rumpled sheet, lay the TV remote control. The bottom buttons are unmarked and most likely unused. And then I had an interesting thought... - Vic, would you like me to make it so that your lamp can be turned on using the remote control from the box? There are even extra buttons...

Concept

Our device must be able to receive a signal from an IR remote control, distinguish “its” button from others, and control the load. The first and last points are as simple as an axe. But the second one is a little more interesting. I decided not to limit myself to any specific remote control (Why? - “That’s not interesting!”), but to make a system that can work with different models of remote controls from different equipment. If only the IR receiver didn’t give up and confidently caught the signal.

We will catch the signal using a TSOP

. Moreover, not every receiver is suitable - the carrier frequency must match the frequency of the remote control. The carrier frequency of the receiver is indicated in its marking: TSOP17xx - 17 is the receiver model, and xx is the frequency in kilohertz. And the carrier frequency of the remote control can be found in the documentation or on the Internet. In principle, the signal will be received even if the frequencies do not match, but the sensitivity will be crap - you will have to poke the remote control directly at the receiver. Every company that produces household appliances is forced to comply with standards when manufacturing hardware. And the modulation frequencies of the remote controls are also standard. But the developers have a blast on the software side - the variety of exchange protocols between the remote control and the device is simply amazing. Therefore, we had to come up with a universal algorithm that does not care about the exchange protocol. It works like this:

Control points are stored in the device memory. For each such point, you need to record the time and output status from the IR receiver - 0 or 1. When receiving a signal from the remote control, the MK will sequentially check each point. If all the dots matched, then this was the very button for which the device was programmed. And if the output from the receiver does not match the template at least at one point, then the device will not react in any way.

However, no one canceled the bugs! It is possible that the signal will differ from the template, but the values ​​at the control points will be the same. This will result in a false positive. It would seem like a rare bastard, and it’s really hard to fight him! But in fact, not everything is so bad (and in some places it’s even good).

Firstly, we have a digital signal, which means that the pulses come with constant delays (timings) and simply do not appear. Therefore, if the points are dense enough, then you don’t have to be afraid that some impulse will be missed.

Secondly, small noise (usually looks like rare short pulses) in most cases goes through the forest - because if it does not hit the control point directly, then it will not affect the system at all. This means we have natural protection from noise.

The second type of errors (aka “Missing a command”) occurs due to the fact that the point is located too close to the edge of the pulse (to the place where the signal at the receiver output changes its level). Imagine that a few microseconds after the checkpoint, the signal should change from HIGH to LOW. Now imagine that the remote control issued a command a little faster than usual (happens quite often). The pulse front has shifted in time, and now it occurs BEFORE the control point! The output from the receiver will not match the pattern and the system will reset. To prevent this from happening, you need to place control points away from the fronts.

“Everything is cool,” you say, “But where can I get control points?” So I've been stuck on this for a long time. As a result, I decided to entrust the placement of points to you. The device has jumper J1. If it is closed when turned on, the device will stupidly transmit via UART everything that the IR receiver outputs. On the other side of the wire, this data is received by my program, which displays pulses from TSOP on the computer screen. All you have to do is use your mouse to scatter control points along this graph and flash them into the EEPROM. If it is not possible to use UART, then jumper J2 comes to the rescue. When it is closed, the device does not output data via UART, but stores it in EEPROM.

Scheme

Simple as hell. I took ATTiny2313 as the controller. Frequency 4 megahertz, from quartz, or internal RC chain. The RX and TX lines for communication and power supply are provided on a separate connector. There, RESET is displayed so that you can reflash the MK without removing it from the device. The output of the photodetector is connected to INT0, it is connected to the power supply through a 33k resistor. If there is strong interference, then you can put a smaller resistor there, for example, 10k. There are jumpers on pins D4 and D5. Jumper1 on D5 and Jumper2 on D4.

The power module is connected to pin D6. Moreover, I took the smallest triac that I had - BT131. Its current is 1A - not cool, but the body is not too large - TO92. For small loads that's it. I made the optocoupler on the MOC3023 - it does not have a zero-crossing sensor, which means it is suitable for smooth load control (I never implemented this here).

Port B is almost completely connected to the connector - you can attach an indicator or something else there. I use this same connector when flashing the firmware of the device. Pin B0 is occupied by the LED.

The whole thing is powered through LM70L05 and a diode bridge. That is, an alternating voltage can be supplied to the input, for example, from a transformer. The main thing is that it does not exceed 25 Volts, otherwise either the stabilizer or the condenser will die.

The payment turned out like this:

Yes, it is slightly different from the board that is in the archive. But this does not mean that I made myself an uber-advanced board and handed you a demo version :). On the contrary, my board has a couple of shortcomings that are not present in the final version: I do not have the RESET pin connected to the pin, and the LED hangs on PB7. And this is not very conducive to in-circuit programming.

Firmware

The device can operate in two modes. In the first - when J2 is closed - it simply transmits pulses from the photodetector to the UART. Let's start with it:

The UART operates at a speed of 9600, i.e., at a frequency of 4 MHz we write 25 to the UBRR register.

...we wait until the leg of the photodetector twitches. As soon as it drops (initially it hangs on the pull-up resistor), we start the timer (TIMER/COUNTER1, the one with 16 bits) and turn on the INT0 interrupt for any input change - any logical change (ICS00 = 1). The timer is ticking...we are waiting.

The pulse from the remote control ended - the output from the photodetector shot up, the interruption worked. Now we write the timer value into memory and reset the timer. You also need to increment the write pointer in order to write to another memory cell at the next interrupt.

Another pulse... the output twitches... interrupt... writing the timer value to memory... resetting the timer... pointer + 2 (we write two bytes at a time)...

And this will continue until it becomes clear that the end (of the RAM) is near. Or until the signal ends. In any case, we freeze the timer and disable interrupts. Then, we slowly throw everything we have collected into the UART. Or, if J2 is closed - to EEPROM.

In the end, you can go into an endless loop and wait for a reset - the mission is completed. And the output will be a sequence of numbers. Each of them is the time between changes in the state of the TSOP output. Knowing where this sequence began (And we know! This is the transition from HIGH to LOW), we can restore the whole picture:

Second mode. Here we receive commands from the remote control and control the load.

Interrupts are not used at all, everything runs in the main program loop. The EEPROM contains control points. Each of them takes 1 byte: 7 bits for the time from the last point and 1 bit for the state of the TSOP output at this point.

After initialization, we sit and wait for TSOP to move. As soon as this happens, we read the first point from the EEPROM, and in a simple loop we depress as much as is written there. In this case, we count the time in packs of 32us. Coming out of the stupor, we check to see what is there at the receiver output.

If the output did not coincide with what we expected, it is not our team. You can calmly wait for the end of the signal and start all over again.

If the output matches our expectations, we load the next point and check it. So until we come across a point whose time = 0. This means that there are no more points. This means the whole team has coincided, and you can pull the load.

So, it turns out, a simple algorithm. But the simpler, the more reliable!

Softina

At first I thought about making the template automatically memorized. That is, you close the jumper, poke the remote control into TSOP, and the MK itself places control points and puts them in the EEPROM. Then it became clear that the idea was crazy: a more or less adequate algorithm would turn out to be too complex. Or it won't be universal.

The second idea was a program for the computer in which you can set control points yourself. Not very technologically advanced, but anything is better than entrusting this matter to MK.

We train the device to respond to the desired button on the remote control:

1) Close jumper J1.

2) Connect UART. If there is no way to connect it, then close jumper J2. Then the device will dump data into EEPROM.

3) Turn on the power.

4) If we decide to use UART, then launch the software and look at the status bar (at the bottom of the window). It should say “COM port open”. If it is not written, then we look for a jamb in the connection and press the “Connect” button.

5) Take the remote control and press the desired button in TSOP. As soon as the device senses that the signal has arrived, the LED will light up. Immediately after this, the device will begin transmitting data via UART (or writing to EEPROM). When the transmission is completed, the LED goes out.

6.1) If we are working via UART, then click the “Load via UART” button. And we are happy with the inscription “Loaded the chart...” in the status bar.

6.2) If we work through EEPROM, then we read the EEPROM memory with the programmer and save it to a *.bin file. (Exactly bin!). Then click the “Load .bin” button in the program and select the file with the EEPROM.

7) We look at the loaded chart - this is a signal from TSOP. There is a slider on the sidebar that you can use to change the scale. Now we click on the schedule with the mouse and set control points. The right button deletes the points. Just don't put them too close to the fronts. It turns out something like this:

8) Click “Save .bin” and save the points. Then we flash this file into the EEPROM. Since we cram the time between two points into 7 bits, it is limited to 4ms. If the time between two points exceeds this value, the program will refuse to push the points into the file.

9) Remove the jumpers. Reboot the device. Ready!

Archive with firmware, board, software

Test video

Why do you need an additional resistor?

In turn, resistor R1 (10 kΩ) provides a constant current through the rectifier diode, so that the voltage supplied to the receiver does not depend significantly on the current drawn by the circuit. The current consumed by this circuit varies greatly. When the LED is off, the TSOP31236 consumes less than 1 mA. When the LED is turned on, the consumption increases by ~4 mA (a little, but still 4 times more).

Diode D1 was used as a supply voltage reducer, but in order to act in this role, a "significant" current must flow through it so that a voltage of ~0.7 V can be generated across it. It is important to note that it must perform this function properly way (all the time) even when the TSOP is waiting for an IR signal, that is, at low power consumption.

What is " significant current "? That's a moot point. It is not defined anywhere and depends mainly on the parameters of the silicon diode and the ambient temperature. Here we have assumed that the additional diode load with a current of about 0.5 mA from resistor R1 will continuously provide "significant current". As a result, D1 will always require a voltage drop of about 0.7 Volts.

The circuit should also work without this resistor, but this is a safer solution!

How to connect an IR receiver to Arduino

The housings of infrared receivers contain an optical filter to protect the device from external electromagnetic fields; they are made of a special shape to focus the received radiation on a photodiode. To connect the IR receiver to the Arduino UNO, three legs are used, which are connected to the ports - GND, 5V and A0.

For this lesson we will need the following details:

  • Arduino Uno board;
  • Bread board;
  • USB cable;
  • IR receiver;
  • Remote control;
  • 1 LED;
  • 1 resistor 220 Ohm;
  • Wires "folder-folder" and "folder-female".

Connection diagram of the IR receiver to the Arduino analog port

Connect the IR receiver according to the diagram and the LEDs to pins 12 and 13 and upload the sketch.

#include // include the library for the IR receiver IRrecv irrecv(A0); // indicate the pin to which the IR receiver is connected decode_results results; void setup() // procedure setup { irrecv.enableIRIn(); // start receiving an infrared signal pinMode (13, OUTPUT); // pin 13 will be the output pinMode (12, OUTPUT); // pin 12 will be the output pinMode (A0, INPUT); // pin A0 will be the input (eng. “intput”) Serial .begin (9600); // connect the port monitor } void loop () // loop procedure { if (irrecv.decode (&results)) // if the data has arrived, execute the commands { Serial .println (results.value); // send the received data to the port // turn on and off the LEDs, depending on the received signal if (results.value == 16754775) { digitalWrite (13, HIGH); } if (results.value == 16769055) { digitalWrite (13, LOW); } if (results.value == 16718055) { digitalWrite (12, HIGH); } if (results.value == 16724175) { digitalWrite (12, LOW); } irrecv.resume(); // receive the next signal on the IR receiver } }

Explanations for the code:

  1. The IRremote.h library contains a set of commands and allows you to simplify the sketch;
  2. The decode_results statement assigns the variable name results to the received signals from the remote control.

What to pay attention to:

  1. To be able to control the inclusion of the LED, you need to turn on the port monitor and find out what signal is sent by this or that button on the remote control;
  2. The obtained data should be entered into the sketch. Change the eight-digit code in the sketch after the double equal sign if (results.value == 16769055) to your own.

The remote control of a VCR, TV, music center or satellite receiver can be used to turn off and on various household electrical appliances, including lighting.

Do-it-yourself remote control, the diagram of which is given in this article, will help us with this.

IR transmitter circuit

The barrier has two modules: one is a transmitter and the other is a receiver. The transmitter uses a classic 555 chip, which works as a pulse generator. The BC327 transistor amplifies these pulses and supplies them to infrared LEDs.

Pulse transmission has two advantages. First: the receiver, with the help of filters, can isolate the transmitter signal from the background noise. Second: if the pulses are short, then more power can be applied to the LEDs in the emitters, without the risk of burning them, and thus obtaining a larger range of action. With the part values ​​shown in the diagram, the transmission frequency will be 1.3 kHz and the pulses will have a duration of 25 µs. And the periods of silence will be 750 μs. The ratio is 1 to 30.


The printed circuit board provides the ability to connect 3 IR LEDs at once. But you can connect only one LED, two or three. If you do not connect all the LEDs, you need to solder jumpers from a piece of wire instead of the LEDs. Current limiting resistance of LEDs is 10 ohms. You can increase it if you need to reduce the output radiation power.

IR communication

For communication you can use the infrared port . In this regard, it is worth explaining another concept that may be new to some. Transfer in the context of communication is the transfer of information between two devices. Most often, this message is a sequence of zeros and ones that is understandable to the recipient.

An example of broadcasting is controlling a TV using a special remote control. After pressing the button, the remote control transmits a sequence of several bits (zeros and ones) to the TV. The receiver detects the corresponding pulse sequence, interprets it, and performs the requested task.

This communication standard is extremely convenient, so it is also very actively used by electronics enthusiasts. An ordinary TV remote control can quickly become, for example, a controller for our Arduino-based robot.

Rating
( 2 ratings, average 4.5 out of 5 )
Did you like the article? Share with friends:
For any suggestions regarding the site: [email protected]
Для любых предложений по сайту: [email protected]