Thursday, July 26, 2012

Mozart, an IR temperature controller

The first project here is an IR Controller for an auxiliary Air Conditioner unit. The System consists of a large 12,000 BTU Window Air Conditioner, an embedded controller measuring temperature and transmitting IR "power on" sequences to the A/C unit and an embedded controller measuring current to ascertain that the IR command was fulfilled.
Background Our plant room has several large plant stands with fluorescent light fixtures providing growing light for several hundred African Violets. A total of 98 T-8 flourescent tubes of 32 watts each produces more heat than the central AC system can keep up with. The Violets need an ambient temperature that does not exceed 80 degrees F. To assist with cooling the room it was necessary to add an auxiliary window AC. The additional AC unit is a large GE 12,000 BTU air conditioner. The GE has a current draw of 12 amps which means it would be pretty expensive to run full time unless it was really needed. This AC box has an IR Remote control to turn the power on and off. This is great news from a control standpoint since it means we won't have to get involved with switching the 110 V line with a relay. Any potential power relay would be large and have to handle at least 12 amps. Controlling the power with an IR remote control simplifies power handling since the only task would be to replicate the Power On/Off IR codes of the Infrared Remote Control. The codes would be sent to the AC unit when it was desired to turn it on or off. The decision to send IR codes is made by measuring the ambient air temperature. When the air temperature is above the target temperature, the AC is activated via an IR command. When the temp has fallen to 1/2 degree less than the target temperature, another IR command is broadcast shutting the AC unit off.
Control Codes A Google search for command codes from the GE Remote control was performed with not much luck. There are plenty of codes on the web for TV sets but most of these were just numbers to program a Universal Remote. Nothing could be found about IR controlled Air Conditioners. The protocol would be even more useful than a programming code but alas, no protocol information could be found either.
Arduino to the Rescue! Since I couldn't find any protocol information online it was time to do a little bench work with a scope, an Arduino and an inexpensive IR decoder module. Typically an IR command is a sequence of pulses modulated on a 38 khz carrier. An IR decoder will detect the 38 khz IR and put out a sequence of 0's and 1's. The decoder I used is a widely available one made by Sharp, pn QH30301 and only requires +5V and ground. A third lead puts out the pulse train.
Pressing the "power on" button on the remote and setting the scope to store the waveform, I obtained the following trace for the power on command:
The trace is useful to get detailed timing info for a sequence of pulses but in order to look at many of these pulses with the hope of finding a pattern requires some computer help with measuring the pulse widths and supplying the measured values in a handy listing. The Adafruit website has a good tutorial about decoding raw IR codes and more importantly, Adafruit code for an Arduino is on github at http://www.ladyada.net/learn/sensors/ir.html
I grabbed the sketch from github and loaded an Arduino Uno I had lying around. Surprisingly, everything worked the first time. The above output from the Arduino terminal shows the measured pulse widths which correspond to the scope trace above. This is for the "Power On" button of the IR remote control. Careful examination of the listing showed a repeating pattern after 43 pulses. Next step is to load up an Arduino with these timings for 43 pulses.  Because the IR needs to be modulated at 38 khz, the PWM output of an AVR is the logical choice. Fortunately, there is an excellent Arduino IR library by Ken Shirriff using the PWM pin to control an IR LED. The library can be obtained from http://arcfn.com/files/IRremote.zip

Once the library is installed in the Arduino toolchain, it was easy to build a sequence of bytes representing the on and off times of the pulse train. The times were manually inserted into an array, rawCodes, as listed below. This data is then sent with a simple function call,  irsend.sendRaw(rawCodes, codeLen, 38);  For the record, here is the data sequence this function uses:

unsigned int rawCodes[RAWBUF] = {4700, 4200, 800, 1400, 800, 300, 800, 350, 750, 350, 750, 350, 800, 300, 750, 350, 800, 350, 750, 350, 750, 1500, 700, 350, 800, 350, 700, 1500, 750, 1500, 700, 1500, 750, 1450, 750, 1500, 700, 1500, 750, 350, 750, 400, 700};


The IR diodes and their respective drivers were repurposed from a TV-B-Gone. This device has 4 diodes with discrete transistor drivers. The TV-B-Gone circuitry was designed for 3.3 volt operation which was perfect since the Arduino has a regulated 3.3 volt output available. The Arduino, TV-B-Gone and temperature sensor fit handily into a recycled plastic project box. The case front and rear panels had a few extra cutouts which were covered by electrical tape, other existing cutouts served to route the power cable, IR LEDs, and the DS18B20 temperature probe.
Code for the Arduino is hosted by GitHub at:

https://github.com/tgdevelop/Mozart

Mozart has been working well with a few exceptions. The exceptions are when the AC is still running after it was commanded to turn off. This can happen if something such as a chair was placed in the way or if someone walked in front of the device just as is was issuing an IR command, effectively blocking the AC unit from seeing the command. Similarly, the same situation can exist if it is trying to switch the AC power on and the signal was blocked. A green LED was added to the front of Mozart to determine if the unit thinks the AC is running or not.

The ultimate solution for this problem of "is it running or not?" will be wireless feedback using an AC current monitor and a Zigbee RF link. This new project is documented in the next section and is named "Wolfie".

Tuesday, July 24, 2012

Electronic Project Blog

The purpose of this blog is to gather in one place the photos, code, schematics and general information of my electronic projects. The span of projects is wide from monitoring temperatures, watering African Violets, an outdoor Flower garden, Grow Boxes or an Orchid Greenhouse. There are also IR control projects, intelligent thermostats, moisture sensing and septic tank fluid level monitoring. All this and more will be presented here over the next several years.