Dear Sirs
I started to study Arduino, my first programing experience, from yesterday.
My first target is receive infrared signal then activate DC motor driver.
My Aim is to activate the driver only while infrared signal is active but my program perform different. it activate DC motor driver forever.
Arduino Output is Pin 7,5,and 3.
Arduino: Arduino UNO
Motor Driver:L294D
#include <IRremote.h>
// Author ralph Fujiyama
int RECV_PIN = 11; //define IR Pin 11
IRrecv irrecv(RECV_PIN);
decode_results results;
const int ENABLE = 7;
const int CH1 = 5;
const int CH2 = 3;
void setup()
{
irrecv.enableIRIn();
// set motor contorl pin output
pinMode(ENABLE,OUTPUT); // define pin 7 as OUTPUT
pinMode(CH1,OUTPUT); // define Pin 5 as OUTPUT
pinMode(CH2,OUTPUT); // define Pin 3 as OUTPUT
Serial.begin(9600);
digitalWrite(ENABLE,LOW); // disable
delay(500);
}
void loop() {
if (irrecv.decode(&results)) {
irrecv.resume();
if (results.value == 0x00FF906F){ // transmitter button then motor on
// turn on motor clock wise
decode_results results;
Serial.println("Volume UP");
digitalWrite(ENABLE,HIGH); // enable on
digitalWrite(CH1,HIGH);
digitalWrite(CH2,LOW);
}else if(results.value == 0x00FFE01F){ // unti clock wise
decode_results results;
Serial.println("Volume Down");
digitalWrite(ENABLE,HIGH); // enable on
digitalWrite(CH1,LOW);
digitalWrite(CH2,HIGH);
}
}}γ³γΌγγγγγ«ε ₯ε
If you could help, that will be highly appriciated.
You didn't put in any code to detect when the infrared signal was "not active" and turn off the motor. Figure out how long between repeats of the IR signals and turn off the motor if you have not received a new message in that time.
Quick and dirty: Turn on the "Show timestamp" option in Serial Monitor. Calculate the time difference between "Volume UP" messages. That is the repeat time.
When you get an Up or Down message, start a timer. If the timer reaches twice the repeat time, turn off the motor.
Thank you very much for your kind advise.
I tried sketch below but result was "motor do not turn on".
I wonder this is because aspect of motor driver IC or my sketch is not good.
γ³γΌγγγ#include <IRremote.h>
// Author ralph Fujiyama
int RECV_PIN = 11; //define IR Pin 11
IRrecv irrecv(RECV_PIN);
decode_results results;
const int ENABLE = 7;
const int CH1 = 5;
const int CH2 = 3;
void setup()
{
irrecv.enableIRIn();
// set motor contorl pin output
pinMode(ENABLE,OUTPUT); // define pin 7 as OUTPUT
pinMode(CH1,OUTPUT); // define Pin 5 as OUTPUT
pinMode(CH2,OUTPUT); // define Pin 3 as OUTPUT
Serial.begin(9600);
digitalWrite(ENABLE,LOW); // disable
delay(500);
}
void loop() {
if (irrecv.decode(&results)) {
irrecv.resume();
if (results.value == 0x00FF906F){ // transmitter button then motor on
// turn on motor clock wise
decode_results results;
Serial.println("Volume UP");
digitalWrite(ENABLE,HIGH); // enable on
digitalWrite(CH1,HIGH);
digitalWrite(CH2,LOW);
}else if(results.value == 0x00FFE01F){ // unti clock wise
decode_results results;
Serial.println("Volume Down");
digitalWrite(ENABLE,HIGH); // enable on
digitalWrite(CH1,LOW);
digitalWrite(CH2,HIGH);
}
else { // stop
digitalWrite(ENABLE,LOW); // disable
decode_results results;
Serial.println("stay");
digitalWrite(ENABLE,LOW); // enable on
digitalWrite(CH1,LOW);
digitalWrite(CH2,LOW);
}}}