Hi guys,
I am really bad at programming i just put some code from the internet together i hoped that someone could help me with my project for school.
What i am trying to accomplish is that the beer pushes down a button, the button activates the servo to turn 180 degrees so the opener is right on top of the beer, when the servo has turned the solenoid pushes the opener up with enough power to open it up. After the solenoid pushed it up the servo turns back 180 degrees and then the cycle is done.
I really hope someone is able to help met with this.
I added the program i made (it probably is just a lot of bullshit) and a sketchup of our 'robot'.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
int solenoidPin = 4; //This is the output pin on the Arduino we are using
int pushButton = 2;
int degree
void setup() {
// put your setup code here, to run once:
pinMode(solenoidPin, OUTPUT); //Sets the pin as an output
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin (9600);
pinMode (pushButton, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int buttonState = digitalRead (pushButton);
Serial.println(buttonState);
delay(1);
if (buttonState , HIGH){
for (pos = 0; pos <= 180; pos += 1){//gaat van 0 naar 180 graden
myservo.write (pos);
delay (15);
if (pos >179){
analogWrite
}}
if (pos = 180){
digitalWrite(solenoidPin, HIGH); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin, LOW); //Switch Solenoid OFF
if (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position }
}}}
Try to avoid doing }}}
put them to separate lines and do a Auto-Format in the IDE, press CTRL-T.
Your code formated;
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
int solenoidPin = 4; //This is the output pin on the Arduino we are using
int pushButton = 2;
int degree
void setup() {
// put your setup code here, to run once:
pinMode(solenoidPin, OUTPUT); //Sets the pin as an output
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin (9600);
pinMode (pushButton, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int buttonState = digitalRead (pushButton);
Serial.println(buttonState);
delay(1);
if (buttonState , HIGH) {
for (pos = 0; pos <= 180; pos += 1) { //gaat van 0 naar 180 graden
myservo.write (pos);
delay (15);
if (pos > 179) {
analogWrite
}
}
if (pos = 180) {
digitalWrite(solenoidPin, HIGH); //Switch Solenoid ON
delay(1000); //Wait 1 Second
digitalWrite(solenoidPin, LOW); //Switch Solenoid OFF
if (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position }
}
}
}
it is supposed to stop the servo from turning back 180 degrees, when i uploaded my code it. turned 180 and back i was trying to stop it from doing that insteantly but i forgot to finish the code i guess.
While a worthy goal, i’d be suspicious of using a solenoid to ‘pop the bottle top’.
A solenoid imparts a very short impulse of mechanical energy, which is just as likely to take the neck off the bottle??
If I was building this, an arrangement of servos is fine to position the opener and bottle - but, i’d use a stronger geared-down servo/motor to apply the progressive force needed to lift the cap.
While a worthy goal, i’d be suspicious of using a solenoid to ‘pop the bottle top’.
A solenoid imparts a very short impulse of mechanical energy, which is just as likely to take the neck off the bottle??
If I was building this, an arrangement of servos is fine to position the opener and bottle - but, i’d use a stronger geared-down servo/motor to apply the progressive force needed to lift the cap.
I think the bottles are twist top, so the solenoid only has to hold the "spanner" around the top as the bottle is turned.
Tom..
I think OP is from The Netherlands, and other than the rare imported US beer bottles I have yet to see twist tops there (I recall having a really hard time opening such bottles - until I realised you have to twist them!)