Drink Mixer Project -- Coding problem, at a loss.

Hey everyone!

I'm fairly new and ignorant to the micro controller and adruino enviornment. I am a final semester Electrical Eng. Tech. student though so i do possess a good working knowledge of electronics. Problem is I've always fallen short when it comes to programming.

Anyhow,

the project i'm working on is a drink mixer, real simple, (or so i thought):

Drink mixer machine, which can make 4 different drinks, using a combination of 4 different liquids. (2 liquors, 2 chasers)

4 Solenoid vales controlled by an arduino, when a drink is selected, the 2 pertinent valves open. 4 Inputs (one input for each possible drink to be selected)

I've made up some real basic code, trying to keep it simple just to get the thing working.

Problem:

Whenever the arduino is powered up, it just seems to cycle through making the same drink everytime even if none of the input pins are switched to HIGH.

The Code:

// Input PBs
int Drink1 = 4;
int Drink2 = 5;
int Drink3 = 6;
int Drink4 = 7;

// Output Pins to Solenoids
int Mix1 = 8;
int Mix2 = 9;
int Mix3 = 10;
int Mix4 = 11;

//Drink 1 is Mix1 & 3
//Drink 2 is Mix2 & 4
//Drink 3 is Mix1 & 4
//Drink 4 is Mix2 & 3

// Assign input pins



void setup()

{
pinMode(Drink1, INPUT);
pinMode(Drink2, INPUT);
pinMode(Drink3, INPUT);
pinMode(Drink4, INPUT);

//Assign output pins
pinMode(Mix1, OUTPUT);
pinMode(Mix2, OUTPUT);
pinMode(Mix3, OUTPUT);
pinMode(Mix4, OUTPUT);

digitalWrite (Drink1, LOW);
digitalWrite (Drink2, LOW);
digitalWrite (Drink3, LOW);
digitalWrite (Drink4, LOW);
}


void loop()


{
  delay (2000);
  if (digitalRead(Drink1) == HIGH)
  {
    digitalWrite(Mix1, HIGH);
    delay (5000);
    digitalWrite(Mix3, HIGH);
    delay (1000);
    digitalWrite(Mix1, LOW);
    digitalWrite(Mix3, LOW);
   }
   if (digitalRead(Drink2) == HIGH)
   {
     digitalWrite(Mix2, HIGH);
    delay (5000);
    digitalWrite(Mix4, HIGH);
    delay (1000);
    digitalWrite(Mix2, LOW);
    digitalWrite(Mix4, LOW);
   }
  if (digitalRead(Drink3) == HIGH)
  {
    digitalWrite(Mix1, HIGH);
    delay (5000);
    digitalWrite(Mix1, LOW);
    digitalWrite(Mix4, HIGH);
    delay(1000);
    digitalWrite(Mix4, LOW);
  }
  if (digitalRead(Drink4) == HIGH);
  {
    digitalWrite(Mix2, HIGH);
    delay (5000);
    digitalWrite(Mix2, LOW);
    digitalWrite(Mix3, HIGH);
    delay(1000);
    digitalWrite(Mix3, LOW);
  }
    
}

Any and all help is appreciated! Excuse my severe ignorance when it comes to this area.

Drinks on me if someone can help me figure this out!

Bretland

It looks like your switches are wired from V+ to the input. Do you have pull down resistors? A better way to wire switches is from ground to the digital input and enable the internal pull up resistors. The switch will be HIGH when unpressed and LOW when pressed. If you don't have the open switch tied to ground or V+, the input is floating and the state is undefined.

@Groundfungus "It gets hot so it must be working"

Not if it gets too hot! I've got a computer here to fix. About a minute after powering up, the southbridge heatsink is almost too hot to touch. I guess that a new motherboard is needed!

Thanks for the reply!

Didn't realize how sensitive the arduino was to minute voltages. ( I thought it had to see pretty darn close to 5v to flip an input as HIGH)

I changed the code as follows and its working! (almosttt!)

Now its constantly just making drink 4, but if i remove that section of code it works as its supposed to! (Just being able to make the first 3 drinks)

Maybe there is some issue i'm not seeing here.

Code:

// Input PBs
int Drink1 = 4;
int Drink2 = 5;
int Drink3 = 6;
int Drink4 = 7;

// Output Pins to Solenoids
int Mix1 = 8;
int Mix2 = 9;
int Mix3 = 10;
int Mix4 = 11;

//Drink 1 is Mix1 & 3
//Drink 2 is Mix2 & 4
//Drink 3 is Mix1 & 4
//Drink 4 is Mix2 & 3

// Assign input pins



void setup()

{
pinMode(Drink1, INPUT_PULLUP);
pinMode(Drink2, INPUT_PULLUP);
pinMode(Drink3, INPUT_PULLUP);
pinMode(Drink4, INPUT_PULLUP);

//Assign output pins
pinMode(Mix1, OUTPUT);
pinMode(Mix2, OUTPUT);
pinMode(Mix3, OUTPUT);
pinMode(Mix4, OUTPUT);

}


void loop()


{
  delay (2000);
  if (digitalRead(Drink1) == LOW)
  {
    digitalWrite(Mix1, HIGH);
    delay (5000);
    digitalWrite(Mix3, HIGH);
    delay (1000);
    digitalWrite(Mix1, LOW);
    digitalWrite(Mix3, LOW);
   }
   if (digitalRead(Drink2) == LOW)
   {
     digitalWrite(Mix2, HIGH);
    delay (5000);
    digitalWrite(Mix4, HIGH);
    delay (1000);
    digitalWrite(Mix2, LOW);
    digitalWrite(Mix4, LOW);
   }
  if (digitalRead(Drink3) == LOW)
  {
    digitalWrite(Mix1, HIGH);
    delay (5000);
    digitalWrite(Mix1, LOW);
    digitalWrite(Mix4, HIGH);
    delay(1000);
    digitalWrite(Mix4, LOW);
  }
  if (digitalRead(Drink4) == LOW);
  {
    digitalWrite(Mix2, HIGH);
    delay (5000);
    digitalWrite(Mix2, LOW);
    digitalWrite(Mix3, HIGH);
    delay(1000);
    digitalWrite(Mix3, LOW);
  }
  
    
}

Thanks so much for the input!

--Bretland

if (digitalRead(Drink4) == LOW);

Take out the semicolon.

BTW, where's my drink? :)

Just saw that and fixed it. It all works as expected!

Come by southern ontario haha.

Bretland: Just saw that and fixed it. It all works as expected!

Come by southern ontario haha.

It's a long way from London to Ontario just for a drink. I'm not that desperate!