So I made my first attempt at a robot using my Arduino...
It can be seen here, so that I don't have to explain how everything works again: https://www.robotshop.com/letsmakerobots/node/31357
Now my problems is the code. What I have so far looks like so:
#include <IRremote.h>
#include <Servo.h>
Servo run; // servo for running hind wheels, continuous rotation
Servo steer; // Servo for steering
int pos = 0;
int RECV_PIN = 11; // IR pin
IRrecv irrecv(RECV_PIN); // set up IR to recieve
decode_results results;
void setup()
{
run.attach(3);
steer.attach(9);
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
run.write(81); // Stop/ break
steer.write(90); // center steering servo
if (irrecv.decode(&results)) {
if (results.value == 0xFFA05F){ // Stop/ break
run.write(81);
}
else if (results.value == 0xFF9867) { // Go forward
run.write(20);
delay(1500);
run.write(81);
}
else if (results.value == 0xFF906F){ //Go backwards
run.write(160);
delay(1500);
run.write(81);
}
else if (results.value == 0xFF20DF){ // turn left
steer.write(62);
delay(500);
}
else if (results.value == 0xFF609F);{ // turn right
steer.write(112);
delay(500);
}
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}
The problem is that no matter what command is given the bot automatically turns left after executing the command given... Why is that? Please help, Thanks!
Hayabusabot