0t-JTVYdE7s

Build yourself a low-cost easy to assemble robotic bartender using an Arduino Uno. This easy Arduino based project can be 3D printed and is a cool Arduino project for beginners.

Part two in our series covers the majority of the electrical assembly.

List of items used in this project and where to find them:

Arduino Uno:http://amzn.to/2xbXNK4
Motor shield: http://amzn.to/2gQUkL0

Download 3D printable parts:
https://www.thingiverse.com/thing:2478890

SUBSCRIBE:
https://www.youtube.com/channel/UC3jc4X-kEq-dEDYhQ8QoYnQ?sub_confirmation=1

INSTAGRAM: https://www.instagram.com/diy_machines/?hl=en
FACEBOOK:https://www.facebook.com/diymachines/?ref=aymt_homepage_panel
PATREON: https://www.patreon.com/diymachines

DIY machines bar circuit diagram

Test_1


//The below is for the contact switch

const int  buttonPin = 2;    // the pin that the pushbutton is attached to

int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button


//----------------------

//The below is for the stepper motors

#include 


AF_Stepper motor1(48, 1);
AF_Stepper motor2(48, 2);


//---------------------

// Below is for the RGB LED

int greenPin = 10;
int bluePin = A1;
int redPin = 9;



//---------------------

//The below are for running the machine:
int raftFound = false;



void setup() {

// for the contact switch 

  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(LED_BUILTIN, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);
  
//--------------------------------

//  For the stepper motors

  motor1.setSpeed(600);
   motor2.setSpeed(600);

//--------------------------------

// For LED

  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

//-------------------------------

}


void loop() {
  delay(1000);
  //Lets find the location of the float:-
  
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  //move the stepper until the contact switch is triggered
  while(buttonState == LOW && raftFound == false){
   setColor(255, 0, 0);  // red
   motor1.step(10, FORWARD, SINGLE); 
   buttonState = digitalRead(buttonPin);
  }

 raftFound = true;
 setColor(0, 255, 0);  // orange

    // Delay a little bit to calm the arduino down.
    delay(300);

//Move to first pump
  motor1.step(50, BACKWARD, SINGLE);
    motor1.release();
  delay(500);
      motor2.step(2000, BACKWARD, DOUBLE);
      delay(2000);
     motor2.step(2000, FORWARD, DOUBLE);
     motor2.release();
      delay(500);
  motor1.step(700, BACKWARD, SINGLE);
  motor1.release();
    delay(500);
      motor2.step(2200, BACKWARD, DOUBLE);
      delay(5000);
      motor2.step(2200, FORWARD, DOUBLE);
      motor2.release();
      delay(500);
   setColor(0, 0, 255);  // green
      delay(999000);


}


void setColor(int red, int green, int blue)
{
  #ifdef COMMON_ANODE
    red = 255 - red;
    green = 255 - green;
    blue = 255 - blue;
  #endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);  
}

RGB_LED_Test


int bluePin = 10;
int greenPin = A1;
int redPin = 9;
 
void setup()
{
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);  
}
 
void loop()
{
  setColor(255, 0, 0);  // red
  delay(1000);
  setColor(0, 255, 0);  // green
  delay(1000);
  setColor(0, 0, 255);  // blue
  delay(1000);
  setColor(255, 255, 0);  // yellow
  delay(1000);  
  setColor(80, 0, 80);  // purple
  delay(1000);
  setColor(0, 255, 255);  // aqua
  delay(1000);
}
 
void setColor(int red, int green, int blue)
{
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);  
}

Contact_Switch_Test


/*
  State change detection (edge detection)

 Often, you don't need to know the state of a digital input all the time,
 but you just need to know when the input changes from one state to another.
 For example, you want to know when a button goes from OFF to ON.  This is called
 state change detection, or edge detection.

 This example shows how to detect when a button or button changes from off to on
 and on to off.

 created  27 Sep 2005
 modified 30 Aug 2011
  by Tom Igoe
 tweaked 18 Sep 2017
   by DIY Machines


This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/ButtonStateChange

 */

// this constant won't change:
const int  buttonPin = 2;    // the pin that the pushbutton is attached to
const int ledPin = 13;       // the pin that the LED is attached to

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(LED_BUILTIN, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);
}


void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButtonState = buttonState;


  // turns on the LED every four button pushes by
  // checking the modulo of the button push counter.
  // the modulo function gives you the remainder of
  // the division of two numbers:
  if (buttonPushCounter % 4 == 0) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }

}