Created
December 30, 2013 02:51
-
-
Save claytantor/8177242 to your computer and use it in GitHub Desktop.
This is an arduino sketch to control a 12v solenoid in a timed loop. It will pressurize a chamber at a specific rate and then power the valve venting the chamber.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
valve_60 | |
Turns on an 12v selenoid on, then off, repeatedly. | |
*/ | |
// Pin 13 has an LED connected on most Arduino boards. | |
// give it a name: | |
const int valve = 13; | |
const int led = 9; | |
const int vent_time_min = 10; //10 sec | |
const int pressure_time_min = 60*10; //10 min | |
int counter = 0; | |
int switch_val = 0; | |
int modulo_led = 0; | |
int modulo_valve = 0; | |
int toggle_time_valve = millis(); | |
int toggle_time_led = millis(); | |
int valve_state = 0; | |
int min_ms = 1000*60; | |
// the setup routine runs once when you press reset: | |
void setup() { | |
// initialize the digital pin as an output. | |
Serial.begin(9600); | |
pinMode(valve, OUTPUT); | |
digitalWrite(valve, LOW); | |
switch_val = 0; | |
toggle_time_valve = millis(); | |
pinMode(led, OUTPUT); | |
} | |
// the loop routine runs over and over again forever: | |
void loop() { | |
int millis_time = millis(); | |
modulo_led = millis_time % 1000; | |
modulo_valve = millis_time % vent_time_min; | |
//there is a timer against millis | |
//if the valve is in an off position and the pressure timer has expired then vent | |
// and set the timer to count to the vent time | |
if (counter > pressure_time_min && switch_val==0) { | |
/*Serial.print("setting to valve to HIGH at:"); | |
Serial.print(millis_time); | |
Serial.print(" switch:"); | |
Serial.println(switch_val);*/ | |
digitalWrite(valve, HIGH); // turn on the valve | |
switch_val = 1; | |
counter = 0; | |
} | |
//else if the valve is on and the vent timer has expired then close the valve | |
// and set the timer to count up to the pressure time | |
else if (counter>vent_time_min && switch_val==1) { | |
/*Serial.print("setting to valve to LOW at:"); | |
Serial.print(millis_time); | |
Serial.print(" switch:"); | |
Serial.println(switch_val); */ | |
digitalWrite(valve, LOW); // turn off the valve | |
switch_val = 0; | |
counter = 0; | |
} | |
//this manages a timer led that uses the same approach | |
if (modulo_led == 0 && LOW == digitalRead(led)) { | |
digitalWrite(led, HIGH); // turn on the valve | |
toggle_time_led = millis_time+1000; | |
/*Serial.print("LED Time:"); | |
Serial.print(millis_time); | |
Serial.print(" counter:"); | |
Serial.println(counter); */ | |
counter+=1; | |
} else if (millis_time > toggle_time_led && HIGH == digitalRead(led)) { | |
digitalWrite(led, LOW); // turn on the valve | |
counter+=1; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how about the connection thru Microcontroller and the materials to be used