Hello all, so what I'm trying to accomplish is controlling 2 motors via a L2R3D via IR.
Source/Credit: http://www.instructables.com/id/Arduino-and-L293D-Robot-Part-1-/?ALLSTEPS
http://www.instructables.com/id/Arduino-and-L293D-Robot-Part-2-Infrared-Sensor/?ALLSTEPS
I know the pins are connected correctly (verified by running motor forward and reverse in seperate program) (and IR is hooked up right by verifying input on another seperate program).
The problem is this: when I upload my program I receive no response from the IR (even though it blinks to indicate physically it's received). I've put various serial.prints in the code and it's not entering past the " if (irrecv.decode(&results))" line.
Any tips?
#include "IRremote.h"
int LeftMotorForward = 10; // Pin 10 has Left Motor connected on Arduino boards.
int LeftMotorReverse = 12; // Pin 9 has Left Motor connected on Arduino boards.
int RightMotorForward = 9; // Pin 12 has Right Motor connected on Arduino boards.
int RightMotorReverse = 13; // Pin 13 has Right Motor connected on Arduino boards.
int receiver = 2; // Signal Pin of IR receiver to Arduino Digital Pin 6
int sec = 100; // Delay integer
int basespeed = 125;
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
//-----------------------------------------------------------------------------
void setup()
{
pinMode(LeftMotorForward, OUTPUT); // initialize the pin as an output.
pinMode(RightMotorForward, OUTPUT); // initialize the pin as an output.
pinMode(LeftMotorReverse, OUTPUT); // initialize the pin as an output.
pinMode(RightMotorReverse, OUTPUT); // initialize the pin as an output.
irrecv.enableIRIn(); // Start the receiver
Serial.begin(9600);
}
//-----------------------------------------------------------------------------
void loop() {
if (irrecv.decode(&results)) // have we received an IR signal?
{
switch (results.value)
{
case 0x3D9AE3F7: // UP/2 button pressed
Driveforward;
break;
case 0x1BC0157B: // DOWN/8 button pressed
Reverse;
break;
case 0xFF5AA5: // RIGHT/6 button pressed
Rightturn;
break;
case 0x8C22657B: // LEFT/4 button pressed
Leftturn;
break;
// Get code for 5 center when other stuff starts working
// case 0x8C22657B: // STOP/4 button pressed
// Allstop;
// break;
}
}
irrecv.resume(); // receive the next value
}
//-----------------------------------------------------------------------------
void Driveforward() {
if (results.value == 0xFFFFFF) {
digitalWrite(RightMotorForward, basespeed + 20); // turn the Right Motor ON
digitalWrite(LeftMotorForward, basespeed + 20); // turn the Left Motor ON
}
else {
digitalWrite(RightMotorForward, basespeed); // turn the Right Motor ON
digitalWrite(LeftMotorForward, basespeed); // turn the Left Motor ON
delay(sec); // wait for 1 second
digitalWrite(RightMotorForward, LOW); // turn the Right Motor OFF
digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
delay(sec); // wait for 1 second
}
}
void Rightturn() {
digitalWrite(RightMotorForward, LOW); // turn the Right Motor OFF
digitalWrite(LeftMotorForward, HIGH); // turn the Left Motor ON
delay(sec); // wait for 1 second
digitalWrite(RightMotorForward, LOW); // turn the Right Motor OFF
digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
delay(sec); // wait for 1 second
}
void Leftturn() {
digitalWrite(RightMotorForward, HIGH); // turn the Right Motor ON
digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
delay(sec); // wait for 1 second
digitalWrite(RightMotorForward, LOW); // turn the Right Motor OFF
digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
delay(sec); // wait for 1 second
}
void Reverse() {
digitalWrite(RightMotorReverse, HIGH); // turn the Right Motor ON
digitalWrite(LeftMotorReverse, HIGH); // turn the Left Motor ON
delay(sec); // wait for 1 second
digitalWrite(RightMotorReverse, LOW); // turn the Right Motor ON
digitalWrite(LeftMotorReverse, LOW); // turn the Left Motor ON
delay(sec); // wait for 1 second
}
void Allstop() {
digitalWrite(RightMotorReverse, LOW); // turn the Right Motor ON
digitalWrite(LeftMotorReverse, LOW); // turn the Left Motor ON
delay(sec); // wait for 1 second
digitalWrite(RightMotorForward, LOW); // turn the Right Motor OFF
digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
delay(sec); // wait for 1 second
}