Dear,
I'm new to arduino and i'm currently making a robot which can drive around all by itself.
So i bought 4 of these engines:
and they are all controlled by the arduino. Now my problem is that the current comes from the digital output pins, which can't deliver enough current or voltage to make the engines run. (At least that's why I think it doesn't work.)
I use an arduino UNO
When I add an LED before the engine, it flashes a bit when I get my hand out of the sight of the proximity sensor.
For those who want to see the code:
// declaring the pins
int left_front = 13;
int right_front = 12;
int left_back = 11;
int right_back = 10;
int sensor_left = 6;
int sensor_middle = 5;
int sensor_right = 3;
int last_dir = 0;
void setup ()
{
Serial.begin(9600);
// setting up the pinmode
pinMode(left_front, OUTPUT);
pinMode(right_front, OUTPUT);
pinMode(left_back, OUTPUT);
pinMode(right_back, OUTPUT);
pinMode(sensor_left, INPUT);
pinMode(sensor_middle, INPUT);
pinMode(sensor_right, INPUT);
}
void loop ()
{
int obs = check_obstacles();
if(obs == 0 && last_dir != 1)
{
last_dir = 1;
go_to_right();
}
else if(obs == 1 && last_dir != 2)
{
last_dir = 2;
go_to_left();
}
else if(last_dir != 3)
{
last_dir = 3;
go_forward();
}
delay(20);
}
// check for obstacles
int check_obstacles()
{
// reading the pins
int left = digitalRead(sensor_left);
int middle = digitalRead(sensor_middle);
int right = digitalRead(sensor_right);
// posting the values in the serial monitors
Serial.print(" 1: ");
Serial.print(left);
Serial.print(" 2: ");
Serial.print(middle);
Serial.print(" 3: ");
Serial.println(right);
// check if left
if(left == LOW )
{
return 0;
}else if(right == LOW || middle == LOW)
{
return 1;
}else
{
return 2;
}
}
//directions to go
int go_to_left()
{ Serial.println("LEFT");
digitalWrite(left_front, LOW);
digitalWrite(left_back, LOW);
}
int go_to_right()
{Serial.println("RIGHT");
digitalWrite(right_front, LOW);
digitalWrite(right_back, LOW);
}
int go_forward()
{Serial.println("FORWARD");
digitalWrite(right_front, HIGH);
digitalWrite(right_back, HIGH);
digitalWrite(left_front, HIGH);
digitalWrite(left_back, HIGH);
}
So how can I solve this?
Thanks in advance,
Willem