Hi. This is my first ever post on this forum.
Also i am a beginner to arduino,
I want to control two DC motors probably 2.5/3 volt. I have tested motors with example code named "MOTOR PARTY" motors are working fine.
Now i want to control them with a remote of MP3 player.
Here is my code:
#include <IRremote.h>
#include <AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
int RECV_PIN = A5;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long lastCode;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
motor1.setSpeed(100);
motor1.run(RELEASE);
motor2.setSpeed(100);
motor2.run(RELEASE);
}
void loop() {
if (irrecv.decode(&results))
{
if(results.value == 0xFFFFFFFF)
{
results.value = lastCode;
}
if(results.value == 0x807FA05F)
{
lastCode = results.value;
up();
}
if(results.value == 0x807F609F)
{
lastCode = results.value;
down();
}
if(results.value == 0x807F906F)
{
lastCode = results.value;
right();
}
if(results.value == 0x807F807F)
{
lastCode = results.value;
left();
}
delay(20);
Serial.println(lastCode, HEX);
irrecv.resume(); // Receive the next value
}
// delay(100);
}
void up()
{
motor1.run(FORWARD);
motor2.run(FORWARD);
}
void down()
{
motor1.run(BACKWARD);
motor2.run(BACKWARD);
}
void right()
{
motor1.run(FORWARD);
motor2.run(BACKWARD);
}
void left()
{
motor1.run(BACKWARD);
motor2.run(FORWARD);
}
On "Serial monitor" it is giving absolutely correct output. But the motors are not moving at all.
In short motors are not working by the code mentioned above. When i am uploading this code and pressing a button, Serial Monitor is giving correct output, but motors are not working.
Please help me asap.
Thanks.