8 Channel relay module question

Hi All,

I had a question on a relay module I just purchased.

5v Active Low 8 Channel Relay Module Board for Arduino Pic AVR MCU PLC Control for sale online | eBay?

Above is what I purchased, and in my Arduino code has all pins set to output and low. I noticed when I power up my Arduino (my relay is wired into 5V and ground, as well as pins 2 - 9), all the red LED's turn on and all 8 relays 'click'. I would assume this means all the relays are turned on, but my code is set as the following:

void setup() {

for(int i=2; i<=53; i++) {
pinMode(i, OUTPUT);

I watched YouTube videos of other relays that only illuminate red when they set a pin to high. When I set a pin to high, the LED turns off. Did I purchase the wrong relay? I acquired a schematic of the relay from the seller which is attached, but I'm not sure how to read it.

Any input is greatly appreciated.

Its not wrong, with your setup relays turn on when you set digitalpin to LOW and turn off if you set to HIGH.

omersiar:
Its not wrong, with your setup relays turn on when you set digitalpin to LOW and turn off if you set to HIGH.

Oh really? I was able to dissect that off of some code I found on youtube, and assumed it set all pins to output, and all pins to low at setup. Then turn on when you set digitalpin to HIGH and turn off if you set to LOW. Any advice on how to fix this to do what I want? I'm still a beginner at C.

This relay module is 5V active low.

That line is from the ebay link you posted, and is consistent with the schematic.

but I'm not sure how to read it.

If you look you will see blocks labeled U1/U2/U3/U4.. Each one has a line coming from Vcc(supply voltage) through two LED's (one to opto switch the relay, and the other as indicator) and going to IN1/In2/In3/In4. These are your input pins, and when they re LOW, ie. connected to ground, they let current flow through that circuit and turn on the LEDs and the relay.

Write your code to set the pins to OUTPUT, and set them HIGH in your setup. They will be at the same voltage as Vcc and no current can flow through the circuit. Write them LOW in your code when you want to turn on the relays.

When a pin is configured to OUTPUT with pinMode, and set to LOW with digitalWrite, the pin is at 0 volts. In this state it can sink current, e.g. light an LED that is connected through a series resistor to, +5 volts, or to another pin configured as an output, and set to HIGH.

See the section "Defining Pin Levels HIGH and LOW" in this reference section http://arduino.cc/en/Reference/Constants

Write your code to set the pins to OUTPUT, and set them HIGH in your setup. They will be at the same voltage as Vcc and no current can flow through the circuit. Write them LOW in your code when you want to turn on the relays.

I read the contents of the link, thanks, but I'm still trying to wrap my mind around what you said above. So basically, I'm doing the opposite - to turn on set to LOW, and turn off set to HIGH, is this due to this particular relay board?

This is my first experience with this particular relay board.

eros:
This is my first experience with this particular relay board.

And many like it of course.

Something not covered in the Arduino tutorials, and a major problem with the examples they give, is that there is absolutely no convention at all in electronics to suggest that you drive a line HIGH to turn something on and in fact in many if not most logic devices and systems, the convention is exactly the opposite; you have active LOW enable lines and controls.

This particularly applies as a safety consideration when you are wiring up switches as inputs to projects, you do not want to be extending the supply line anywhere where you can avoid it, just in case it should be accidentally grounded.

Try the following however im not sure why you are cycling through 53 different outputs on your relay module if there are only 8 relays.... the relay board I have has four and it is pins 4,5,6,7 that run the seperate relays you might have better luck cycling through 3 through 13 on your board. I compiled this code but i didnt load it in because my relay board is burried in my living room wall.

EDIT!!!! i misread the above post your setup switches on low code should be fixed
int i=2;
void setup()
{
pinMode(i, OUTPUT);
digitalWrite(i, HIGH);
}

void loop()
{
do//starts post-test loop
{
digitalWrite(i,LOW);//turns the relay on
delay(1000);
digitalWrite(i,HIGH);//turns the relay off
i++;//incrementis the value of i thus incrementing which pin turns on on the next loop
}while(i<=53);//checks to see if i is less than or equal to 53
}