1
\$\begingroup\$

I am working in Arduino on a mini pro. I have an old MP3 remote which transmits infrared at about 38Khz. I have a program written that when my infrared sensor is picking up on a signal from the remote it tells a relay pin to be low and to make the relay pin high if it does not pick up on a signal from the remote. The loop is constantly running and checking so "if (receiving) pin -> low" and "if (not receiving) pin -> high." My problem is that the MP3 remote doesn't send a constant signal. It constantly flickers on and off, which causes the relay to flicker on and off when it should stay off.

I am trying to figure out how long to set a delay to perfectly offset the flickering of the signal from the remote. If I cannot offset the flickering are there any other solutions to use the IR on the same wavelength without flickering?

All help is very welcome and I am open to ideas and suggestions!!!!

This is the code I already have but it has taken a while and I am not very confident with Arduino code.

#include <boarddefs.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#include <IRremote.h>
#include <IRremoteInt.h>

int RECV_PIN = 11;
int OUTPUT_PIN = 4;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
 pinMode(OUTPUT_PIN, OUTPUT);
 pinMode(13, OUTPUT);
 irrecv.enableIRIn(); // Start the receiver
}

int on = 0;
unsigned long last = millis();

void loop() {
  if (digitalRead(RECV_PIN) == LOW) {
   digitalWrite(OUTPUT_PIN, LOW);
 }
 else if (digitalRead(RECV_PIN) == HIGH){
  digitalWrite(OUTPUT_PIN, HIGH);
 }
irrecv.resume(); // Receive the next value
} 
\$\endgroup\$

closed as off-topic by Nick Alexeev Jan 5 '17 at 17:52

  • This question does not appear to be about electronics design within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    \$\begingroup\$ You want a countdown timer - any time you receive signal, turn the relay on and reset the countdown to a value longer than the gap. When you don't get signal, start counting down. Only if the count reaches zero should you turn off the relay. Probably put a small delay in the loop to make the time somewhat deterministic - that will be crude, but likely workable enough. FYI, if the remote's transmission did not pulse the 38 KHz on and off at a lower rate, the receiver module would soon ignore it. \$\endgroup\$ – Chris Stratton Jan 5 '17 at 2:50
  • \$\begingroup\$ what is the purpose of the relay? you could add a delay after "if (receiving) pin -> low" and also after "if (not receiving) pin -> high.". By varying the delay, you could get away with it. this should work, unless you are into something more serious. \$\endgroup\$ – Umar Jan 5 '17 at 2:53
  • \$\begingroup\$ The purpose of the relay is to accept the 12v battery pack and only occasionally send 12v to the solenoid. \$\endgroup\$ – Sam Vincent Jan 5 '17 at 3:47
  • \$\begingroup\$ How would I write the code for a countdown that resets every time it receives so that only after a delay after it stops receiving does it send high to the pin? \$\endgroup\$ – Sam Vincent Jan 5 '17 at 3:48
0
\$\begingroup\$

You really should be using the microcontroller to decode the transmissions from the IR remote. If you do that you could see when some particular button is pressed and take action on that specifically. For examples:

  1. Decode two different buttons one which turns the relay on and another that turns it back off.
  2. Watch the repeating transmits from the remote control as as long as the same button is pressed keep the relay on.

If you still want to make it work just on the detection of modulation from the IR receiver then use an oscilloscope to see how often the remote sends the transmissions. (These things often will send at a repeat rate of ten times per second).

A better scheme would be to detect the start of the transmission detection and then turn on the relay based upon that. Then shut the relay off if there has been no start of detection within say .15 seconds. The reason this could be better is that some IR remotes will send a long packet when a button is first pressed and will then send a very short packet in repeat indication as the button is held down.

The problem with any simple envelope detection like you are doing now and in these latter described schemes is that they are very susceptible to IR interference. If you look at the output of a typical IR receiver module with an oscilloscope it is not uncommon to see all kinds of random detects coming out even when the IR remote control transmitter is not active. This is why I initially recommend that you decode the transmission protocol itself to ensure that you are seeing legitimate transmissions.

\$\endgroup\$
  • \$\begingroup\$ I have decoded each button and using a button to turn it off then back on again isn't really what I'm looking for. I'm designing a safety system and what I really need is for the relay to go high when no IR is detected from the remote. Thank you! I am also not very confident with arduino code. \$\endgroup\$ – Sam Vincent Jan 5 '17 at 3:18
  • \$\begingroup\$ If you are trying to make a safety system and are not confident about your work I would strongly recommend that you seek the help of a seasoned professional. \$\endgroup\$ – Michael Karas Jan 5 '17 at 13:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.