Hello everyone,
I am brandnew to Arduino (and programming, and electronics in general) and am hoping to get some help. Any advice is appreciated.
I will do my best to list and explain all necessary background info, hope it makes sense.
I am trying to build a simple tank robot using an Arduino Uno. The robot will be remote controlled and have 2 dc motors. I'm using the following components:
- Arduino Uno
- Adafruit Motor Shield (I think I accidentally bought a cheap knock off - ooops)
http://smile.amazon.com/gp/product/B00813HBBO/ref=oh_aui_detailpage_o03_s00?ie=UTF8&psc=1 - IR receiver
- TV remote
- two DC motors
I am including the IRremote.h library and the adafruit AFmotor.h library.
I started out by writing a code to get the decoded IR signals from the TV remote. Worked out just fine
Then I wrote a test code to see if the motors are working. Both are working (I took the sample code off of the adafruit website and adjusted it).
Next, I am trying to combine both so that the input from the TV remote will start and stop the motors. This is where my problems start. Here is my code
#include <AFMotor.h>
#include <IRremote.h>
AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #1, 64KHz pwm
AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
const int receiver = 2;
IRrecv irrecv(receiver);
decode_results results;
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
motor1.setSpeed(200); // set the speed of motorsto 200/255
motor2.setSpeed(200);
motor1.run(RELEASE); // both motors stop
motor2.run(RELEASE);
irrecv.enableIRIn(); // Start IR receiver
}
void loop() {
if(irrecv.decode(&results)) // have we received an IR signal?
irrecv.resume(); // Receive the next value
{
{
if(results.value == 650130)
{
Serial.print("tick");
motor1.run(FORWARD); // turn it on going forward
motor2.run(FORWARD);
delay(100);
}
else if(results.value == 387986)
{
Serial.print("tock");
motor1.run(BACKWARD); // backward
motor2.run(BACKWARD);
delay(100);
}
else if(results.value == 854930)
{
Serial.print("tack");
motor1.run(RELEASE); // stopped
motor2.run(RELEASE);
delay(100);
}}}}
The code compiles and uploads fine. Also, the serial monitor will show tick, tock, tack everytime I press the remote buttons, so the arduino is receiving the signals. But, the motors are not doing anything at all.
Does anyone know what I am doing wrong?
Thank you so much in advance!
Rynoa