Temperature sensor and high voltage light control

Hello everyone!

I am building a setup using Arduino to control the light output of a 120v 75w bulb on my reptile cage. I want to place a temperature sensor inside the tank on the basking spot and the cool side. I want Arduino to regulate how much light comes out of the heat lamp based on the temperature so that it is at a steady 110F. I have two issues that I am trying to figure out..

Temp sensor: I bought a tmp36 temp sensor and placed it on a 2 foot cable and tried reading the temps. They were all over the place and not steady. So I cut the cable and tried using 2 inches, and the temp is pretty steady (goes up or down 1 degree sometimes). I need to have a temp sensor that can be on a 6 foot cable from the Arduino to the inside of the tank. Which temp sensor would achieve this and be very accurate at doing so? If I need to buy some new ones I don't mind, I just want to make sure that the reading are correct and steady since this will control how much light is put out.

Dimming 120v 75w bulb: How would I dim the heat lamp bulb using arduino? I could place a servo on the dimmer that comes with the bulb, but I don't believe this to be the best way.. I think the best way would be to have some sort of circuit board that arduino would interface with and control the dimming. It needs to be able to step up/down in increments since it will be controller by the temperature.

Any feedback is greatly appreciated. I want to make sure I do this correct because I don't want the bulb turned up too high or too low because the temp sensor isn't reading correctly or the dimmer is malfunctioning.

Caution when working 120VAC must be taken but for your lamp control look for items like the following: http://www.instructables.com/id/Arduino-controlled-light-dimmer-The-circuit/

Also have you read the datasheet on the TMP36 for use with long leads or remote location that should provide some solutions for your wire length. http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Temp/TMP35_36_37.pdf

The temperature sensor here is simple, just throw in an Maxim DS18B20 digital temperature sensor and you are good to go. I would suggest against using any analog temperature sensors as any transmission line can be problematic, but digital ones are immune to that. That 1-Wire digital temperature sensor chip is in an TO-92 package and can work by "parasite power" from 1-Wire bus, so clip off the power pin (or use it as well for better performance, but I doubt you will ever need that), attach the 1-Wire bus and ground wires and heat shrink it you get a waterproof digital thermometer.

The bulb controlling part requires more work. If you are good with just switching the bulb on and off you can use an solid state relay. If you are dimming it then more work is required and you will have to embrace the fact that your Arduino will be exposed to some (current limited) mains voltage. The idea is to watch for the zero crossing of mains power, delay a while and fire a triac. By doing this you control the amount of power get sent to the bulb.

I would suggest you to split this mains watching off to an ATtiny85 chip and use opto-isolated I2C bus from your main Arduino to control it, so that an insulation failure won't take down your entire setup, just one subsystem, probably just fry one socketed ATtiny85 chip, optocouplers and some passives.

Try putting a capacitor (maybe 1uF) across the Arduino’s analog input (between the input and ground). That should help to filter-out the noise and smooth the readings.

Of course, you need to isolate the AC from the Arduino. You can do that with a relay, a solid state relay, or an opto-isolator. In your case, I’d recommend a relay or solid state relay.

AC dimming is somewhat tricky… You have to detect the AC line frequency and synchronize with it. But, heaters don’t use “dimming”, and I don’t recommend that you use it either.

You’ve probably noticed how a regular house furnace works… When the temperature is below the target, the furnace switches on, when it’s above the target, it switches off.

There is normally some hysteresis or “swing” to keep the thing from oscillating or to keep the relay from “chattering”. That means you might turn the heater on at 109F or below and off at 111F or above. (Or, you can make it tighter with a fraction of a degree of hysteresis).

If you get a solid state relay, make sure to get one that’s rated for switching 120VAC or more at 1 Amp or more for the 75W bulb. With solid state relays, it’s very important that you get one designed for AC. And get one that can use a 5V control voltage. (They are very common.)

Mechanical relays that can operate from the Arduino (5V coil voltage at 40mA or less) are not as common, but they are available. Again, make sure the contacts are rated for at least 120VAC at 1 Amp. A mechanical relay is less costly than a solid-state relay.

I would also use a solid state relay. Your incandescent 75 watt light bulb heater will have inrush (could be 8 - 10 times), so using a solid state relay that is rated above 5 - 6 amps would provide more peace of mind. The solid state relay is also quiet compared to the clicking of a mechanical relay. You can build a SSR, but buying one is also easy and provides more safety around AC power, since this will probably be used, unattended, 24 hours a day in your application.

Thanks all of you for your advice.

I ended up buying this AC Dimmer from inmojo: http://www.inmojo.com/store/inmojo-market/item/digital-ac-dimmer-module-lite-v.2/ and then I bought a 20x4 LCD and a bunch of DS18B20 temp sensors from Adafruit.

I got a little test all wired up and displaying the max/min/current temps for the cage. I'm considering moving most of the code over to the raspberrypi just because I want to have a web interface with graphs and all that plus I'm going to have relays that will control how many hours the lights are on each day and these need to be time based. I don't feel like spending the time to wire up a timer to the arduino or something like that. Probably just use the arduino as a middleman for the sensors and the raspberry pi.

Thanks for mentioning the DS18B20. It works very accurate and doesn't have the issue the TMP36 had.

I will post my success after I get the system near completion :)