I am making a remote controlled robot using the arduino. The controller will be an iPod touch. The interface software sends commands to the arduino via the serial monitor. I wrote code to command the two drive motors, but when I send the one the motors a command to start, the motor I commanded to start comes on full speed and the second motor comes on half speed. In addition, I am only able to stop one motor at a time. I want to stop both motors. There is a sckamadic attached and here is my code:
int message = 1;
int M1P = 11;
int M2P = 6;
int M1 = 0;
int M2 = 0;
void setup()
{
pinMode(M1P, OUTPUT);
pinMode(M2P, OUTPUT);
Serial.begin(9600);
}
void loop()
{
{
if (Serial.available() > 0)
message = Serial.read();
if (message == 'R');
digitalWrite(M1P, HIGH);
}{
if (message == 'r')
digitalWrite(M1P, LOW);
}
{
if (Serial.available() > 0)
message = Serial.read();
if (message == 'L');
digitalWrite(M2P, HIGH);
}{
if (message == 'l')
digitalWrite(M2P, LOW);
}
}
I guess that when u say your motors are connected to the pins, you mean that a high-current switch is connected to the output pins... either a relay, or a transister or perhaps a motor controller circuit.
Because a motor needs a LOT more power than the arduino can output.
==
Assuming you have a switch that can be turned on by the small current that the arduino outputs..
Your code always only read one character per call of loop() - as the Arduino is so fast compared to the the serial line.
But you are tring to read twice... and checking the first character against 'R' or 'r' and the second character against 'L' or 'l'.
You should really only read one character at a time - and check it against R, r, L and 'l'.
haydenyoung:
I am making a remote controlled robot using the arduino. The controller will be an iPod touch. The interface software sends commands to the arduino via the serial monitor. I wrote code to command the two drive motors, but when I send the one the motors a command to start, the motor I commanded to start comes on full speed and the second motor comes on half speed. In addition, I am only able to stop one motor at a time. I want to stop both motors. There is a sckamadic attached and here is my code:
int message = 1;
int M1P = 11;
int M2P = 6;
int M1 = 0;
int M2 = 0;
your code could not understand which one to work on also i wonder how were you able to compile this, this should be an error.
Curly braces are used to define blocks of code. Typically they are used after an if statement, a while statement, or a for statement. Of course, they are required after a function declaration. They can be used anywhere else, though, and it is not an error. Useless, yes. Error, no.