Tagged ‘DS18B20

Well I have everything assembled on the breadboard and it’s working properly. The software is done (except for tweaks in the temperature control logic that I can only do when in use) and it clocked in at just under 1000 lines. The bulk of the code is in the UI, as most of the hardware functions are done through the libraries available for these components. I’m using glcd to control the KS0108 128×64 LCD, IRremote to read input from my unknown IR receiver, EEPROM to read/write to the memory on the Arduino ATMega1280, OneWire & DallasTemperature to read temperature from the DS18B20 sensor, and RealTimeClockDS1307 & Wire to keep the time with the DS1307 RTC.

The main loop takes care of three timers: temperature polling, slope calculation, and a pre-emptive heat off timer that is used when the temperature is rising quickly, to ensure the desired temp is not over-shot. It also listens for IR input and adjusts the LCD backlight using an LDR analog input and a PWM output connected to the backlight anode (with 200ohm resistor). I was a bit worried that the current draw would be too much for the arduino digital pin but ohms law says 9.2 milliamps which I confirmed with a multimeter. Not sure why the community using these LCDs seem to think the current draw is too high… hopefully I’m not missing anything.

The slope calculation timer is set at 5 minutes. This is the where I’ve placed the control heat function call, as to limit the on/off cycle to a minimum of 5 minutes. I don’t want the relays to drive me insane with unthrottled clicking! It also calls the graphing function that draw the current temperature on the screen. I’ve put in 24 hour history logging of temperature values and an ability to scroll through the graph, cause I’m thinking it might be cool to see the temp lows of the previous night or how quickly the temperature rises in summer or something. Actual temperature polling and numerical display is every 4 seconds (split into two 2 second parts, to allow time to read the sensor value (The DS18B20 has a ~700ms response time). Only if the temperature changes will the LCD redraw, to eliminate flickering.

Physically, the heat will be controlled using 2 of the 4 relays on a module I picked up off ebay. This module is responsible for the highest current draw of the project, clocking in at about 120 milliamps. Actually it was enough to bring down the USB voltage from 5.12v to about 4.6v. Because of this I’ll probably be using a 9v or 12v input to the barrel connector to make use of the voltage regulator on the arduino board. Without a constant 5v signal the LCD contrast will change when the relays are activated which just looks tacky.

Time is kept with the Dallas DS1307 RTC, which initially I received (as a package) with a defective crystal. After pulling my hair out for a few hours I decided to give up and buy another crystal from a local shop and voilĂ , the clock started ticking. It’s not the most accurate clock, especially when running on battery. I noted a 6 second lag the first day and about 2-3 second the next few days (while leaving it powered on). I think this might go down a bit more once I move it from the breadboard to a soldered prototype PCB. If it doesn’t, I can set the time every couple of months. My schedule times are only down to the hour anyway so it’s not a big deal.

I don’t have much to say about the IR receiver, except that it works well with the library (IRremote) Ken Shirriff wrote, and hasn’t given me any trouble. Briefly I was only getting garbage reads but quickly found a bad jumper on the breadboard knocking down the voltage too low. It seems to decode almost everything so I won’t have a problem mapping the functions to key codes from the harmony remote. I’ll just pick a random device and use that as a base code set.

Next up is soldering this down to a prototype shield with some headers to connect to the sensors (which will be mounted outside of the enclosure). I still haven’t decided on an enclosure but I’m leaning toward a single gang recessed AC receptacle and a wall mount box to put overtop. That way I can hide the AC/DC transformer and separate the PCB from the powering.

Here’s the loaded breadboard. From left to right we have the DS1307 RTC, The DS18B20 Temp Sensor, the LDR, two LEDs I was using for testing, and the IR sensor. The big metal thing is the potentiometer for the LCD backlight. The Relay module is in the top left and obviously the LCD is above and the arduino is on the right.

IMG_0001.JPG
View all photos at Picasa Web Albums