Relay shield and arduino uno for light control

Hello,

I am doing a project for controlling a 4 light sources. I need to turn on a light source each 5 second. For this, I bought an arduino uno and relay shield v2.0.

  1. I Stacked the Relay Shield onto Arduino. And I connected Arduino to PC using a USB cable.

  2. I connected each light source like this:

a) The positive wire pass throw the COM and NO before to be connected to battery.
b) The negative wire pass is connected directly to the battery.
c) I configure the follwing pin to control four relays:

pin 7 -> relay 1
pin 6 -> relay 2
pin 5 -> relay 3
pin 4-> relay 4
I developed my program like this:

[code]// On the relay v2.0, the 4 relays are controlled by the 4 following pins.
// these pins correpond to the same 4 pins on the Arduino Uno micro controller.
/*
relay 1—> pin 7.
relay 2—> pin 6.
relay 3—> pin 5.
relay 4—> pin 4.
*/
int light1=7; // Arduino pin 7 to control light1 connected to the relay 1.
int light2=6; // Arduino pin 6 to control ligh2 connected to the relay 2.
int light3=5; // Arduino pin 5 to control light3 connected to the relay 3.
int light4=4; // Arduino pin 4 to control ligh4 connected to the relay 4.
// the setup routine runs once when you press reset:
void setup()
{
// declare pin 7 to be an output to control the relay 1 and consequently the ligh1.
pinMode(light1,OUTPUT);
pinMode(light2,OUTPUT);
pinMode(light3,OUTPUT);
pinMode(light4,OUTPUT);

}

// the loop routine runs over and over again forever:
void loop()
{
//------------------------light1------------------------
digitalWrite(light1,HIGH);// NO1 and COM1 Connected;
delay (5000);
digitalWrite(light1,LOW);// NO1 and COM1 Disconnected;

// //------------------------light2------------------------
digitalWrite(light2,HIGH);// NO2 and COM2 Connected;
delay (5000);
digitalWrite(light2,LOW);// NO2 and COM2 Disconnected;

//------------------------light3------------------------
digitalWrite(light3,HIGH);// NO3 and COM3 Connected;
delay (5000);
digitalWrite(light3,LOW);// NO3 and COM3 Disconnected;

//------------------------light4------------------------
digitalWrite(light4,HIGH);// NO4 and COM4 Connected;
delay (5000);
digitalWrite(light4,LOW);// NO4 and COM4 Disconnected;

}
// Fin du programme
[/code]

I remark that the leds corresponding to relays work correctly turn on for each 5 seconds. But the relays are not clicked (no noise). Besides, the light sources are not worked (it is turn off ). Therefore, I changed the light source connection such that the positive wire of each light source is connected between the NO and COM. In this case, the lights sources are worked. But, the problem is : light sources are always turn on even i changed the LOW and HIGH status of pins. What is the problem. any help please!

The relays need power. Try using a power adapter to power the Uno.

Thanks for you response. Can you explain me more please. I connected the arduino uno in my PC using the usb cable.

In your response, you mean that I have to connect also the relay shield in power. What pin should I use to connect it please? Have any documentations to help me? I am very very pressed.

No problem.

Using USB for power only provides 5 volts to the Uno and shield(s). The relay shield I have required power to be supplied to the Vin pin on the Arduino for it to operate.

There should be a power jack on the Uno where a power adapter can be connected.