Created
April 29, 2024 11:32
-
-
Save Robotto/e35f34ab7cd9d533fc307e040d36fe63 to your computer and use it in GitHub Desktop.
pump-o-tron!
This file contains hidden or 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
#define N_MEASUREMENTS 32 //Number of analogRead (pressure) measurements to average over | |
#define MAX_PRESSURE 830 | |
const int pumpPin = 8; //LOW TO RUN, HIGH TO STOP | |
const int valvePin = 9; //HIGH TO CLOSE, LOW TO OPEN | |
const int pressurePin = A0; | |
bool valveState=false; | |
unsigned long pressureFiltered = 0; | |
void setup() { | |
Serial.begin(115200); | |
// put your setup code here, to run once: | |
digitalWrite(pumpPin,HIGH); | |
digitalWrite(valvePin,LOW); | |
pinMode(pumpPin,OUTPUT); | |
pinMode(valvePin,OUTPUT); | |
} | |
void loop() { | |
unsigned long ADCSum=0; | |
for (int i=0; i<N_MEASUREMENTS; i++) { | |
ADCSum+=analogRead(pressurePin); | |
} | |
pressureFiltered = ADCSum>>5; | |
char RX; | |
if(Serial.available()) | |
{ | |
RX=Serial.read(); | |
if(RX=='1') {digitalWrite(pumpPin,!digitalRead(pumpPin)); delay(100);} | |
if(RX=='2') valveState = !valveState; | |
} | |
if(digitalRead(pumpPin)==LOW) valveState=HIGH; //KEEP VALVE CLOSED WHEN RUNNING PUMP | |
digitalWrite(valvePin,valveState); | |
Serial.print(digitalRead(pumpPin)); | |
Serial.print(','); | |
Serial.print(valveState); | |
Serial.print(','); | |
Serial.println(pressureFiltered); | |
delay(10); | |
if(pressureFiltered > MAX_PRESSURE) digitalWrite(pumpPin,HIGH); //PUMP AUTO OFF! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment