Properduino - When an Engineer Gardens - Part 1 - Le Propergator Watering System by grahamslawson

Step 4: Use your Relays!

relay active.jpg
relay pcb bottom.jpg
build a circuit like this one using most of the parts from step one
Include the LED so you know when the relay should be on
Make sure the relay extension cord IS NOT PLUGGED IN!!!
Write up a program that turns the relay on for 2 seconds when the character "R" is received over Serial and when a button on pin 12 is pulled HIGH, the relay turns on.
Make sure you have a button on pin 12 or comment that bit out =]
for some reason it returns numbers when you press a key that ins't R. I think its the DEC I put after it =/
It should look like this:

//Relay controller for water pump
//LMC

int relay = 10;
int button = 12;
int thirteen = 13;
int val;

void setup (){
pinMode(thirteen, OUTPUT); //start of setup basic cmds
digitalWrite(thirteen, HIGH); //debug light
delay(500); //WAITZ!!!
pinMode(relay, OUTPUT);
Serial.begin(19200);
Serial.println('Bonjour. Press R to turn relay on for 2 seconds');
digitalWrite(thirteen, LOW); //End of setup cmds
delay(500); // end of setup cmds

}

void loop(){

if (Serial.available()) {

val = Serial.read();
if (val=='R'){
digitalWrite(thirteen, HIGH);
digitalWrite(relay, HIGH);
delay(2000);
digitalWrite(relay, LOW);
digitalWrite(thirteen, LOW);
} else {
Serial.print("You pressed:");
Serial.print(val, DEC);
Serial.println(". Press R for Relay, Any other key will do nothing");
}

}

if (digitalRead(button) == HIGH){
digitalWrite(thirteen, HIGH);
digitalWrite(relay, HIGH);
delay(2000);
digitalWrite(relay, LOW);
digitalWrite(thirteen, LOW);
}

delay(500);
}

Upload it to your board
Open your serial monitor
Send some R's

You should hear the relay clicking over and the LED should light up.
If not, youve put the transistor in wrong and you now need to redo it all =]
You can now see why I didn't put the transistors and all that in the box =]
Sorry the picture is a duplicate of the first step.

 
Remove these adsRemove these ads by Signing Up
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!