My Servo needs to turn by the push of a button from 0-180 degrees.
wait 1 sec.
and turn back (180-0).
another push wil repeat the actions.
i've tried to combine the examples on the arduino software but it won't work out.
can someone code send me a working coding?
We don't actually have working code for projects like that. Do you have the code you tried? If so, please post it(to post: type [code], then paste your code, the type [/code] and you will get help making it work.
Also give a bit of information, like what level of school are you in, and does your teacher mind if you get help from the internet? Personally, I think all such help should be encouraged, because using technology is a colaborative endevor.
You can try to do a code with a variable (x, for instance). First set the variable to 1. Then, do an if statement like:
if (x == 1){
x = 0
servo.write(180)
}
if (x ==0){
x=1
servo.write(-180)
With this code when x is 1, the servo moves forward and if x is 0 the servo moves backward (I think that if you put .write(-180), the servo moves backward)
Im an industrial design student.
Currently 2nd year.
I have a Arduino from my previous study wich a didn't finish 2 years ago
In this project we need to make a dispenser system.
I don't get class in programming.
The purpose of this project is understanding how the flow a systeem works, not how to code or how you make the system work.
I found a coding online for my servo. But it makers it turn 0-180 and back continiously. So i have to add an button in the setup and loop.
Here's the code for the servo i'm trying to work with:
/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#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
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (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
}
}
The code you found has good comments everywhere. Reading the comments you should know that the second half rotates the arm back. If you insert a big delay between first and second parts, you get the effect you need. Button is a separate question.
If you don't need the servo to run slowly, just tell it where to go:
void loop()
{
if (digitalRead(ButtonPin) == LOW)
{
// The button was pressed
myservo.write(180); // tell servo to go to position 180
delay(1000); // wait one second
myservo.write(0); // tell servo to go to position 0
}
}