I have just got a relay shield for my arduino. I downloaded the demo code from Relay Shield | Seeed Studio Wiki to test it, and have altered the variable delays succesfully.
The demo code switches all of the four relays at the same time.
I would like to switch the relays in sequence with a delay between each. Then have a delay at the end before looping back to the beginning.
Can someone help me do this please
Try out the blink example. It looks like the shield is just "if you put the pin on, the relay turns on," so the blink example (with pins 4, 5, 6, or 7 instead of 13) will turn the relays on and off.
Then just play with the digitalWrite and delay functions.
// RelayShieldDemoCode.pde to control seeed relay shield by arduino.
// Copyright (c) 2010 seeed technology inc.
// Author: Steve Chang
// Version: september 2, 2010
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
unsigned char relayPin[4] = {4,5,6,7};
void setup()
{
int i;
for(i = 0; i < 4; i++)
{
pinMode(relayPin[i],OUTPUT);
}
}
//just an simple demo to close and open 4 relays
// every other 1s.
void loop()
{
int i=0;
for(i = 0; i < 4; i++)
{
digitalWrite(relayPin[i],HIGH);
delay(200); //delay between turning on each relay, 200 milliseconds
}
delay(1000);
for(i = 0; i < 4; i++)
{
digitalWrite(relayPin[i],LOW);
delay(200); //delay between turning off each relay, 200 milliseconds
}
delay(1000);
}
You can simply turn them off or on using below code.
void setup() {
// initialize the digital pins as an output.
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop() {
digitalWrite(4, HIGH); // Turns ON Relay on digital pin 4
delay(1000); // wait for a second
digitalWrite(5, HIGH); // Turns ON Relay on digital pin 5
delay(1000); // wait for a second
digitalWrite(6, HIGH); // Turns ON Relay on digital pin 6
delay(1000); // wait for a second
digitalWrite(7, HIGH); // Turns ON Relay on digital pin 7
delay(1000); // wait for a second
digitalWrite(4, LOW); // Turns OFF Relay on digital pin 4
delay(1000); // wait for a second
digitalWrite(5, LOW); // Turns OFF Relay on digital pin 5
delay(1000); // wait for a second
digitalWrite(6, LOW); // Turns OFF Relay on digital pin 6
delay(1000); // wait for a second
digitalWrite(7, LOW); // Turns OFF Relay on digital pin 7
delay(1000); // wait for a second
}
Hi Lefty.
This is how I have modified the sketch. The system is fot actuating valves for drip photography. I have got the sensors, and delay system to trigger the shutter and the flash so everthing now works. I will now have to start studying the software, because I would like an lcd to display my settings.
Thanks for your help.
Hi guys,...I know this is an older thread, but the code is close to what I'm trying to do. I just need to add RTC functions to the code.
How I need it, is I want to add 24 hour timing with 7 day week programmable that will allow me to turn the individual relays on/off multiple times a day, 7 days a week with skip days.
I'm new, so if you could start me in the right direction or better yet there is most likely code already that would do this,...show me the way.
How I need it, is I want to add 24 hour timing with 7 day week programmable that will allow me to turn the individual relays on/off multiple times a day, 7 days a week with skip days.
So, what have you tried? What are you timing? How do you know what time/day it is?
show me the way.
Go to the end of the block, and turn left. If that is wrong, go two blocks and turn right.
You have to have some idea where you are going before a map is going to be useful. If you do, you haven't told us where that is.
Hello Please, I want a program to Shield has 8 relay when using switch on pin No. 0, for example, All relays operate sequentially after time 5 seconds each of them to keep working to that Turn off this switch, If you connect another switch on pin No. 2 only work relays No. 1, 3, 5, 7 sequentially duration time 5 seconds each .