Hi all, I hope every body is well. I have a very annoying problem!
I have as suggested in the title a small dc motor salvaged from a CD-ROM, a salvaged IR sensor from an old DVD player and have used a 556 timer as an H-Bridge (as desribed here -->555 / 556 H bridge – Electro Bob). Ooh and i am on an Arduino Mega (1280).
If i run this code it works as expected, the motor spins one way, stops, spins tother way, stops... so on and so forth.
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
analogWrite(8, 75); //pwm for lower speed
digitalWrite(9, LOW);
delay(3000);
digitalWrite(8, LOW);
delay(2000);
digitalWrite(8, LOW);
analogWrite(9, 75); //pwm for lower speed
delay(3000);
digitalWrite(9, LOW);
delay(2000);
}
I decided that i would like to control the direction of spin via a remote control (funky uh!!!) so set about connecting and testing the IR reciever that i salvaged and after a minute or two had it fully functioning as expected using Ken Sharriff's IRremote library here-->Using arbitrary remotes with the Arduino IRremote library.
After successfully turning an led on and of using two buttons on my remote i connected up the H-Bridge and motor and adjusted the code to this:
#include <IRremote.h>
int RECV_PIN = 4;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
pinMode(8, OUTPUT); // "A"
pinMode(9, OUTPUT); // "B"
irrecv.enableIRIn(); // Start the receiver
Serial.begin(9600);
}
void loop() {
if (irrecv.decode(&results)) {
switch (results.value) {
case 0xFFD827: // play button on my remote
analogWrite(8, 75); //pwm for lower speed
digitalWrite(9, LOW);
delay(3000);
digitalWrite(8, LOW);
break;
case 0xFF02FD: // stop button on my remote
digitalWrite(8, LOW);
analogWrite(9, 75); //pwm for lower speed
delay(3000);
digitalWrite(9, LOW);
break;
}
irrecv.resume();
}
}
Fired everything up and success!!! Well sort of lolol!!! I press the play button on my remote and voila the motor spins for a few seconds and stops! I then pressed the stop button on my remote and got a grand total of 'zilch'!!! So i made sure i was looking for the correct remote code for stop and even output to the serial monitor to make sure everything was fine. All OK there! So I swapped the codes for the play and stop buttons around and sure enough the stop button worked but now the play button doesn't. Only one thing I can put it down to folks....my code sucks!!!lololol!!
So here I am asking the experts for help! (sorry for waffling on, and thanks for your time!):
Regards,
Ian