Introduction: Lemonade Machine

Hello and welcome to my Lemonade Machine instructable.


This is a fun project I made for my schoolwork "If This Then That". I made this arduino project because I was to lazy to go to the kitchen to get myself a drink. So if you had the same problem than you are on the right page.

With the lemonade machine you don't have to decide which drink you have to pick because it will pick it for you. And for the people that like a bit of fun, with the timer you will have to make your drink fast and set a record for yourself and friends. I you will enjoy this tutorial and that it will come to good use.

Step 1: Components

What do you need:

- Arduino Uno

- Buzzer

- Survo

- Micro server

- Pushbutton

- LED x 3 (different colors)

- Resistor 220

- Wood glue

- Wood (you need to creat a 3 boxes with 4 short sides and 2 wide sides p.b)

- Drinking tap x3

-Screws x12

-Long male to female jumper wires x 17

-Tin (soldeer tin)

-Soldering iron

-Door hinge x3

-Tube x3

- small paper to write on and color

(In the picture you can also see which tools I used for this project)

Step 2: Getting Started

  1. Start by saw your wood to get 12 small pieces (14x7 cm) and 4 wide pieces (14x14). Use 3 of the small pieces to make a hole about 4 cm wide.(check your tap for the correct measure, you will need to fitt the tap in the hole later)
  2. Use your wood glue to glue the pieces together to create a box with a hole. So now you will have a open box consisting of 3 (14x7) piece of which two have a hole to put the tube in between, the 4th piece you need to scrub the sides to make it slide in better.
  3. Put the tub in between the holes and use super glue or wood glue to glue them
  4. You can now close the lid by slidding the other wood piece in
  5. Ad the tap at all 3 boxes and you should have it done like the last picture in the slide

Step 3: Testing Arduino With 123D Circuits

Now we will create our aurduino in 123d circuit or thinkercad. First build the circuit as shown in the first image.(see first image) Next set up a servo and a 7 segment display as shown in the rest of the pictures.

Step 4: Setting Up the Code

Now we need to set up the code. So the main loop, loops through all the different function.

So first we have the melody that plays then the arduino waits for a button to be pressed. When the button is pressed the 3 LED's will start flashing one by one. When the button is pressed again the LED that was on is saved and will flash meanwhile the servo will wave (if you made a sign). This will go on for as long as you make this function last. Next the timer starts to count up until you press the button again to end the whole sequence. So the melodie plays again and arduino waits for you to press the button.

#define NOTE_B0  31
#define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49 #define NOTE_GS1 52 #define NOTE_A1 55 #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 #define NOTE_AS4 466 #define NOTE_B4 494 #define NOTE_C5 523 #define NOTE_CS5 554 #define NOTE_D5 587 #define NOTE_DS5 622 #define NOTE_E5 659 #define NOTE_F5 698 #define NOTE_FS5 740 #define NOTE_G5 784 #define NOTE_GS5 831 #define NOTE_A5 880 #define NOTE_AS5 932 #define NOTE_B5 988 #define NOTE_C6 1047 #define NOTE_CS6 1109 #define NOTE_D6 1175 #define NOTE_DS6 1245 #define NOTE_E6 1319 #define NOTE_F6 1397 #define NOTE_FS6 1480 #define NOTE_G6 1568 #define NOTE_GS6 1661 #define NOTE_A6 1760 #define NOTE_AS6 1865 #define NOTE_B6 1976 #define NOTE_C7 2093 #define NOTE_CS7 2217 #define NOTE_D7 2349 #define NOTE_DS7 2489 #define NOTE_E7 2637 #define NOTE_F7 2794 #define NOTE_FS7 2960 #define NOTE_G7 3136 #define NOTE_GS7 3322 #define NOTE_A7 3520 #define NOTE_AS7 3729 #define NOTE_B7 3951 #define NOTE_C8 4186 #define NOTE_CS8 4435 #define NOTE_D8 4699 #define NOTE_DS8 4978
//int digit1 = 10; //PWM Display most left display
int digit2 = 9; //PWM Display second left
int digit3 = 6; //PWM Display second right display
int digit4 = 5; //PWM Display most right display
#define DIGIT_ON  LOW
#define DIGIT_OFF  HIGH
#define DISPLAY_BRIGHTNESS  500
boolean duiz = false;
boolean hon = false;
int segA = 8; 
int segB = 7; 
int segC = 10; 
int segD = 4; 
int segE = A0; //pin 6 is used bij display 1 for its pwm function
int segF = 2; 
int segG = 3; 
//
#include 
Servo servo;
int melody[] = {
  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};
int noteDurations[] = {
  4, 8, 8, 4, 4, 4, 4, 4
};
  
int tap1 = 0;
int tap = 0;
void setup(){
  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
 //pinMode(digit1, OUTPUT);
 pinMode(digit2, OUTPUT);
 pinMode(digit3, OUTPUT);
 pinMode(digit4, OUTPUT);
  
  servo.attach(A1);
  
  Serial.begin(9600);
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(A3,INPUT);
}
////////////////////////////////////////////////////////////
void loop(){
  tap1 = 0;
  servo.write(50);
  
  melodie();
  buttoncheck(); 
  ledloop();
  drinkmakingsequence();
  displayNumber();
}
///////////////////////////////////////////////////////////
void buttoncheck(){
  delay(600);
  while(digitalRead(A3) == HIGH) { };
  while(digitalRead(A3) == LOW) { };
  delay(600);
  }
void ledloop(){
  while(digitalRead(A3) == LOW) { 
  Red(); button(); Yellow(); button(); Green(); button(); 
  };
  while(digitalRead(A3) == HIGH) {
    button(); 
  };
}
void drinkmakingsequence(){
    servo.write(90);
    flash();
    delay(200);
    servo.write(20);
    flash();
    delay(200);
    servo.write(90);
    flash();
    delay(200);
    servo.write(20);
    flash();
    delay(200);
    servo.write(90);
    flash();
    delay(200);
    servo.write(20);
    flash();
    delay(500);
    servo.write(90);
    delay(200);
    servo.write(20);
    delay(200);
    servo.write(90);
    delay(200);
    servo.write(20);
    delay(200);
    servo.write(90);
    flash();
    delay(300);
    servo.write(20);
    delay(5
    ++++00);
    servo.write(50);
}
void melodie(){
    for (int thisNote = 0; thisNote < 8; thisNote++) {
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(A2, melody[thisNote], noteDuration);
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    noTone(A2);}
    delay(500);
}
void button(){
tap = digitalRead(A3);
 Serial.print(tap);
if(tap == 1){
if(tap1 == 1){
digitalWrite(13,HIGH);
tone(A2,300,200);
delay(10);
 digitalWrite(13,LOW);
}
if(tap1 == 2){
digitalWrite(12,HIGH);
tone(A2,100,300);
delay(10);
digitalWrite(12,LOW);
}
if(tap1 == 3){
digitalWrite(11,HIGH);
tone(A2,500,200);
delay(10);
digitalWrite(11,LOW);
}
}}
void flash(){
if(tap1 == 1){
digitalWrite(13,HIGH);
tone(A2,300,300);
delay(200);
 digitalWrite(13,LOW);
}
if(tap1 == 2){
digitalWrite(12,HIGH);
tone(A2,100,300);
delay(200);
digitalWrite(12,LOW);
}
if(tap1 == 3){
digitalWrite(11,HIGH);
tone(A2,500,300);
delay(200);
digitalWrite(11,LOW);
}
}
void Red(){
if(tap == 0){
digitalWrite(13,HIGH);
tone(A2,100,100);
delay(200);
digitalWrite(13,LOW);
tap1 = 1;
}}
void Yellow(){
if(tap == 0){
digitalWrite(12,HIGH);
tone(A2,200,100);
delay(200);
digitalWrite(12,LOW);
tap1 = 2;
}}
void Green(){
if(tap == 0){
  digitalWrite(11,HIGH);
  tone(A2,300,100);
  delay(200);
  digitalWrite(11,LOW );
  tap1 = 3;
}}
void displayNumber() {
 int number;
  Serial.println(number);
  
  for( int i = 0; i<=9999; i++){// for loop to pick a number from.
    duiz = false;
    hon = false;
    if(digitalRead(A3) == HIGH) { 
    break; 
    };
       for(int k = 0; k<50; k++){ // for loop to slow it down.
   
int figur = i;
 for(int digit = 1 ; digit < 5 ; digit++) { //for loop to place the number in the right digit
    //Turn on a digit for a short amount of time
    switch(digit) {
    case 1:
     if(figur > 999){                               
      //digitalWrite(digit1, DIGIT_ON);
      lightNumber(figur / 1000);            // for example 2511 / 1000 = 2
      figur %= 1000;                        // new value of figur = 511         figur = figur %1000
      
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
        if (figur < 100){
      duiz = true;
         if (figur <10){
          hon = true;
           
         }
     
      }else duiz = false; 
     }
     
      break;
   case 2:
   if(duiz == true){
    digitalWrite(digit2, DIGIT_ON);
    lightNumber(0);
     delayMicroseconds(DISPLAY_BRIGHTNESS);
     
   }if(hon == true){
    break;
   }
   
   if(figur > 99 && figur < 1000){
      digitalWrite(digit2, DIGIT_ON);
      lightNumber(figur / 100);
      figur %= 100;
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      if (figur < 10){
      hon = true;
      
      }else hon = false;
   }
    
      break;
    case 3:
    if(hon == true){
    digitalWrite(digit3, DIGIT_ON);
    lightNumber(0);
     delayMicroseconds(DISPLAY_BRIGHTNESS);
      break;
     }
   
     if(figur > 9 && figur < 100){
      digitalWrite(digit3, DIGIT_ON);
      lightNumber(figur / 10); 
      figur %= 10;
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
     }
     
      break;
    case 4:
    
    
    
    
     if(figur < 10){
      digitalWrite(digit4, DIGIT_ON);
      lightNumber(figur); 
      delayMicroseconds(DISPLAY_BRIGHTNESS); 
      
      break;
     }
  
     
    }
     //Turn off all segments
    lightNumber(10); 
    //Turn off all digits
    //digitalWrite(digit1, DIGIT_OFF);
    digitalWrite(digit2, DIGIT_OFF);
    digitalWrite(digit3, DIGIT_OFF);
    digitalWrite(digit4, DIGIT_OFF);
    
}
}}}
void lightNumber(int numberToDisplay) {
#define SEGMENT_ON  HIGH
#define SEGMENT_OFF LOW
  switch (numberToDisplay){
  case 0:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_OFF);
    break;
  case 1:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;
  case 2:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;
  case 3:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_ON);
    break;
  case 4:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;
  case 5:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;
  case 6:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;
  case 7:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;
  case 8:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;
  case 9:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_ON);
    break;
  case 10:
    digitalWrite(segA, SEGMENT_OFF);
    digitalWrite(segB, SEGMENT_OFF);
    digitalWrite(segC, SEGMENT_OFF);
    digitalWrite(segD, SEGMENT_OFF);
    digitalWrite(segE, SEGMENT_OFF);
    digitalWrite(segF, SEGMENT_OFF);
    digitalWrite(segG, SEGMENT_OFF);
    break;
  }
 
}

Step 5: Creating Your Lemonade Machine

So with this part we will start to put the things together by using tin out of sight on the back side of the lemonade machine. Spread the components apart by a great distance. Use long strips of tin to connect the 5 volts and the ground to all the connected cables. Next extend every outlet that needs to go to either a digital pin or an analoge pin with a long cable to reach the arduino that will be located on the upper side of the whole lemonade machine. Make sure to tape all the wires down so they won't touch eachother electrical currents.

*Tip

Label all wires that go to either analog or digital pins with the numbers of those digital/analoge pins (for example A3 or 13)

Hope you enjoyed this tutorial and have a great time with your Lemonade Machine!