Looking for Example code for the Relay Board Shield

Anyone have some example code to use with the relay board shield? Perhaps code to switch each of the 4 relays on one at time for 5 seconds and then off again.


There are many "relay board shields".
Link to the one you have.

Did you go through the examples that come with the IDE.
Activating a relay (writing a pin HIGH or LOW) is a basic task, like switching a LED on/off.
Covered in several examples.

You can first use delay() to turn the relays on/off 5 seconds apart.
But if your program has to do anything else (delay blocks), then use millis() for the timing.
The "BlinkWithoutDelay" example shows you how.

Yeah... Start with the basic Blink Example with one of the relay inputs connected to pin-13 so you can see the LED go on/off when the relay switches. Then you can add outputs or change to different output pins, change the timing, etc.

It might be a good idea to write a little sequencing test program to make sure the relays are connected correctly and working as expected.

I see a lot of examples for the Arduino for Windows 1.8.5 under File/Examples menu but, nothing that specifically says Relay Board. I was successful with the Blink example with the on-board LED and changed the delay to 10 sec instead of 1 sec.

Controlling a relay on a relay shield is the same as controlling a LED.
You just have to know which (fixed) pin the relay is connected to.
That's why I asked for a link to the relay shield.

I couldn't tell what pins the relays were connected to by looking. I was able to figure out that they are connected to pins 4, 5, 6, 7 through trial and error.

Thanks for the help!

This relay shield uses pin 4,5,6,7.
You can see that on the Eagle board image on that page. The thin blue lines.