Infrared TV Remote Using ESP32(with Android App)

by michaelmckey in Circuits > Remote Control

24006 Views, 17 Favorites, 0 Comments

Infrared TV Remote Using ESP32(with Android App)

WhatsApp Image 2021-06-09 at 00.20.49 (1).jpeg
WhatsApp Image 2021-06-09 at 00.20.50 (1).jpeg
WhatsApp Image 2021-06-09 at 00.20.49 (2).jpeg

The remote control from my TV was worn out and beginning to malfunction. As it was an older model, a new remote could not be purchased. So, instead, I decided to make my own TV remote to replace it.

In this tutorial, we will make an InfraRed remote, using the ESP32, which can be controlled with my app on the Google Play Store (https://bit.ly/34kJ3rF). The app will work with almost any microcontroller, but I decided to use the ESP32 as it has Bluetooth and Wi-Fi functionality along with the serial functionality of most microcontrollers. The programs in this tutorial are compatible with most Arduino based microcontrollers, so this project will work on most devices. For example, whilst building this I also created working remotes for the Arduino Uno and the Arduino Mega (although the pin numbers are different).

The finished remote has its own build in IR transmitter and receiver so it can be used to duplicate any other IR remote (just by receiving and storing the signals a TV would receive). This allowed me to back up my old TV remote so I will not permanently lose any of the functionality of my TV.

Supplies

Essentials:

  • A microcontroller (I used the ESP32)
  • An IR transmitter and receiver (I used the 1838T receiver and a generic 1.2V IR LED)
  • Resistors
  • A switch or a button (I used a tactile push button, but it can be inconvenient)
  • A 2N2222 Transistors
  • USB cable for the microcontroller

Perfboard version:

  • perfboard
  • solid core wire
  • female pin headers

Breadboard version:

  • breadboard
  • jumper cables

Optional:

  • USB power bank (I used a cheap one bought locally)

Building the Circuit

Screenshot (105).png
WhatsApp Image 2021-06-09 at 00.20.48.jpeg
WhatsApp Image 2021-06-09 at 00.20.48 (1).jpeg

There are many variants of the ESP32 - each with its own pinout! This complicates the process of designing and sharing circuits for it. I used the ESP32-WROOM-32 module but any ESP32 will work - just be careful to use the pinout of your own device. The ESP32 in the circuit above has a different pinout that my development board.

The ESP32 uses 3.3V logic but the 1838T works best with 5V. The 1838T receiver should be hooked up to ground and 5V (the Vin pin is connected to the 5V from the USB cable, so I used that). A 10k pullup resistor is used on the receiver's output to prevent the pin from floating (which would be perceived by the device as a received code). This output should then be connected to a potential divider to provide 3.3V to the ESP32 GPIO 22 (any input pin would work).

In the IR receiver datasheet, the device has a maximum peak current rating of 100mA. As the codes are sent in short pulses, the LED is only on for a fraction of a second at a time. This means it can draw a higher current than normal without burning out. The more current through the device the brighter the light output and therefore the longer the range of the device. I decided to let 60mA of current flow through the LED as this value provides a good range without running the LED at too high a current. I got a range of 4.2m with this design.

Each IO pin on the ESP32 only has a max current draw of 12mA which would result in a shorter range if used directly. To overcome this, I used a NPN transistor which allowed GPIO 22 to control the flow of current from the 3.3V pin (which can source more current).

I also added a button which is used to enable the receiver in software. This prevents background noise from being recorded as a signal which would then be saved by the app.

Programming

bluetooth_remote_screenshot.png

Due to the versatility of the ESP32, you can control the remote using three different communication protocols (serial, Bluetooth, and http (over Wi-Fi)). I have attached a different program to try out each. I also added serial to the Bluetooth example to show that the protocols are not mutually exclusive and can be used simultaneously.

I have commented the programs, if you want to understand how they work (and how to apply them to your own projects). On the Play Store listing, I have added annotated screenshots to guide you through the app. I also added some example remotes into the app which it might be helpful to mess around with (although they obviously will not work with your appliances).

Testing

Screenshot_20210609-003904_MC Remote.jpg
20210609_003319.jpg
20210609_004553.jpg
Screenshot_20210609-005440_Video Player.jpg
20210609_004058.jpg

When you finish assembling the project, test it to ensure all the connections are right and the components aren't defective (I've had many low-quality receivers malfunction so that they appear to be receiving random commands constantly). Sunlight can sometimes be perceived as a command by the receiver, so the button is a vital addition to prevent random noise being saved as a code.

To check if the receiver is working right:

  1. Connect to the device via your chosen method.
  2. Point your remote at the receiver's front face.
  3. Hold down the ESP32 receive button and (while it is held) click any working button on your other remote.
  4. The corresponding command should be displayed on your phone (and saved to your list of commands)
  5. Repeat step three.
  6. If the same command is display on your device; and only that command; your receiver is working correctly.
  7. Try other buttons on your remote (it will save them in the order you press them which is useful to know for assigning them to your virtual layout)

The Infrared LED can also break. The circuit deliberately pulses a high current through the LED to achieve a longer range. If the circuit isn't connected correctly (for example during testing) prolonged exposure to this current could damage the component - just like a regular LED. As we cannot see infrared radiation with the naked eye, it is harder to diagnose the problem. Luckily, the camera in your phone can see IR.

To check the IR LED (transmitter) is working:

  1. Connect to the device via your chosen method.
  2. Point the ESP32 remote at your phone or computer camera.
  3. Press a button on the virtual remote on your phone to send that code to the device.
  4. You should see a flickering purple light from the LED on your screen.

If you have recorded some commands for your appliance, you could alternately try and control it with the ESP32 remote.

For the remote to send a command the receiver must be disabled. So, this means that you can't reflect a signal to test both components simultaneously.

Conclusion

WhatsApp Image 2021-06-09 at 00.20.49 (1).jpeg
WhatsApp Image 2021-06-09 at 00.20.49 (2).jpeg

Hopefully, you have enjoyed the project and made yourself a new TV remote. My remote has a consistent range of 4.2m but depending on the components you used your results might vary. If you want to improve the project, you could upgrade the circuit to add a higher power transmitter to increase this range. If you made the circuit on a breadboard, you could now solder all the components on to perfboard to make it permanent (just ensure the ESP32 is removable so you can use it on future projects).

The app was originally designed to be for a TV remote control and only that. But after working on it, I realised that I was limiting its potential and it could be used for many microcontroller projects. You can now also use it to control any microcontroller project with serial, Bluetooth, or Wi-Fi. I have released the code for the app under the MIT licence on GitHub so feel free to use it in your own projects.

If you do decide to create your own project, I would love to hear from you. Or if you have any suggestions to improve my app or the tutorial; feel free to contact me.