Hello! I am very new to Arduino and am hitting lots of road blocks.
I want to be able to push a button and have the servo move 90. I then want to push it a second time, and have it move another 90 degrees...and so on and so fourth, continuously.
I've been reading a lot of these forum and all I can seem to get is having it go 180 degrees and then back to zero, or it does one 90 turn and then stops.
If anyone has any insight, I would be very appreciative! Thanks!
Normal servos don't rotate 360 degrees. Do you have a special one that does? If you have a continuous rotation servo, check the specs to see how to control it.
Are you able to control it under software control (without the pushbutton)?
I don't know much about continuous rotation servos... With a normal servo, you can't send a "90 degrees more" message. If you want to move from 90 to 180 degrees, you send it a 180 degree command. If you want to "go back 20 degrees" from there, send a 160 degree message.
So, I did some more research and found that servos only turn 180degrees...like I said, I am VERY new to Arduino.
Therefore, I now just want it to go in 5 30 degree increments until it reaches 150 degrees.
I've been playing around with this code, and I can now get it to turn 30 degrees once when pushing the button. But after that, it stops. I've labeled the positions at the top. Again, I would love your wonderful help.
// test sketch a.2
#include <Servo.h>
Servo servo1; // define servo aliases
#define leftPin 2 // define buttons attached to pins
int pos1 = 30; // set angle when inialitized
int pos2 = 60;
int pos3 = 90;
int pos4 = 120;
int pos5 = 150;
int delayPeriod = 80; // increasing this slows down the servo slew movement
// 1000 too much 300 jumpy 100 smooth slew 80 fast 50
// too fast 70 testing
// Project addition idea:
// add variable to control slew rate via potentiometer
// connected to analog input pin
void setup()
{
//test
servo1.write(pos1); // Put servo1 at home position of 0 degrees
servo1.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(leftPin, INPUT);
// digitalWrite(leftPin, HIGH); // turn on pullup resistor
//test
if(digitalRead(leftPin) == LOW); // turn on pulldown resistor
}
void loop()
{
if(digitalRead(leftPin) == HIGH) // left button instructions
{
// in steps of 1 degree
if( pos1 > 0)
--pos1;
servo1.write(pos1); // tell servo to go to position in variable 'pos1'
delay(delayPeriod);
if( pos2 > 0)
--pos2;
servo1.write(pos1); // tell servo to go to position in variable 'pos2'
delay(delayPeriod);
}
}