CODE
#include <IRremote.h>
//this pin will be used to power the IR chip (to prevent noise from the motor)
int voltPin = 11;
//IR remote
int IRpin = 5;
IRrecv IR(IRpin);
decode_results cmd;
//MOTOR
int en1 = 9;
int dir1 = 8;
int dir2 = 7;
void setup() {
IR.enableIRIn();
pinMode(en1, OUTPUT);
pinMode(dir1, OUTPUT);
pinMode(dir2, OUTPUT);
pinMode(voltPin, OUTPUT);
digitalWrite(voltPin, HIGH);
Serial.begin(9600);
}
void loop() {
while (IR.decode(&cmd) == 0){
}
delay(200);
IR.resume();
//FORWARD
if(cmd.value == 0xCC3359A6){
digitalWrite(dir1, HIGH);
digitalWrite(dir2, LOW);
analogWrite(en1, 255);
}
//BACKWARDS
if(cmd.value == 0xCC33D926){
digitalWrite(dir1, LOW);
digitalWrite(dir2, HIGH);
analogWrite(en1, 255);
}
//STOPS
if(cmd.value == 0xCC334BB4){
digitalWrite(dir1, LOW);
digitalWrite(dir2, LOW);
analogWrite(en1, 0);
}
}
CIRCUIT:
*note: I use a MB102 power supply module on the breadboard (circuit diagram doesn't show it). Also, the circuit shows a 4510 BCD counter instead of the L293D chip because the software I used didn't have it (sorry but I didn't know what to do). This is what the different ports correspond to:
"Load": EN1
"L0": IN1
"L1": OUT1
"L2" and "L3": 0V
"Clock": OUT2
"TC": IN2
"Gnd": +Vmotor