Step 15: Arduino Sketch
SKETCH FOR WORK THE TESTING TOOL:
This Sketch is just to get you started and will allow you to control the outlets in a very general way. You can visit:
Luke Liseman and his "Garduino" design
http://www.instructables.com/id/Garduino_Gardening_Arduino/
Here you will find other sensors that you can play with. These will safely work on the
POW-Rduino.
POW_Rduino SKETCH:
// Turn on LED when the button is pressed
// send sensor output to RELAY1 and RELAY2
// will be used to turn on high voltage outlets for POW-Rduino
// and keep it on after it is released
#define LED 13 // the pin for the LED
#define BUTTON 2 // the input pin where the pushbutton is connected
#define RELAY1 7 // pin for RELAY1 connection
#define RELAY2 8 // pin for RELAY2 connection
int val = 0; // val will be used to store the state
// of the input pin
int old_val = 0; // this variable stores the previous
// value of "val"
int state = 0; // 0=LED off while 1=LED on
void setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output
pinMode(BUTTON, INPUT); // and BUTTON is an input
pinMode(RELAY1, OUTPUT); // tell Arduino RELAY1 is an output
pinMode(RELAY2, OUTPUT); // tell Ardrion RELAy2 is an output
}
void loop() {
val = digitalRead(BUTTON); // read input value and store it
// check if there was a transition
if ((val == HIGH) && (old_val == LOW)){
state = 1 - state;
}
old_val = val; // val is now old, let's store it
if (state == 1) {
digitalWrite(LED, HIGH); // turn LED on
} else {
digitalWrite(LED, LOW); // turn LED off
}
if (state == 1) {
digitalWrite(RELAY1, HIGH); // singnal sent to RELAY1
} else {
digitalWrite(RELAY1, LOW);
}
if (state == 1) {
digitalWrite(RELAY2, HIGH); // singnal sent to RELAY2
} else {
digitalWrite(RELAY2, LOW);
}
}
Remove these ads by
Signing Up




































Not Nice















Visit Our Store »
Go Pro Today »



