crytosis:
sorry for the late update
that idea looks compromising.. for now i already done with the valve part.. just a simple edit from the debounce example.. assume the led is valve for now.. since my valve use higher voltage (12V) than arduino can supply (5V), which pin should i put the external power supply.. for the timer part, i still dont know how to put it inside the code
// constant and variable (SOV = solenoid valve)
const int inletButton = 2; // SOV switch input
const int outletButton = 3; // SOV switch input
const int motorButton = 4; // motor switch input
const int motorPin1 = 5; // pin 2 on L293D
const int motorPin2 = 6; // pin 7 on l293D
const int inlet = 11; // SOV
const int outlet = 12; // SOV
int inValve = HIGH;
int outValve = HIGH;
int inletState;
int outletState;
int inletButtonState = LOW;
int outletButtonState = LOW;
int enablePin = 9; // pin 1 on L293D
// debounce
long lastDebounceTime = 0;
long debounceDelay = 50;
void setup() {
// set switch as input
pinMode(inletButton, INPUT);
pinMode(outletButton, INPUT);
pinMode(motorButton, INPUT);
// set other as output
pinMode(inlet, OUTPUT);
pinMode(outlet, OUTPUT);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
// enable pin
digitalWrite(inlet, inValve);
digitalWrite(outlet, outValve);
digitalWrite(enablePin, HIGH);
}
void loop() {
int reading1 = digitalRead(inletButton);
int reading2 = digitalRead(outletButton);
// start the motor
if (digitalRead(motorButton) == HIGH) {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
}
// stop the motor
else {
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
}
// debounce
if (reading1 != inletButtonState) {
lastDebounceTime = millis();
}
if (reading2 != outletButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading1 != inletState) {
inletState = reading1;
if (inletState == HIGH) {
inValve = !inValve;
}
}
if (reading2 != outletState) {
outletState = reading2;
if (outletState == HIGH) {
outValve = !outValve;
}
}
}
digitalWrite(inlet, inValve);
digitalWrite(outlet, outValve);
inletButtonState = reading1;
outletButtonState = reading2;
}
i include an attachment of my circuit (still dont know if it good or bad).. by the way, do you have any idea regarding how to connect external power supply to the solenoid(valve)
OK you will need a relay or some form of transistor to switch the higher voltages - personally i would just go with a 4 port optoisolated relay board - less than $10 and your Arduino is protected from nasty stuff
http://yourduino.com/sunshop2/index.php?l=product_detail&p=201
Your code seems to jump all over the place - can i suggest you put it in the format that i stepped out above and see how far that gets you ?
Craig