Pages: [1]   Go Down
Author Topic: programming relay shield  (Read 3569 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have just got a relay shield for my arduino. I downloaded the demo code from   http://seeedstudio.com/wiki/Relay_Shield   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

* RelayShieldDemoCode.pde (1.29 KB - downloaded 79 times.)
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You mean like this?

Code:
//  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);
 
}

Lefty
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Lefty that works. However what I want is to be able to do is  alter the variables for each relay individually, not to be all the same
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 83
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK try below, The output pins used are pin 4 to 7

You can simply turn them off or on using below code.
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
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi.
Yes I understand that, so I will play around with that.
Thanks
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

* sketch_mar15_valve_timings.ino (0.92 KB - downloaded 53 times.)
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 83
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good Luck!  you can refer http://arduino.cc/en/Tutorial/LiquidCrystal for interfacing LCD.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Thank You in advance,---Rick
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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?

Quote
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.
Logged

Pages: [1]   Go Up
Jump to: