Drink Machine Using UNO

Hi everyone! I am very new to wiring and coding in general so I apologize in advance. I am currently working on a project for school, it is a drink pouring machine that can mix 2 liquids together with a push of a button. I have am working on an UNO and have: 2 12v parastaltic pumps, a button, and a 4 channel relay (along with other basic components). I have tried the wiring and coding configurations this website gave me, but it does not seem to be working! Any and all help is greatly welcomed and appreciated! Cheers

dear Nick,

you need to read a value from your button using “digitalRead()”

after that you check if the value HIGH give HIGH for the first relay and wait a little and off to the first relay and ON the second wait some minute and trend it off using “digitalWrite(,)”

1 Like

Thanks hammoudeh94 for the idea,
Currently I have in there
sensorValue = analogRead(sensorPin);
if(sensorValue < 300){
digitalWrite (Rum, LOW); //pump 1 on
but I can give digitalRead() a shot. As it stands, my coding reads as follows:

{

pinMode(Lemonade, OUTPUT);

pinMode(Limeade, OUTPUT);

pinMode(Button, INPUT);

digitalWrite (Lemonade, HIGH); //pump 1 off

digitalWrite (Limeade, HIGH); //pump 2 off

delay(1000); // let relays settle down before running the first time. // Might be for LEDs only ***************************************************

}

void loop() //this part of the code loops and loops forever

{

sensorValue = analogRead(sensorPin);
//this part makes the LEDs strobe to make the robot look cool

//this stops when the start button is pressed

//if bottom is pressed the LEDs show which motor is running

sensorValue = analogRead(sensorPin);

if(sensorValue < 300){

digitalWrite (Lemonade, LOW); //pump 1 on

digitalWrite (Limeade, LOW); //pump 2 on

delay(8000); // waits 8 sec to pump 1/4 oz of liquid

delay(8000); // waits 8 sec to pump 1/4 oz of liquid

digitalWrite (Limeade, HIGH); // turns off Limeade pump 2

// at this point the Limeade has been on for 16 sec and has pumped 1/2 oz

delay(16000); // waits 8 sec to pump 1/4 oz of liquid

digitalWrite (Lemonade, HIGH); //turns off pump 1

}

}

sorry lets start from beginning,

you need to push a push bottom after that the two pump on.

else nothing happens.
??

Sorry hammoudeh94 let me clarify,
My idea was to have the one button wired up, so when pushed it would activate the 2 pumps, having them run for a certain amount of time, and in the end reset to be able to do it over again.

dear nick-woods,

what i mean the push bottom give you a 1 or 0,
for that we use digitalRead(),
and because we want to wait if the bottom pushed or not we use while loop,like this:

void setup() {
pinMode(Lemonade, OUTPUT);

pinMode(Limeade, OUTPUT);

pinMode(Button, INPUT);

}

void loop(){

digitalWrite (Lemonade, HIGH); //pump 1 off

digitalWrite (Limeade, HIGH); //pump 2 off

delay(1000);
while(digitalRead(sensorPin) == 0);

while(digitalRead(sensorPin) == 1){

digitalWrite (Lemonade, LOW); //pump 1 on

digitalWrite (Limeade, LOW); //pump 2 on

delay(8000); // waits 8 sec to pump 1/4 oz of liquid

delay(8000); // waits 8 sec to pump 1/4 oz of liquid

digitalWrite (Limeade, HIGH); // turns off Limeade pump 2

// at this point the Limeade has been on for 16 sec and has pumped 1/2 oz

delay(16000); // waits 8 sec to pump 1/4 oz of liquid

digitalWrite (Lemonade, HIGH); //turns off pump 1

}

}
please try this code and give me the result please

Hammoudeh94,
Thank you for all the help, I was messing around with what you gave me and ended up getting this to work. Thanks for the help.
const int buttonPin1 = 1; //The pin button 1 is connected to
const int buttonPin2 = 2; //The pin button 2 is connected to
const int buttonPin3 = 3; //The pin button 3 is connected to
const int pumpPin1 = 4; //The pin pump 1 is connected to
const int pumpPin2 = 5; //The pin pump 2 is connected to
const int pumpPin3 = 6; //The pin pump 3 is connected to

int button1State = 0; //A variable to hold if button 1 was pressed
int button2State = 0; //A variable to hold if button 2 was pressed
int button3State = 0; //A variable to hold if button 3 was pressed

void setup(){

pinMode(pumpPin1, OUTPUT); //Defines pump 1 as output
pinMode(pumpPin2, OUTPUT); //Defines pump 2 as output
pinMode(pumpPin3, OUTPUT); //Defines pump 3 as output
pinMode(buttonPin1, INPUT); //Defines button 1 as input
pinMode(buttonPin2, INPUT); //Defines button 2 as input
pinMode(buttonPin3, INPUT); //Defines button 3 as input
}

void loop(){

button1State = digitalRead(buttonPin1); //Reads if the button has been pushed (on/off)
if (button1State == HIGH){ //If the button was pushed execute the following commands:

digitalWrite(pumpPin1,LOW); //Turn on pump 1
digitalWrite(pumpPin2,LOW); //Turn on pump 2

delay(10000); //wait 10 seconds (10000 milliseconds)
digitalWrite(pumpPin1,HIGH); //Turn off pump 1
digitalWrite(pumpPin2,HIGH); //Turn off pump 2

} else { //If the button was not pushed
digitalWrite(pumpPin1, HIGH); //Keep pump 1 off
digitalWrite(pumpPin2, HIGH); //Keep pump 2 off
}
//------------------------------------------------------------------------------------------------------------------------------------
button2State = digitalRead(buttonPin2); //Reads if button 2 has been pushed (on/off)
if (button2State == HIGH){ //If the button was pushed execute the following commands:

digitalWrite(pumpPin1,LOW); //Turn on pump 1
digitalWrite(pumpPin3,LOW); //Turn on pump 2

delay(10000); //wait 10 seconds (10000 milliseconds)
digitalWrite(pumpPin1,HIGH); //Turn off pump 1
digitalWrite(pumpPin3,HIGH); //Turn off pump 2

} else { //If the button was not pushed
digitalWrite(pumpPin1, HIGH); //Keep pump 1 off
digitalWrite(pumpPin3, HIGH); //Keep pump 2 off
}
//------------------------------------------------------------------------------------------------------------------------------------
button3State = digitalRead(buttonPin3); //Reads if button 2 has been pushed (on/off)
if (button3State == HIGH){ //If the button was pushed execute the following commands:

digitalWrite(pumpPin2,LOW); //Turn on pump 1
digitalWrite(pumpPin3,LOW); //Turn on pump 2

delay(10000); //wait 10 seconds (10000 milliseconds)
digitalWrite(pumpPin2,HIGH); //Turn off pump 1
digitalWrite(pumpPin3,HIGH); //Turn off pump 2

} else { //If the button was not pushed
digitalWrite(pumpPin2, HIGH); //Keep pump 1 off
digitalWrite(pumpPin3, HIGH); //Keep pump 2 off
}
}

:+1::+1::+1: if you want anything i am here,
and you can make this machine working on Bluetooth in future.
and good job for you.