Hi,
I'd like to create a servo controlled laserpointer, which can be controlled by a PC application.
I'm using a power LED, two servos with an angle of 180 degrees and a laser (in the circuit it is the green LED) and the Arduino Dueminalove board.
You can find the circuit here:
http://l68.img-up.net/?up=AnalogInpu83ye.png.
I coded this to realize it:
#include <Servo.h>
// Commands
#define SLEEP 0
#define PING 1
#define RESET 2
#define LASERON 11
#define LASEROFF 12
#define ANGLELASER 21
Servo servoX;
Servo servoY;
int baudRate = 9600; // Baudrate of the serial connection
int command = SLEEP; // Current command
int resetted = LOW; // HIGH if the Reset() method was executed
int ledPin = 13;
int laserPin = 12;
int servoXPin = 9;
int servoYPin = 10;
int laser = LOW;
void setup() {
Reset();
pinMode(ledPin, OUTPUT);
pinMode(laserPin, OUTPUT);;
digitalWrite(ledPin, HIGH);
}
void loop() {
digitalWrite(ledPin, HIGH);
if(Serial.available() > 0) {
ProcessSerialCommand(Serial.read());
}
digitalWrite(laserPin, laser);
}
void ProcessSerialCommand( byte in ) {
if(in == LASERON) {
LaserOn();
}
if(in == LASEROFF) {
LaserOff();
}
if(in == ANGLELASER) {
AngleLaser();
}
if(in == PING) {
Ping();
}
if(in == RESET) {
Reset();
}
if(in == SLEEP) {
command = SLEEP;
}
Serial.flush();
}
void Ping() {
Serial.println(1, DEC);
}
void Reset() {
if(resetted == HIGH) {
Serial.end();
servoX.detach();
servoY.detach();
}
Serial.begin(baudRate);
servoX.attach(servoXPin);
servoY.attach(servoYPin);
resetted = HIGH;
}
void LaserOn() {
laser = HIGH;
}
void LaserOff() {
laser = LOW;
}
void AngleLaser() {
while(Serial.available() < 2)
{}
servoX.write(Serial.read());
servoY.write(Serial.read());
delay(1000);
}
The problem is, that the servo sucks to much power (I measured 80mA - 370mA) when I plug the USB cable into the Arduino.
The Arduino always restarts. It works with one servo, but then the laser and the power led flickers.
I don't know how to get rid of this problem.
Do I need additional power source (I have some 1.5V batteries) or do I have to limit the current of the servos.
I hope you can give me an answer.