ardutronic
Published © CC BY-NC-SA

Automatic mighty drink maker!

The project was divided into three parts - a prototype, a contactless payment, and a final device. This material is the first of them.

IntermediateWork in progress5 hours187
Automatic mighty drink maker!

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
PCBWay Custom PCB
PCBWay Custom PCB
×1
DC motor (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Code

bartender.ino

Arduino
#include <Adafruit_NeoPixel.h>
#define PIN 11
#define NUMPIXELS 7
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 250;

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

int button = A7;
int rgb = 11;
int ir = A3;

#define enA 10
#define in1 13
#define in2 12
#define enB 9
#define in3 8
#define in4 7

int adc_key_val[5] = {600, 650, 700, 800, 900};
int NUM_KEYS = 5;
int adc_key_in;
int key = -1;
int oldkey = -1;

int motorSpeed = 50;

void setup()
{
  Serial.begin(9600);
  pixels.begin();
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
  { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ; // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, SSD1306_WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(2000);
  // display.display() is NOT necessary after every single drawing command,
  // unless that's what you want...rather, you can batch up a bunch of
  // drawing operations and then update the screen all at once by calling
  // display.display(). These examples demonstrate both approaches...
}

void loop()
{
  adc_key_in = analogRead(button); // read the value from the sensor
  key = get_key(adc_key_in);       // convert into key press

  display.clearDisplay();

  display.setTextSize(1);              // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE); // Draw white text
  display.setCursor(0, 16);             // Start at top-left corner
  display.println(F("Choose a coctail 1-3"));
  display.display();

  if (key != oldkey) // if keypress is detected
  {
    delay(50);                       // wait for debounce time
    adc_key_in = analogRead(button); // read the value from the sensor
    key = get_key(adc_key_in);       // convert into key press
    if (key != oldkey)
    {
      oldkey = key;
      if (key >= 0)
      {
        display.clearDisplay();
        display.setCursor(0, 16);
        switch (key)
        {
          case 0:
            display.println(F("Coctail nr.: 1"));
            display.display();
            Serial.println("S1 OK");
            red();
            delay(1000);
            M1();
            delay(1000);
            break;
          case 1:
            display.println(F("Coctail nr.: 2"));
            display.display();
            Serial.println("S2 OK");
            green();
            delay(1000);
            M2();
            delay(1000);
            break;
          case 2:
            Serial.println("S3 OK");
            break;
          case 3:
            display.println(F("Coctail nr.: 3"));
            display.display();
            Serial.println("S4 OK");
            blue();
            delay(1000);
            M1();
            delay(1000);
            break;
          case 4:
            Serial.println("S5 OK");
            break;
        }
        display.clearDisplay();
        display.setCursor(10, 16);
        display.setTextSize(2); 
        display.println(F("THANKS"));
        display.display();
        delay(2000);
      }
    }
  }

  Mstop();
}

void red()
{
  for (int i = 0; i < NUMPIXELS; i++)
  {
    pixels.setPixelColor(i, pixels.Color(50, 0, 0)); // Moderately bright green color.
    pixels.show();                                   // This sends the updated pixel color to the hardware.
    delay(delayval);                                 // Delay for a period of time (in milliseconds).
  }

  for (int i = NUMPIXELS; i >= 0; i--)
  {
    pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Moderately bright green color.
    pixels.show();                                  // This sends the updated pixel color to the hardware.
    delay(delayval);                                // Delay for a period of time (in milliseconds).
  }
}

void green()
{
  for (int i = 0; i < NUMPIXELS; i++)
  {
    pixels.setPixelColor(i, pixels.Color(0, 50, 0)); // Moderately bright green color.
    pixels.show();                                   // This sends the updated pixel color to the hardware.
    delay(delayval);                                 // Delay for a period of time (in milliseconds).
  }

  for (int i = NUMPIXELS; i >= 0; i--)
  {
    pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Moderately bright green color.
    pixels.show();                                  // This sends the updated pixel color to the hardware.
    delay(delayval);                                // Delay for a period of time (in milliseconds).
  }
}

void blue()
{
  for (int i = 0; i < NUMPIXELS; i++)
  {
    pixels.setPixelColor(i, pixels.Color(0, 0, 50)); // Moderately bright green color.
    pixels.show();                                   // This sends the updated pixel color to the hardware.
    delay(delayval);                                 // Delay for a period of time (in milliseconds).
  }

  for (int i = NUMPIXELS; i >= 0; i--)
  {
    pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Moderately bright green color.
    pixels.show();                                  // This sends the updated pixel color to the hardware.
    delay(delayval);                                // Delay for a period of time (in milliseconds).
  }
}

void M1()
{
  analogWrite(enA, motorSpeed);
  analogWrite(enB, motorSpeed);

  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
}

void M2()
{
  analogWrite(enA, motorSpeed);
  analogWrite(enB, motorSpeed);

  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
}

void Mstop()
{
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}

int get_key(unsigned int input)
{
  int k;
  for (k = 0; k < NUM_KEYS; k++)
  {
    if (input < adc_key_val[k])
    {
      return k;
    }
  }
  if (k >= NUM_KEYS)
    k = -1; // No valid key pressed
  return k;
}

Credits

ardutronic

ardutronic

39 projects • 39 followers
I'm 20 years old student of electronic technical college. I'm passionate about electronics as well as editing movies

Comments