The Problem:
So following The Arduino Starter Kit, Project 05 - Mood Cue. I have the circuit connected up and used the example code from the IDE, however the motor just trambles in place very weakly oscillating maybe a degree or two.
Details:
The TX light is on, RX light is off, and LED light looks dimly light, which is odd because I don't think it's connected up. An additional point is pressing on either terminus of the A0 - Potentiometer wire increases how vigourous the trembling is, removing the pressure returns it back to the weak tremble. This makes me think the wire is loose, but it's in the socket pretty solidly. The servo tends to do a more definite turn the first time it is connected or disconnected, before returning to trembling.
// include the Servo library
#include <Servo.h>
Servo myServo; // create a servo object
int const potPin = A0; // analog pin used to connect the potentiometer
int potVal; // variable to read the value from the analog pin
int angle; // variable to hold the angle for the servo motor
void setup() {
myServo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600); // open a serial connection to your computer
}
void loop() {
potVal = analogRead(potPin); // read the value of the potentiometer
// print out the value to the Serial Monitor
Serial.print("potVal: ");
Serial.print(potVal);
// scale the numbers from the pot
angle = map(potVal, 0, 1023, 0, 179);
// print out the angle for the servo motor
Serial.print(", angle: ");
Serial.println(angle);
// set the servo position
myServo.write(angle);
// wait for the servo to get there
delay(15);
}
Servos pull a lot of current - more than the Arduino can provide.
Breadboards have tiny traces and can't withstand high currents.
So you have a double whammy: a device trying to pull too much power from a source that can't provide it, through a connection that can't handle it.
That twitching you see is another clue that the servo is underpowered.
It is true that you will see tutorials that suggest that you can run a servo connected to an Arduino, and you can, maybe, if the servo has no load. For best results though, the servo needs its own power, the Arduino just controls it.
I see. Thanks for letting me know. So nominally is the circuit and code correct?
How would I go about modifying the circuit to accommodate a power source? A transistor with the potentiometer on the drain, the battery on the source, and the yellow wire on row 17 as the gate?
It's weird Arduino's own starter kit shouldn't meet the specs of their own hardware though - would I not expect everyone to be suffering this same problem with this project (t's from the tutorials)? (It is this tutorial)
No - that battery isn't powerful enough and it's the wrong voltage. Four AAs is a more usual configuration if you want to run a hobby servo of a battery.
Ah, there I might be stuck - the starter kit only came with a battery clip for a 9V battery. Seems odd they would miss such a vital component of the starter kit of their own product. Is there no other way to run the servo properly?
Okay, that works... the servo is slowly sweeping out a 180 degree arc, then turns back the other direction and repeats. So is the problem here the breadboard itself?
Eventually I'd like to turn this project into the ability to move a plastic arm up and down from a remote input (using LabView if it matters), and was going to use this tutorial as the basis for that. Do you think Arduino is not suitable for this task?
Be aware that many servos can't manage the whole 180 degrees. It occurs to me that the original problem may have been that the pot was asking for a position that the servo couldn't manage.
Nonetheless, if you want to make real project, I still suggest that you get better power for it.
Okay, with just the servo, (i.e. no capacitors) it's working just as plugged into the UNO alone. So I'm guessing the problem is either the capacitors or the potentiometer the analog input? my money is the potentiometer. That said, the servo does appear to be able to do the full 180 arc, and that potentiometer is ask 179.
At the moment it does just rotate back and forth, how would I control it to stop at one end or the other - i.e. take an input to move the servo to the far end of it's arc, and then input again to move it back to the other end of the arc?
Do the capacitors / analog input that are now out of the circuit make any real difference?
Agreed, it sounds like power would be a good idea, but baby steps, I'll get this thing working first
The potentiometer isn't connected well, the middle pin is on the other side of the breadboard and the yellow wire doesn't connect.
In the book it's connected to one side, but it's not possible.