marine_hm:
My son sent me a video of a beer being poured into a glass. So I decided I would make him one and send it for Christmas or maybe his birthday.
I don't know much about stepper motors. I'm sure that's all I need. But do I need a high torque?
Size? Just for a normal 16oz bottle of beer.
Thanks in advance. Nick
Two comments - torque is possible to calculate, and stepper motor holding torques are not
the thing to use.
Go to the datasheet and look at the torque/speed curves for a stepper - torque drops a lot with speed.
Then derate at least by a factor of 2. Resonance and other issues mean its wise to be very conservative...
Torque can be increased with gears, or a bigger motor, but bigger motors are a lot bulkier/heavier.
I'm working on a project kind of as a joke birthday present for my son based on a video he sent me.
I'm making him a beer dispenser the pours the beer from a bottle. Very Simply That!!!
Here's my Sketch so far: ANY TAKERS?
/*
Birthday Present to My son Nicholas
Creating Sketch to pour beer out of a bottle because it would be too easy to just pour it!
*/
#include <Servo.h>
Servo myservo1; // create servo object to pour the beer
Servo myservo2; // create servo object to tilt the glass
void setup() {
myservo1.attach(3); // attaches the servo on pin 3 to pour the beer
myservo2.attach(4); // attaches the servo on pin 4 to tilt the glass
}
void loop() {
myservo1.write(45); // Recover from standby mode or unit just turned on
delay(5000); // waits for the servo to get there
myservo1.write(0); // sets the servo position down to insert bottle, wait for button press
delay(5000); // need code for button press
myservo1.write(125); // Pour the beer *** Need to slow the speed to pour it slower ***
delay(10000); // waits for the beer to come out of the bottle
myservo1.write(45); // sets the servo position/standby mode (Place a bottle in rack for display)
// will work on tilting the beer glass after I get the initial movement down
} // I don't want this to loop. Can I just do without the VOID LOOP?
Here's my latest sketch: Now I need suggestions on either button press or button for reset? Not sure how to do it properly. I want to make sure that it will not move until a button press is made. Suggestions!!?
/*
Birthday Present to My son Nicholas
Creating Sketch to pour beer out of a bottle because it would be too easy to just pour it!
*/
#include <Servo.h>
Servo myservo1; // create servo object to pour the beer
Servo myservo2; // create servo object to tilt the glass
void setup() {
myservo1.attach(4); // attaches the servo on pin 4 to pour the beer
myservo2.attach(2); // attaches the servo on pin 2 to tilt the glass
myservo1.write(20); // Recover from standby mode or unit just turned on
myservo2.write(90); // Wait for glass to be inserted
delay(1000); // ?? need code for button press Can I program for a button press to reset the arduino???
// Button press?
myservo2.write(60); // Tilt glass at 60 deg. to recieve beer(-30)
delay(2500); // Waits for the servo to get there
myservo1.write(125); // Pour the beer *** Need to slow the speed to pour it slower ***
delay(25000); // Waits for the beer to come out of the bottle
myservo1.write(20); // Sets the servo position/standby mode
delay(1000); // Wait for bottle to tilt up
myservo2.write(90); // Stand glass straight up for serving
} // (Place a Glass & Bottle in rack for display)
void loop() {
}
Check this out!!! I realize this is childs play for you, but for me it was a big deal.
Can I program a button press to do a reset on the arduino? Never mind! I see a tutorial just for THAT!!!
/*
Birthday Present to My son Nicholas
Creating Sketch to pour beer out of a bottle because it would be too easy to just pour it!
Thanks to Paul McWhorters video on YouTube (LESSON 16: Controlling a Servo with Arduino
*/
#include <Servo.h>
int pos = 0; // variable to store the servo position
int servoDelay1 = 50;
int servoDelay2 = 200;
Servo myservo1; // create servo object to pour the beer
Servo myservo2; // create servo object to tilt the glass
void setup() {
myservo1.attach(4); // attaches the servo on pin 4 to pour the beer
myservo2.attach(2); // attaches the servo on pin 2 to tilt the glass
myservo2.write(60); // THESE TWO LINES SET THE SERVO POSITIONS
myservo1.write(25); // AS SOON AS THE ARDUINO IS POWERED UP
// TILT GLASS TO RECIEVE BEER
for (pos = 90; pos >= 60; pos -= 1) {
myservo2.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
// POUR BEER FROM BOTTLE
for (pos = 25; pos <= 125; pos += 1) { // Tilts beer bottle to 125 degrees
myservo1.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay2);
}
// TILT GLASS BACK UP
for (pos = 60; pos <= 90; pos += 1) {
myservo2.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
// RETURN BOTTLE TO ORIGINAL POSISTION
for (pos = 125; pos >= 25; pos -= 1) { // Tilts beer bottle to 125 degrees
myservo1.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
// ****************************************
} // END OF SETUP
void loop() {
}
marine_hm:
Can I program a button press to do a reset on the arduino?
There should be no need to cause the Arduino to reset unless a program has crashed.
You can easily include code in a program so that it goes back to the beginning of an action when a button is pressed.
I don't know what you meant by "Check this out". As I said earlier I am much to lazy to figure stuff out by reading program code without a guide from the author as to what it does and does not do.
I see you have the "animation" of the beer and the glass motors in the setup.
I'm thinking that's why you want a button, to reset the arduino and to run the program again.
While I it possible to hook up a button to two specific pins on the arduino and make it reset I think it makes more sense to move the moving of the servo to the loop function. That way you wont have to reset the arduino. Plus the servomotors will only start moving when you press a button, instead of when you power up the arduino.
You then hook up a button to a digital in pin ( with a pull up or pull down resistor) and make the loop function check for a state change on the button.
If you detect a state change you then want to play that animation you made.
You can even hook up some pot meters to maybe move the servo motors by hand or something? Just to make it even more unusefull
This is what I've got so far: with the following error code
Arduino: 1.6.5 (Windows 7), Board: "Arduino/Genuino Uno"
BeerRun:8: error: 'PULLUP' was not declared in this scope
BeerRun.ino: In function 'void loop()':
BeerRun:39: error: no match for 'operator==' (operand types are 'Button' and 'int')
'PULLUP' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Sketch:
/*
Birthday Present to My son Nicholas
Creating Sketch to pour beer out of a bottle because it would be too easy to just pour it!
Thanks to Paul McWhorters video on YouTube (LESSON 16: Controlling a Servo with Arduino
*/
#include <Button.h>
const byte ledPin = 13;// I'M ASSUMING THE THE LED COMES ON WHEN THE BUTTON IS PRESSED
Button button(12, PULLUP);// AGAIN, ASSUMING THIS IS A PULLUP UP RESISTER FOR DEBOUNCE
int button = A01;
/* ?? THIS MEANS THAT THE BUTTON IS ATTACHRD TO PIN 12, AND THE OTHER END OF THE BUTTON WOULD BE
* ATTACHED TO GROUND? WHEN, THE BUTTON IS PRESSSED LED(PIN13) LIGHTS UP AS AN INDICATOR THAT
* THE ARDUINO IS READING THE BUTTON PRESS?
*/
#include <Servo.h>
int pos = 0; // Variable to store the servo position
int servoDelay1 = 50; // Creates servo delay speed=50 in miliseconds
int servoDelay2 = 200; // Creates servo delay speed=200 in miliseconds
Servo BeerServo; // Creates servo object used to pour the beer
Servo GlassServo; // Creates servo object used to tilt the glass
void setup() {
pinMode(ledPin, OUTPUT); //debug to led 13
pinMode(button, INPUT);
BeerServo.attach(4); // attaches the servo on pin 4 to pour the beer
GlassServo.attach(2); // attaches the servo on pin 2 to tilt the glass
GlassServo.write(60); // THESE TWO LINES SET THE SERVO POSITIONS
BeerServo.write(25); // AS SOON AS THE ARDUINO IS POWERED UP
} // END OF SETUP
void loop() {
// ************ WAIT FOR BUTTON TO BE PRESSED **********
while (Button.button()){ // Wait for button to be pressed
if (button == HIGH) // If button pressed, RUN LOOP CYCLE
}
// TILT GLASS TO RECIEVE BEER
for (pos = 90; pos >= 60; pos -= 1) {
GlassServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
// POUR BEER FROM BOTTLE
for (pos = 25; pos <= 125; pos += 1) { // Tilts beer bottle to 125 degrees
BeerServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay2);
}
// TILT GLASS BACK UP
for (pos = 60; pos <= 90; pos += 1) {
GlassServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
// RETURN BOTTLE TO ORIGINAL POSISTION
for (pos = 125; pos >= 25; pos -= 1) { // Tilts beer bottle to 125 degrees
BeerServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
}
Oh SNAP!!! This just compiled. Now to test it on the breadboard. Where did that little button go??
Off to Radio Shack.
/*
Birthday Present to My son Nicholas
Creating Sketch to pour beer out of a bottle because it would be too easy to just pour it!
Thanks to Paul McWhorters video on YouTube (LESSON 16: Controlling a Servo with Arduino
*/
#include <Button.h>
const byte ledPin = 13;// I'M ASSUMING THE THE LED COMES ON WHEN THE BUTTON IS PRESSED
int button = A0;
/* ?? WHEN, THE BUTTON IS PRESSSED LED(PIN13) LIGHTS UP AS AN INDICATOR THAT
* THE ARDUINO IS READING THE BUTTON PRESS?
*/
#include <Servo.h>
int pos = 0; // Variable to store the servo position
int servoDelay1 = 50; // Creates servo delay speed=50 in miliseconds
int servoDelay2 = 200; // Creates servo delay speed=200 in miliseconds
Servo BeerServo; // Creates servo object used to pour the beer
Servo GlassServo; // Creates servo object used to tilt the glass
void setup() {
pinMode(ledPin, OUTPUT); //debug to led 13
pinMode(button, INPUT);
BeerServo.attach(4); // attaches the servo on pin 4 to pour the beer
GlassServo.attach(2); // attaches the servo on pin 2 to tilt the glass
GlassServo.write(60); // THESE TWO LINES SET THE SERVO POSITIONS
BeerServo.write(25); // AS SOON AS THE ARDUINO IS POWERED UP
} // END OF SETUP
void loop() {
// ************ WAIT FOR BUTTON TO BE PRESSED **********
analogRead(button);
if (button == HIGH); // If button pressed, RUN LOOP CYCLE
// TILT GLASS TO RECIEVE BEER
for (pos = 90; pos >= 60; pos -= 1) {
GlassServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
// POUR BEER FROM BOTTLE
for (pos = 25; pos <= 125; pos += 1) { // Tilts beer bottle to 125 degrees
BeerServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay2);
}
// TILT GLASS BACK UP
for (pos = 60; pos <= 90; pos += 1) {
GlassServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
// RETURN BOTTLE TO ORIGINAL POSISTION
for (pos = 125; pos >= 25; pos -= 1) { // Tilts beer bottle to 125 degrees
BeerServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
}// Back to top of loop
No... That didn't work either. The loop just runs whether PIN A0 is HIGH or LOW.
Suggestions please!
/*
Birthday Present to My son Nicholas
Creating Sketch to pour beer out of a bottle because it would be too easy to just pour it!
Thanks to Paul McWhorters video on YouTube (LESSON 16: Controlling a Servo with Arduino
littleBits Electronics - Introduction to Arduino Programming ii: Push My Button
*/
#include <Button.h>
const byte ledPin = 13;// I'M ASSUMING THE THE LED COMES ON WHEN THE BUTTON IS PRESSED
int button = A0;
/* ?? WHEN, THE BUTTON IS PRESSSED LED(PIN13) LIGHTS UP AS AN INDICATOR THAT
* THE ARDUINO IS READING THE BUTTON PRESS?
*/
#include <Servo.h>
int pos = 0; // Variable to store the servo position
int servoDelay1 = 50; // Creates servo delay speed=50 in miliseconds
int servoDelay2 = 200; // Creates servo delay speed=200 in miliseconds
Servo BeerServo; // Creates servo object used to pour the beer
Servo GlassServo; // Creates servo object used to tilt the glass
void setup() {
pinMode(ledPin, OUTPUT); //debug to led 13
pinMode(button, INPUT);
BeerServo.attach(4); // attaches the servo on pin 4 to pour the beer
GlassServo.attach(2); // attaches the servo on pin 2 to tilt the glass
GlassServo.write(60); // THESE TWO LINES SET THE SERVO POSITIONS
BeerServo.write(25); // AS SOON AS THE ARDUINO IS POWERED UP
} // END OF SETUP
void loop() {
// ************ WAIT FOR BUTTON TO BE PRESSED **********
analogRead(button);
if (button == HIGH); // If button pressed, RUN LOOP CYCLE
// TILT GLASS TO RECIEVE BEER
for (pos = 90; pos >= 60; pos -= 1) {
GlassServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
// POUR BEER FROM BOTTLE
for (pos = 25; pos <= 125; pos += 1) { // Tilts beer bottle to 125 degrees
BeerServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay2);
}
// TILT GLASS BACK UP
for (pos = 60; pos <= 90; pos += 1) {
GlassServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
// RETURN BOTTLE TO ORIGINAL POSISTION
for (pos = 125; pos >= 25; pos -= 1) { // Tilts beer bottle to 125 degrees
BeerServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
}// Back to top of loop
It's still running continuously without a button press to get it started.
/*
Birthday Present to My son Nicholas
Creating Sketch to pour beer out of a bottle because it would be too easy to just pour it!
Thanks to Paul McWhorters video on YouTube (LESSON 16: Controlling a Servo with Arduino
littleBits Electronics - Introduction to Arduino Programming ii: Push My Button
*/
#include <Button.h>
const byte ledPin = 13;// I'M ASSUMING THE THE LED COMES ON WHEN THE BUTTON IS PRESSED
int button = A0;
/* ?? WHEN, THE BUTTON IS PRESSSED LED(PIN13) LIGHTS UP AS AN INDICATOR THAT
* THE ARDUINO IS READING THE BUTTON PRESS?
*/
#include <Servo.h>
int pos = 0; // Variable to store the servo position
int servoDelay1 = 50; // Creates servo delay speed=50 in miliseconds
int servoDelay2 = 200; // Creates servo delay speed=200 in miliseconds
Servo BeerServo; // Creates servo object used to pour the beer
Servo GlassServo; // Creates servo object used to tilt the glass
void setup() {
pinMode(ledPin, OUTPUT); //debug to led 13
pinMode(button, INPUT);
BeerServo.attach(4); // attaches the servo on pin 4 to pour the beer
GlassServo.attach(2); // attaches the servo on pin 2 to tilt the glass
GlassServo.write(60); // THESE TWO LINES SET THE SERVO POSITIONS
BeerServo.write(25); // AS SOON AS THE ARDUINO IS POWERED UP
} // END OF SETUP
void loop() {
// ************ WAIT FOR BUTTON TO BE PRESSED **********
analogRead(button);
if (button == HIGH);{ // If button pressed, RUN LOOP CYCLE
// TILT GLASS TO RECIEVE BEER
for (pos = 90; pos >= 60; pos -= 1) {
GlassServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
// POUR BEER FROM BOTTLE
for (pos = 25; pos <= 125; pos += 1) { // Tilts beer bottle to 125 degrees
BeerServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay2);
}
// TILT GLASS BACK UP
for (pos = 60; pos <= 90; pos += 1) {
GlassServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
// RETURN BOTTLE TO ORIGINAL POSISTION
for (pos = 125; pos >= 25; pos -= 1) { // Tilts beer bottle to 125 degrees
BeerServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
}
}// Back to top of loop
Hanging my head in shame.... Sorry. Loading sketch and retrying.
Yeah, that must have worked. Servos are not moving. RadioShack did not have any push buttons. Until I get one... In theory, I should be able to plug a connector pin from A0 to positive rail on the breadboard for button to = high?
/*
Birthday Present to My son Nicholas
Creating Sketch to pour beer out of a bottle because it would be too easy to just pour it!
Thanks to Paul McWhorters video on YouTube (LESSON 16: Controlling a Servo with Arduino
littleBits Electronics - Introduction to Arduino Programming ii: Push My Button
*/
#include <Button.h>
const byte ledPin = 13;// I'M ASSUMING THE THE LED COMES ON WHEN THE BUTTON IS PRESSED
int BUTTON = 10;
/* ?? WHEN, THE BUTTON IS PRESSSED LED(PIN13) LIGHTS UP AS AN INDICATOR THAT
* THE ARDUINO IS READING THE BUTTON PRESS?
*/
#include <Servo.h>
int pos = 0; // Variable to store the servo position
int servoDelay1 = 50; // Creates servo delay speed=50 in miliseconds
int servoDelay2 = 200; // Creates servo delay speed=200 in miliseconds
Servo BeerServo; // Creates servo object used to pour the beer
Servo GlassServo; // Creates servo object used to tilt the glass
void setup() {
pinMode(ledPin, OUTPUT); //debug to led 13
pinMode(BUTTON, INPUT);
BeerServo.attach(4); // attaches the servo on pin 4 to pour the beer
GlassServo.attach(2); // attaches the servo on pin 2 to tilt the glass
GlassServo.write(60); // THESE TWO LINES SET THE SERVO POSITIONS
BeerServo.write(25); // AS SOON AS THE ARDUINO IS POWERED UP
} // END OF SETUP
void loop() {
// ************ WAIT FOR BUTTON TO BE PRESSED **********
if (digitalRead(BUTTON) == HIGH){ // If button pressed, RUN LOOP CYCLE
// TILT GLASS TO RECIEVE BEER
for (pos = 90; pos >= 60; pos -= 1) {
GlassServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
// POUR BEER FROM BOTTLE
for (pos = 25; pos <= 125; pos += 1) { // Tilts beer bottle to 125 degrees
BeerServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay2);
}
// TILT GLASS BACK UP
for (pos = 60; pos <= 90; pos += 1) {
GlassServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
// RETURN BOTTLE TO ORIGINAL POSISTION
for (pos = 125; pos >= 25; pos -= 1) { // Tilts beer bottle to 125 degrees
BeerServo.write(pos); // Tilt glass at 60 deg. to recieve beer(-30)
delay(servoDelay1);
}
}
}// Back to top of loop
This kind of works.. When Pin 10 is connected to ground the program is waiting for button press. When I disconnect pin 10 from ground the servos do their thing. So now I have to learn how to properly wire the button.