lemonade maker

I'm trying to create a system that mixes water and lemon juice into a glass. I want to start the whole system with the flip of a toggle switch and then have everything shut off when a proximity sensor detects the liquid at the top of the glass. I am using two solenoid water valves, a standard ON/OFF toggle switch and a capacitive proximity sensor (Normally Open). I'm having a problem getting them all to work together, sometimes the switch turns on the system and opens the solenoids, but then the proximity sensor doesn't shut it off and vice versa. I'm attaching the code I'm working on. NOTE: the solenoids run off of 12V so I have two MOSFET devices to control them with the Arduino UNO. Thanks for any help you guys can be!

int toggleswitch = 0; // ON/OFF switch to start the system
int proximity = 0; //The Normally Open capacitive proximity sensor

void setup() {
pinMode(7, INPUT);//sets anolog pin 7 as an input
pinMode(8, INPUT);//sets pin 8 as an inputu
pinMode(3, OUTPUT);//sets pun 3 as an output for the water valve
pinMode(4, OUTPUT);

}

void loop() {
toggleswitch = digitalRead(8);//the variable name "toggleswitch" will be associated with pin 8
proximity = digitalRead(7);//the variable name "proximity" will be associated with pin 7

if (toggleswitch == HIGH and proximity == LOW) { //the ON/OFF switch is in the "on" position and sending signal to the Arduino
digitalWrite(3, HIGH);//Opens the water solenoid valve connected to the water container
digitalWrite(4, HIGH);
}
if (toggleswitch == HIGH and proximity == HIGH); { //the ON/OFF switch is "on" and the proximity sensor is activated by the full glass
digitalWrite(3, LOW);
digitalWrite(4, LOW);
//Both solenoids close and stop the flow of liquids
}
if (toggleswitch == LOW) {
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
}

LEMONADE_MAKER.ino (1.17 KB)

Please post your code and a schematic

int toggleswitch = 0; // ON/OFF switch to start the system
int proximity = 0; //The Normally Open capacitive proximity sensor

void setup() {
pinMode(7, INPUT);//sets anolog pin 7 as an input
pinMode(8, INPUT);//sets pin 8 as an inputu
pinMode(3, OUTPUT);//sets pun 3 as an output for the water valve
pinMode(4, OUTPUT);

}

void loop() {
toggleswitch = digitalRead( 8 );//the variable name "toggleswitch" will be associated with pin 8
proximity = digitalRead(7);//the variable name "proximity" will be associated with pin 7

if (toggleswitch == HIGH and proximity == LOW) { //the ON/OFF switch is in the "on" position and sending signal to the Arduino
digitalWrite(3, HIGH);//Opens the water solenoid valve connected to the water container
digitalWrite(4, HIGH);
}
if (toggleswitch == HIGH and proximity == HIGH); { //the ON/OFF switch is "on" and the proximity sensor is activated by the full glass
digitalWrite(3, LOW);
digitalWrite(4, LOW);
//Both solenoids close and stop the flow of liquids
}
if (toggleswitch == LOW) {
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
}

I don't have a schematic made right now

lhartz996:
I don't have a schematic made right now

S' OK. I can wait

Please remember to use code tags when posting code

if (toggleswitch == HIGH and proximity == HIGH); Oops

I'm trying to have the proximity switch be what shuts off the solenoids without having the toggle switch turned off

Try the line I highlighted without the semicolon.
Semicolon at the end of @"if"s are rarely a good idea

I didn't even catch that, I'll give it a shot. Here's that schematic, forgive how horrible it is, I'm going to school for mechanical engineering and had hoped not to have to deal with these very often lol.

it won't let me post the picture of the schematic

I've got it to work with the switch (the solenoids open when the switch is flipped "ON"), but the proximity sensor does nothing (it is getting power and is getting signal, it has an indicator led that flashes when activated)

Update, I got the entire system to work appropriately. Discovered that even though the proximity sensor was labeled a Normally Open, it was acting like a Normally Closed, so I made some adjustments and now everything is gravy. Thanks for your help!