Never used an IR receiver before in a project but everything seems to be working fine until i combine it with a motor, and once it reads the serial monitor it keeps spinning and printing the words forever :,( just want to make a curtain closer.
#include <IRremote.h>
IRrecv rec(9);
int bwrd = 12;
int frwd = 13;
void setup() {
// put your setup code here, to run once:
rec.enableIRIn();
pinMode(bwrd, OUTPUT);
pinMode(frwd, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (rec.decode()) {
Serial.println(rec.decodedIRData.decodedRawData, HEX);
delay(1500);
}
if (rec.decodedIRData.decodedRawData==0xF30CFF0) {
digitalWrite(frwd, HIGH);
delay(200);
Serial.println("stahp!!");
digitalWrite(frwd, LOW);
}
if (rec.decodedIRData.decodedRawData==0xE718FF00) {
digitalWrite(bwrd, HIGH);
delay(200);
Serial.println("wait!!");
digitalWrite(bwrd, LOW);}
rec.resume();
}
I also know like nothing about programming or electronics beyond college basics.
i have no idea i think it retains its value until it resumes at the end which makes it start the search again but i could be entirely wrong ive just seen a few tutorials.
It's a class variable that would need to have something done to it to change its value.
Can we take you at you word on this
everything seems to be working fine
but I would prefer testing that would allow you to say "it works perfectly doing what I write the code to do...". You may need to add to your sketch to prove it.
ok so take the motors out of the equation for now and just read the IR. Also remove the delays. There is a better non-blocking way to add a delay. There is an example sketch called Blink Without Delay.
the IR sensor works and reads values on its own perfectly fine and starts the motor in the right direction ive programmed it to it just doesn't stop lol
then once you want the motors to stop, you need a way to clear rec.decodedIRData.decodedRawData. There should be a way to do that, otherwise you will need a third button to stop the motors yourself.