Hi. I'm quite new to Arduino. I'm working on a project involving potentiometers and servos. I made sure the code was correct, and that everythiing was connected correctly. When I plug the USB cable into the computer and upload the sketch to the Arduino, there seems to be no errors and the sketch was uploaded successfully and the green "On" and the orange LED light is ON but the orange LED isn't blinking so servos won't do anything.
Down below is an image of my project and the code if that helps.
#include <Servo.h>
Servo servo1; // create servo object to control a servo
Servo servo2;
int potpin = A4; // analog pin used to connect the potentiometer
int potpin2 = A3;
int val; // variable to read the value from the analog pin
int val2;
void setup()
{
servo1.attach(9); // attaches the servo on pin 9 to the servo object
servo2.attach(8);
}
void loop()
{
val = analogRead(potpin); // reads the value of the // potentiometer (value between // 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with // the servo (value between 0 and // 180)
servo1.write(val); // sets the servo position according // to the scaled value
delay(15); // waits for the servo to get there
val2 = analogRead(potpin2);
val2 = map(val2, 0, 1023, 0, 179);
servo2.write(val2);
delay(15);
}
My project (picture link):
Please edit your post and add code tags
type
** **[code]** **
before the code
type
** **[/code]** **
after the code
After that there will no longer be a smiley 8)
The conclusion that your servos don't work because the led does not blink is incorrect. The led on pin 13 only blinks if you tell it to blink. Your code does not do that (and that is not a problem).
It's really difficult (read as: impossible) to figure out the circuitry against your carpet. Can you provide a diagram rather? (Just draw it freehand and take a pic...)
sterretje:
Please edit your post and add code tags
type
** **[code]** **
before the code
type
** **[/code]** **
after the code
After that there will no longer be a smiley 8)
The conclusion that your servos don't work because the led does not blink is incorrect. The led on pin 13 only blinks if you tell it to blink. Your code does not do that (and that is not a problem).
well i made sure everything was connected correctly and usually a blinking orange LED light indicates that the sketch has 100% successfully uploaded to the board.
I can't make out from your sketch where the servos get their power from, but looks like it might be from the Arduino 5V? If so, there's probably not enough current available.
manor_royal:
I can't make out from your sketch where the servos get their power from, but looks like it might be from the Arduino 5V? If so, there's probably not enough current available.
ok so what should I do add extra voltage to the servos?
First confirm what I asked?- are they connected to the Arduino 5V?
You should get a 6V pack like 4xAAs say, and connect the power wires of the servos to that. Then connect the -ve of that battery and servo to the Arduino ground.