hi,
i just got a ardunio uno -
setup a simple circuit with a photoresistor that controls a servo
code belo
#include <Servo.h>
Servo myservo;
int potpin = 0;
int val;
void setup()
{
myservo.attach(9);
Serial.begin(9600);
}
void loop()
{
val = analogRead(potpin);
val = map(val, 0, 900, 0, 179);
constrain(val, 0, 179);
Serial.println(val);
delay(25);
myservo.write(val);
delay(15);
}
i upload that code and open the serial monitor which starts printing out values.
the problem is that the serial sends data out but when there is a sudden large change in the value its sending tx freezes (the tx led either stays lit constant or goes out) and no data is being sent anymore - i have to unplug the usb and start again to get it sending again
i also tried reading with dotnet on com11 so make sure it wasnt a software issue and i got the same result
anyone know why this might be happening???
It might be a problem with the servo code. Try removing that call and see if it still happens.
It could be a hardware issue where a sudden demand for current causes a glitch and screws up the arduino. How are you powering the servo? They normally need an external power supply, how much peak current does yours take?
I agree with mike.
Most servos I have used are right on the edge of the power Arduinos are capable of supplying on board.
Try hooking it via an H-bridge, mosfet, or transistor to an external power supply like a >5v battery or a wall wart.
Most servos I have used are right on the edge of the power Arduinos are capable of supplying on board.
Try hooking it via an H-bridge, mosfet, or transistor to an external power supply like a >5v battery or a wall wart.
The "H-bridge, mosfet, or transistor" are usually for motors and aren't usually used with servos.