DEV Community

Ankit Agrawal
Ankit Agrawal

Posted on • Originally published at aggrawalankit.substack.com

I lost my TV remote, so I built one with an Arduino

arduino web ui for mi tv remote

So, yesterday my primary TV suddenly stopped working, it's a Sony Bravia. What happened?… well god knows… and believe me, sony has no clue even after being on a call with them for over 30 mins!

I had to try out Spider-Man 2 on my PS5; and I know I am way too late in doing so.

But anyways, I needed a screen and so I connected to the TV in my room and turned it on but I had no remote to change the input to HDMI3. I looked and searched and found but no luck!

Xiaomi has a Mi Remote app and so, I could have used it but for that it had to be connected to wifi but I constantly (every month) rotate my wifi creds and this model (Mi TV 4A 43 inch) of Mi TV had no Bluetooth and so, this app was also a fail.

This is when it hit me… why not connect the IR blaster to my d1-mini and simply program it so that I can send commands using serial monitor and connect it to the wifi. So, I first asked Claude to just add a command to simulate the power button such that when I send “p” using serial monitor, it sends the relevant pulse using the IR blaster and it didn’t work! I tried some more codes that I found on the internet for this button but still no luck!

It was not as easy as I initially thought it to be.

Anyways, next best option → bruteforce 7 common power code sets that I found on the web . I flashed this code thinking this is it. I opened serial monitor and sent the command to start sending codes one at a time. None worked!

I thought to then reverse engineer the Mi TV remote app. I mean it should have all the codes needed since it can control any mi tv. But before that I thought to use the superpower of searching the web to see if someone else has already done it and I found this: https://github.com/ysard/mi_remote_database

now, someone had already done something similar and so, now I had all the code sets needed. so, I cloned the repo then decrypted Xiaomi brand 153, model 5122 via their Python exporter in flipper zero format then extracted the raw mark/space microsecond timings at 38 kHz.

Now, this led me to discover that Mi TV uses a non-standard quaternary protocol (4 different space lengths: 578/867/1147/1428 µs).

Next, I flashed 3 commands → power, volume up and down.

All 3 worked!

Next, I added all the commands from a remote like navigation keys, back button etc and then used this to connect to my wifi. This TV, now I could control using the Mi Remote app as well since it was on the same network as my phone.

The next time I change my wifi password, I would again need this “gadget” and so, I created a web-ui for all the buttons of a remote and hosted a tiny server on this d1 mini.

Here is the code file if you need it:

https://drive.google.com/file/d/1INZLRXr2k0VmKKlSUtJZjiqaEJE04-5M/view?usp=sharing

Top comments (0)