News

Alexa Controlled AirCon Unit

🇬🇧 · Derby Makers · Bernard Killeen

By Brendan Stafford The Problem I recently had air conditioning installed in my home extension. It is supplied with a hand controller that has a wide range of functions. I should have asked for the Wi-Fi option but I missed a trick. I quite fancied the idea of controlling it via Alexa inside the house and via my phone when outside. A discussion at one of our maker meetings set me thinking. It seems that an Arduino extension called SinRic Pro will implement Alexa commands in a ‘home made’ Arduino based device. Having learned about SinRic Pro, and the ability to control devices by Alexa voice commands, I then decided to make a device that can mimic the InfraRed controller. Learning about the Handset First of all I needed to decode the protocol that the remote used. I built a simple decoder using a trusty old Arduino Uno I had to hand. An Infra Red receiver diode can be interrogated by the code in order to ‘see’ the protocol. There is also a lot of information on the internet about IR communication for this type of application. Similar protocols are used by a range of hand sets for controlling household devices such as TVs, PVRs, etc. With this I established an understanding of the message format and worked out the messages I would need to switch it on, off, change the temperature, and flip between Econ and Auto modes (the remote can do a fair few other things but I didn’t feel I needed them). I then wrote a sketch using the same Uno, and found I was reliably able to control the AC to my desires. The transmitter LED was under powered but more of that later. Integrating WiFi and Alexa Great – so now I needed to integrate the WiFi side. The ESP32 is ideal as it integrates the WiFi hardware and can be programmed using the Arduino IDE. I bought an ESP32 S2 mini ( https://www.wemos.cc/en/latest/s2/s2_mini.html# ) for the princely sum of £4.00! The new ESP arrived so I wrote my new program and hooked up the ESP to the IR LED and was amazed at how easily it attached to my wifi and connected to SinRic I thought I was about there, but … I tried out my new solution and found that it didn’t work – well, ok, it worked about one time in five Diagnosing the problem In order to diagnose what was going on I had to break out the oscilloscope, which I had not used in years, so that needed a chunk of work just to relearn how to use it. With the scope I was able to see that the timing of my encoded IR signal was getting corrupted – with some of the marks and spaces being extended by a couple of hundred microseconds. I discussed this with a few of our Makers. They suggested looking at the operating system, FreeRTOS. I read up a bit about it and conjectured that some other tasks were likely interrupting and causing the delays. After some more playing with the basics of FreeRTOS I found that the ESP code generated by my compile runs as nine tasks. The main task running is, imaginatively, called “loopTask” and has priority 1 (this is my main loop). The global configMAX_PRIORITIES seemed to be set at 25, and it seems legitimate priorities go up to configMAX_PRIORITIES-1. When I set loopTask to 23 the behaviour was unchanged, but when I set it to 24 it looked like the interrupting task was no longer outbidding it and the timing worked as per my intentions So I changed my code to set the priority of loopTask to 24 before encoding the IR and then set it back to 1 just after. It’s pretty much a bodge – certainly not elegant, but it does what I need so I decided I would live with that. Electronics Hardware Next, I needed to sort out the electronics – and this is another topic I could do with some help on as I know next to nothing about it. The power output of the ESP32’s pin is too low to effectively drive the IR LED so a transistor based circuit is needed. I got a start by looking at https://www.gsnetwork.com/led-resistor-values-for-current-limiting-resistor/ for some guidance on the right value of resistor to use. That site says – Min Resistor = (Voltage Supplied – Vf) / Max Current My IR LED has a forward voltage of 1.2 V and a current of 100 mA and I am using 5 V so that led me to a calculation of – (5 V – 1.2 V)/0.1 A = 38 ohm Finally, I needed to understand how to incorporate the transistor. A fellow Maker, Bernard, advised me “For this application you are using the transistor as a switch. Your calculations look correct and a 38 or 47 ohm resistor should work fine. The transistor gain is the ratio of collector current to base current and is around 100 or so for the 2N2222.”, and the following diagram – Having put it all together this solution works really well, so I’m delighted. The Finished Article The unit needs to be powered from a USB supply. It is located conveniently near the air con unit. Now I can use the handset if I need to, but Alexa can control it quite effectively from anywhere in the house. I also have the capability to control it using my phone from anywhere I can get internet. The best bit is that it cost less than £20!

Maker Projects