hi. I'm pretty new to arduino and need your help troubleshooting my code.
my prodject is an bottle filler. I want to fill diffrent size bottle without telling the arduino which size it's filling. my idea was to use a copperwire and the fillingtube (stainless) and when the water level hits the copper wire circuit is cloesd and use that ass the trigger to close the valve. i made a prototyp on my breadbord and used a potentiometer instead of the copper wire. in my code i want the arduino to read from analog pin and when the volts gets over 4V it should close the valve. hope you guys can help me.
int LEDPin1 = 10;
int buttonPin = 3;
int LEDPin2 = 11;
int LEDPin3 = 12;
int LEDPin4 = 8;
int buttonRead;
int buttonPin3 = 2;
int buttonRead3;
int offPin1 = A0;
int offPin2 = A2;
int readVal;
float V2 = 0;
int dt = 250;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LEDPin1, OUTPUT);
pinMode(LEDPin2, OUTPUT);
pinMode(LEDPin3, OUTPUT);
pinMode (buttonPin, INPUT);
pinMode (LEDPin4, OUTPUT);
pinMode (buttonPin3, INPUT);
pinMode (offPin1, INPUT);
pinMode (offPin2, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
buttonRead = digitalRead(buttonPin);
buttonRead3 = digitalRead(buttonPin3);
readVal = analogRead (offPin1);
V2 = (5. / 1023.) * readVal;
Serial.println(V2);
delay(dt);
if (buttonRead == 1) {
digitalWrite (LEDPin1, LOW);
digitalWrite (LEDPin2, LOW);
digitalWrite (LEDPin3, LOW);
}
if (buttonRead == 0) {
digitalWrite (LEDPin1, HIGH);
delay (1000);
digitalWrite (LEDPin2, LOW);
digitalWrite (LEDPin3, LOW);
delay (1000);
digitalWrite (LEDPin2, HIGH);
delay (5000);
digitalWrite (LEDPin2, LOW);
delay (2000);
while (V2 < 4.0) {
digitalWrite (LEDPin3, HIGH);
readVal = analogRead (offPin1);
}
digitalWrite (LEDPin3, LOW);
delay (3000);
digitalWrite (LEDPin1, LOW);
}
if (buttonRead3 == 0) {
digitalWrite (LEDPin4, HIGH);
delay (5000);
}
else {
digitalWrite (LEDPin4, LOW);
}
}
sketch_sep22a.ino (1.38 KB)