Hello all in the arduinosphere,
I am a super noob and have taken on a project beyond my newly acquired knowledge base. Im am attempting to make an automated liquid fill control regulator. I dont know what t call it but when the liquid gets so low the arduino needs to send a high pulse to the relay which opens the valve. I have all the hardwaretaken care of. I just cant get the coding down. I can get the sensor to display distance on the serial monnitor but how do code, if the output = 12" open the valve, when it reads 4" close the valve? The goal is to automatically fill the resevoir when it gets low. Can anyone help me please to figure out how to code this. Im using an arduino uno and an HC-SR04 sensor. This is what I have so far:
int trigPin = 11;
int echoPin = 12;
long duration, inches;
int selenoidPin = 10;
const int threshold = 6;
void setup() {
//Define inputs and outputs
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(selenoidPin, OUTPUT);
//Serial Port begin
Serial.begin (9600);
}
void loop() {
int digitalValue = digitalRead(echoPin);
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
if (digitalValue > threshold) {
digitalWrite(selenoidPin, HIGH);
} else {
digitalWrite(selenoidPin, LOW);
}
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = (duration/2) / 74;
Serial.print(inches);
Serial.print("in, ");
Serial.println(digitalValue);
delay(1);
}
Please tell me why it will read the distance but not engage the selenoid by sending a HIGH to the pin?
Thank you
FirstAttempt.ino (860 Bytes)