10 Ingenious Steps to Build Your Own TV Remote with an Arduino
Losing your TV remote can be a modern-day tragedy, especially when you're in the middle of an epic gaming session. That's exactly what happened to me when my Sony Bravia gave up, forcing me to switch to a Xiaomi Mi TV – only to discover its remote was nowhere to be found. Frustrated but determined, I embarked on a DIY journey to create a custom remote using an Arduino-compatible D1 Mini and an IR blaster. What started as a simple fix turned into a deep dive into IR protocols, reverse engineering, and wireless convenience. Here's how I turned a lost remote into a fully functional, WiFi-connected command center in 10 steps.
1. The Initial Crisis: A Lost Remote and a Broken TV
My primary TV, a Sony Bravia, suddenly stopped working for reasons unknown even after a 30-minute call with Sony support. Desperate to test Spider-Man 2 on my PS5, I moved to my bedroom TV – a Xiaomi Mi TV 4A 43-inch. But without its remote, I couldn't switch the input to HDMI3. I searched everywhere, but the remote was gone. This is where the seed of a DIY solution was planted: why not build my own remote using an Arduino and an IR blaster?

2. Why Existing Apps Failed: The WiFi and Bluetooth Trap
I first tried Xiaomi's Mi Remote app, which can control any Mi TV over WiFi. However, my TV lacked Bluetooth, meaning it relied solely on WiFi for the app to work. The problem? I change my WiFi password every month for security, so the TV was offline. The app was useless. This limitation pushed me toward a hardware solution that wouldn't depend on network connectivity – at least for the initial setup. An IR-based approach seemed perfect since it works without any network.
3. The DIY Concept: IR Blaster + D1 Mini
The idea was simple: connect an IR blaster (LED + resistor) to a D1 Mini (ESP8266 board) and program it to send infrared commands. I would control it via the serial monitor on my computer, sending single-character commands like 'p' for power. I asked Claude AI for help to generate the initial code, thinking it would be straightforward. The D1 Mini is cheap, powerful, and perfect for such IoT projects. What could go wrong?
4. First Failure: The Power Command Didn't Respond
I wrote a basic sketch that sent a standard NEC power code for Mi TVs when 'p' was typed. Nothing happened. The TV didn't even blink. I tried several other power codes found online, but none worked. This was frustrating – the TV was completely unresponsive to my codes. Something was off. I realized that Mi TVs might use a non-standard IR protocol, meaning generic codes wouldn't work. I needed the exact timing for my specific model.
5. Brute Force: Trying 7 Common Power Code Sets
Out of ideas, I compiled a list of 7 common Xiaomi power code sets from various online databases. I wrote a script that sent each code one by one with a delay, hoping one would trigger the power toggle. I flashed this code and sent a command via serial monitor. The TV remained stubbornly off. None of the codes worked. This brute-force approach failed miserably. I needed a smarter method – reverse engineering the official remote's protocol.
6. Reverse Engineering: Finding the Exact Codes
I decided to reverse engineer the Mi Remote app's communication. Surely, the app must contain the correct IR codes for all Mi TVs. Before diving into that, I searched GitHub and found a goldmine: the mi_remote_database repository. Someone had already extracted codes from Xiaomi's database. I cloned the repo, located brand 153 (Xiaomi) and model 5122 (my TV), then used their Python exporter to convert the encrypted codes into Flipper Zero format. From there, I extracted raw mark/space timings in microseconds at 38 kHz carrier frequency.

7. Discovering the Quaternary Protocol
When I examined the extracted timings, I found something unexpected. Mi TVs don't use standard NEC or Sony SIRC protocols. Instead, they use a quaternary protocol with four different space lengths: 578 µs, 867 µs, 1147 µs, and 1428 µs. This explained why generic codes failed – the decoder on the TV expects these specific space values. The raw data also included the usual 38 kHz carrier. Understanding this was the key to success. I could now encode any command by precisely reproducing the mark/space patterns.
8. First Success: Power, Volume Up, and Volume Down
Armed with the correct timings, I wrote new code that sent the power command using the quaternary pattern. I uploaded it to the D1 Mini, opened the serial monitor, typed 'p', and the TV turned on! Then I added volume up and volume down – both worked flawlessly. This was a huge milestone. I now had a functional, albeit minimal, remote control. The serial monitor allowed me to send commands manually, but it was not very convenient for everyday use.
9. Full Remote Control: Adding All Keys
With the protocol cracked, I expanded the code to include every button on a standard Mi TV remote: navigation keys (up, down, left, right), OK, back, home, menu, mute, and number keys. I mapped each to a unique character or string sent via serial. Now I could control the entire TV from my laptop. But this still required a wired connection (USB-serial). To make it truly wireless, I integrated WiFi connectivity so the D1 Mini could join my home network.
10. Future-Proofing: Web-UI and WiFi Integration
To avoid repeating the process every time I change WiFi passwords, I built a tiny web server on the D1 Mini that hosts a complete remote control interface. The server runs a simple HTML page with buttons for each key, sending HTTP requests to the ESP8266. Now I can control the TV from any device on the network – phone, tablet, or laptop. And if I change the network, I just reconnect the D1 Mini via its serial port once to update the credentials. The code is available here for anyone wanting to replicate this project.
Conclusion: Building a custom TV remote from scratch was a rewarding journey that taught me about IR protocols, reverse engineering, and embedded web servers. What began as a frustrating afternoon turned into a fun weekend project. The best part? My DIY remote is now more reliable than the original – it never gets lost, and it works from anywhere in the house over WiFi. If you're ever stuck without a remote, consider building your own. It's easier than you think, and you'll learn a lot along the way.
Related Articles
- Google Home's Gemini AI Gets Smarter: Multi-Step Tasks and Event Management Upgrades
- Silent Data Sinks: How Poor Quality Is Crippling Generative and Agentic AI in Production
- DAIMON Robotics Unveils Daimon-Infinity: A Giant Leap in Robotic Touch
- Enterprise AI Takes Action: NVIDIA and ServiceNow Unite for Autonomous Agents
- ByteDance Unveils Astra: A Breakthrough Dual-Brain System for Robot Navigation
- ByteDance Unveils Astra: A Two-Brain System for Robot Navigation in Complex Indoors
- Worm Plague Hits Industrial Systems: Email Attacks Surge in Q4 2025
- How to Use Drone Data to Build Growth Curves for Crop Breeding Success