Go Down

Topic: Light sequence for 4 x 50 W halogen lights (240V) (Read 631 times) previous topic - next topic


I am very new to Arduino, have done some initial courses online after I bought the starter kit. The more I read the more confused I get. I am an artist and am practical minded. Also interested in electronics but am not so confident.
What I wonder is 2 things.

When I create my sketch for 4 halogen lights that will need to go on one after another, in a sequence, and then reverse, back and forth. I intend the light to go on for 1 sec and then off moving over to the next light and so on, with NO delay in between. The movement of light will create an old fashioned way of making an image move, like a flicker book, but here with lights instead.

I am uncertain on the CODE. I am uncertain on the Voltage, how to convert/use the Arduino (UNO) to be able to output the sequence to actual 4 halogen lights of 50W each / 240V power supply.

My thinking is that the sequence is fairly straight forward.
In reality (the analog world we live in) I see light 1 turns on, stays on for 1 sec, turn off and without delay shifts to light 2 that turns on for 1 sec and so forth until the 4th light when it goes on 1 sec, the off for part of a sec and then reverse back all the way to light 1.

I am also keen on building in a sensor, that allow the piece to stay in OFF mode whilst the room is empty (to save energy and bulbs).

How do I ground 4 lights?

Would I dare ask if I think the right way here; excuse me being novice. Actually doing the code completely makes my confidence non existent....
Am I anywhere on a right track and could anyone just advice on best way of getting on with coding as well as understanding voltage etc...

/*sensor with 4 leds to control 4 pins output to 4 halogen lights in a sequence with a sensor control*/

int sensorPin = 8;
int ledPin = 3;
int ledPin = 5;
int ledPin = 6;
int ledPin = 9

void setup()
  pinMode(sensorPin, INPUT);
  pinMode(ledPin, OUTPUT);

I would be grateful for any advice on how to sort of kick start confidence in this project as the initial online making a led light with a switch an so on was simple when guided, but left on my own devices I sort of loose track of pins, outputs, void loops etc. I am not asking for anyone to do it for me, but rather put me in a good direction. I have looked on so many online things that my brain is more confused....
Thanks for your patience.


Nov 21, 2012, 10:06 pm Last Edit: Nov 21, 2012, 10:14 pm by HazardsMind Reason: 1
Code wise it is incredibly simple to do, hardware wise, not so much. First since you are new to arduino, have you tried the blinking LED example? That is a great way to begin. If you want, you can wire 4 LEDs just to test your code, then move on to the hard stuff later. Now since you going to be around 240V, you may want to use relays that can handle that amount of voltage and current.

I also took a look at your code and noticed that all your LEDs are named the same, dont do it that way. Instead do like this:
Code: [Select]

byte pin[LEDS] = {3,5,6,9}; // these particular pins are your Pulse Width Modulation pins, it will work that same with pins 2,3,4,5

void setup()
  for (int LEDS = 0; LEDS <= 3; LEDS++)
        pinMode(pin[LEDS], OUTPUT); //sets the pins as output
        digitalWrite(pin[LEDS], LOW); //sets the LEDs as low(off) just to make sure

void loop()
   int i;
  for ( i = 0; i <= 3; i++)
    digitalWrite(pin[i], HIGH);
    delay(1000); //1 second delay as ON

for (i = 3; i >= 0; i--)
    digitalWrite(pin[i], HIGH);


try that for a start.
My GitHub:


Start with LEDs and get that working before adding the 240V circuitry.

I'd leave the people-motion sensor for last...   You'll have to figure-out the hardware connections depending on how the motion sensor works.   Typically, you run a motion sensor off 12VDC, and the output either goes from 0 to 12V when motion is sensed, or the other way from 12V to zero.  Or, it might have normally-open or normally-closed relay contacts.   On the software side, all you need is an If-statement...  Do one thing if the condition is met, and do something else (or nothing) if the condition is not met.

how to convert/use the Arduino (UNO) to be able to output the sequence to actual 4 halogen lights of 50W each / 240V power supply.
You MUST isolate the high voltage from the Arduino and yourself.  The easiest and best way to to that (if you don't need dimming) is with solid state relays (one relay per lamp or one per output-channel.) (example).  Make sure the solid state relay can be triggered from the Arduino's 5V output, and the output rating should be at least 240V and about 1 Amp.  (240V at 50W is about 1/4 of an amp).

A relay is just a switch that's operated electrically...    With a tiny amount of electricity (from a battery or Arduino, etc.) you can turn on/off a huge amount of electricity.

Mechanical relays could work, but they make a bit of noise, might be slow, and most won't work direclty from the Arduino's 5V output.
How do I ground 4 lights?
On the AC side, the ground is not part of the lighting circuit.   If the lamp (or appliance) is grounded, the metal case is grounded for safety.   If something goes wrong and a "hot" wire somehow gets connected to the case, nobody will get shocked because the case remains at ground potential (zero volts).  With this error condition...  Current flows directly to ground (with essentially no resistance) and the circuit breaker blows.

And since the AC is isolated by the relay, you don't need a connection between the Arduino's low-voltage ground and the AC ground.  (One of the relay'slow-voltage input terminals is connected to the Arduino's ground.)

So if the lamp has 3 connections/terminals, one is ground, one is "hot" and the other is "neutral".  Current flows (something like water in a pipe*) from hot, through the light, and back through the neutral.  (The power source or battery is like a water pump.)

A switch (or relay) wired in series with the hot (or neutral) connection can break the connection,  stop current flow, and turn off the light.  Normally the switch should be wired to the hot side, but a switch on either side will break the circuit and turn off the light.

* Water pipes are a actually poor analogy, because if you break a wire (or open a connection) the electrons don't spill out. :D  And, it's AC, so the direction of curren flow is alternating, and it may be hard to understand how resistance is related to work & energy such as "generating" heat or light.  The important thing to understand is that electricity flows in a circuit/circle, and if you break the circuit, currnet stops flowing.


If you want to keep the code simple you might just find a separate motion sensor that turns an outlet on and off.  Plug the Arduino (via AC/DC adapter) and the lights into this switched outlet and then all you have to write code for is sequencing the lights.  I have seen motion sensors like this around, and one was even built into our garage, so I am sure there must be a 240V version where you live. 

Be thankful that you still can get 50W halogens, in the US many of them are being phased out due to environmental legislation and they are becoming harder to find.

Go Up