Greetings,
So this is my first project and read/watched a few guides. So now Im pulling the trigger on my project.
Using my Arduino Uno, my goal is to push and hold a button that will move a servo to position. When releasing the button, the servo moves back to original position.
After reading guides, I figured that it would be easier to just use pre-made wiring diagram and sketch of something similar, and just altering it a bit. But doing this, caused some problems and was wondering if someone could help me out to fix or make this work.
The servo im working with is a Corona CS-239HV slim servo
4.6kg / .13sec / 22g
Operating Voltage: 6.0V/7.4V
Operating Current: 300mA / 400mA
Operating Speed: 0.14sec.60º/ 0.13sec.60º
Stall Torque: 4.0kg.cm / 4.6kg.cm
Dead Band: ?5uSec
Operating Travel: 40º/one side pulse traveling 400us
Potentiometer: 3 slider/Direct Drive
Ball bearing: MR85x2
Gear: Metal
Operating Temperature Range: -20c+60c
With my tact button (50mA, 12VDC)
This is how I hooked it up to my Arduino Uno
The sketch I used is this:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo myservo1;
const int buttonPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 5; // the pin that the LED is attached to
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
int ledState = 0; // remember current led state
int pos = 0; // variable to store the servo positions
int pos1 = 180;
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo1.attach(10); // attaches the servo 1 on pin 10 to the servo object
pinMode(buttonPin, INPUT); // initialize the button pin as a input
pinMode(ledPin, OUTPUT); // initialize the button pin as a output
}
void loop()
{
buttonState = digitalRead(buttonPin); // read the pushbutton input pin
if (buttonState != lastButtonState) // compare buttonState to previous state
{
if (buttonState == 1)
{
if(ledState == 1)
{
delay(30); ledState = 0;
for(pos = 0; pos <= 180; pos += 10) // goes from 0 degrees to 180 degrees
{ // in steps of 10 degrees
myservo.write(pos); // tell servo to go to position ‘pos’
}
for(pos1 = 180; pos1 >= 0; pos1 -= 10) // goes from 180 degrees to 0 degrees
{ // in steps of 10 degrees
myservo1.write(pos1); // tell servo to go to position ‘pos1’
}
delay(15); // waits 15ms for the servo to reach the position
}
else
{
delay(30); ledState = 1;
for(pos = 180; pos >= 0; pos -= 10) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position ‘pos’
}
for(pos1 = 0; pos1 <= 180; pos1 += 10) // goes from 0 degrees to 180 degrees
{
myservo1.write(pos1); // tell servo to go to position ‘pos1’
}
delay(1000);
}
}
lastButtonState = buttonState; // remember the current state of the button
}
// turns LED on if the ledState =1 or off if ledState = 0
digitalWrite(ledPin, ledState);
myservo.write(pos); // goes from 0 degrees to 180 degrees
myservo1.write(pos1); // goes from 180 degrees to 0 degrees
delay(20);
}
The problem I had with this was:
- When connected to power, the servo moved but stopped. Nothing happened when button is pressed
- When remove button and plugged back in, servo moves but nothing happens when button is pressed
- the 10ohm resistor is extremely hot. I quickly removed from power and USB.
Can someone help me?