views:

5080

answers:

4

I'd like to start out with the Arduino to make something that will (preferably) dim my room lights and turn on some recessed lighting for my computer when a button or switch is activated.

First of all, is this even possible with the Arduino?

Secondly, how would I switch on and off real lights with it? Some sort of relay, maybe?

Does anyone know of a good tutorial or something where at least parts of this are covered? I'll have no problems with the programming, just don't know where to start with hardware.

+2  A: 

There is just a ton of this kind of stuff at the Make magazine site. I think you can even find some examples of similar hacks.

Charlie Martin
+3  A: 

Hi, Most people do it using triacs. A triac is like two diodes in anti-parallel (in parallel, but with their polarity reversed) with a trigger pin. A triac conducts current in either direction only when it's triggered. Once triggered, it acts as a regular diode, it continues to conduct until the current drops bellow its threshold.

You can see it as a bi-directional switch on a AC line and can vary the mean current by triggering it in different moments relative to the moment the AC sine-wave crosses zero.

Roughly, it works like this: At the AC sine-wave zero, your diodes turn off and your lamp doesn't get any power. If you trigger the diodes, say, halfway through the sine's swing, you lamp will get half the normal current it would get, so it lights with half of it's power, until the sine-wave crosses zero again. At this point you start over.

If you trigger the triac sooner, your lamp will get current for a longer time interval, glowing brighter. If you trigger your triac latter, your lamp glows fainter.

The same applies to any AC load.

It is almost the same principle of PWM for DC. You turn your current source on and off quicker than your load can react, The amount of time it is turned on is proportional to the current your load will receive.

How do you do that with your arduino?

In simple terms you must first find the zero-crossing of the mains, then you set up a timer/delay and at its end you trigger the triac.

To detect the zero-crossing one normally uses an optocoupler. You connect the led side of the coupler with the mains and the transistor side with the interrupt pin of your arduino. You can connect your arduino IO pins directly to the triacs' triggers, bu I would use another optocoupler just to be on the safe side.

When the sine-wave approaches zero, you get a pulse on your interrupt pin. At this interrupt you set up a timer. the longer the timer, the less power your load will get. You also reset your triacs' pins state. At this timers' interrupt you set your IO pins to trigger the triacs.

Of course you must understand a little about the hardware side so you don't fry your board, and burn your house, And it goes without saying you must be careful not to kill yourself when dealing with mains AC =).

HERE is the project that got me started some time ago. It uses AVRs so it should be easy to adapt to an arduino. It is also quite complete, with schematics. Their software is a bit on the complex side, so you should start with something simpler.

Marcelo MD
+4  A: 

An alternative (and safer than playing with triacs – trust me I've been shocked by one once and that's enough!) is to use [X-10][1] home automation devices.

There is a PC (RS232) device (CM12U UK or CM11 US) you can get to control the others. You can also get lamp modules that fit between your lamp and the wall outlet which allows you to dim the lamp by sending signals over the mains and switch modules which switch loads on and off.

The Arduino has a TTL level RS232 connector (it's basically what the USB connection uses) – Pins 0 and 1 on the Diecimila so you could use that, connect it via a level converter which you can buy or make and connect to the X-10 controller, theirs instructions on the on the Arduino website for making a RS232 port.

Alternatively you could use something like the FireCracker for X-10 which uses 310MHz (US) or 433MHz (UK) and have your Arduino send out RF signals which the TM12U converts into proper X-10 mains signals for the dimmers etc.

In the US the X-10 modules are really cheep as well (sadly not the case in the UK).

[1]: X-10 http://en.wikipedia.org/wiki/X10_(industry_standard)

Stephen Harrison
A: 

As a quick-start, you can get yourself one of those dimmerpacks (50-80€ for four lamps). then build the electronics for the arduino to send DMX controls: Arduino DMX shield

You'll get yourself both the arduino-expirience + a good chance of not frying your surrounding with higher voltage..

oori