IR remote receiver not working while relay is HIGH

I'm newbie with Arduino, I have just one week of research.

I brought I starter kit and done the example projects. Now I'm trying to create one on my own. But I'm having troubles:

I could manage to make a example of controlling a LED using IR remote. But, when I changed the LED to a relay and a motor (using 5V pin of the Arduino board, i. e., without external supply), I can't turn off the relay using the remote (using communication through the serial port - USB - it works).

I start my Arduino.ino with the relay LOW and I can turn it HIGH using IR remote, and so turning the motor on. But after that the IR receiver doesn't receive data anymore (I call resume method properly).

The problem is not in the code, because the same code works with LED example (to turn it on and turn it off). I'm suspecting that relay + motor is expanding the total of energy when it's on, but I cannot prove it.

Please help-me.

Suggestion of apps to draw the Arduino Electric Scheme will be appreciated too.

Thank you.

[UPDATE]
I have also changed the IR remote receiver by a push button, and it works too.

[UPDATE]
To test, I run in DEBUG mode and when the relay is LOW the IRremote lib keep printing the following lines to serial:

Testing mark 50 vs 9000: 136 <= 1 <= 228
Attempting NEC decode

After I change relay to HIGH the lines stop printing.

Have you read all of this: https://www.arduino.cc/en/Tutorial/DigitalPins

And had a look at this: digitalWrite does not trigger Relay - Programming Questions - Arduino Forum

If those don't apply to your problem, then please provide a schematic and links to datasheets for your components so that the good people of the forum can help you.

If you are driving the relay directly from the output pin, you risk damaging your Arduino. If it works with a LED but not a relay, you need to use a transistor driver for the relay. Don't forget the diode reverse connected across the coil.

Weedpharma

Maruero:
Suggestion of apps to draw the Arduino Electric Scheme will be appreciated too.

Pencil, paper and the back of an envelope. I've been using it for years.
If I have to make it neat, I use Open Office. But that's just me.

Thank you People for your help.

Martin-X and Weedpharma, yes I read all the Digital Pin docs and that is not my problem, because I working with a relay that can be driven by the Digital Pin (it's used in this way in a example project that came with my starter kit).

The relay I'm using is a HRS1H-S-DC5V:

And the motor I'm using is a small 6V 130 Motor.

As I wrote in the post, the problem is not control the relay, the problem is receiving IR remote information. In my code, when receive the command by serial it turns the motor off and on without problem, i. e., I don't have problem commanding the relay through digital pin.

But, somehow the relay + motor is affecting the IR remote receiver.

As wrote too, when I exchange the IR remote receiver to a push button (on the same pins) it worked too.

#include <IRremoteTools.h>

int relayPin = 3;                          
int relayState = HIGH;
int incomingByte = 0;
  
void setup() {
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, relayState); 

  beginIRremote();
  
  Serial.begin(9600);
}
 
void loop(){

  if(IRrecived()){
    Serial.println(getIRresult(), HEX);
    if(getIRresult() == 0xFD00FF){
      relayState = !relayState;
      digitalWrite(relayPin, relayState);
    }
    
    delay(1000);
    Serial.println("Before resume");
    resumeIRremote();
  }

  if (Serial.available() > 0) {
    incomingByte = Serial.read();
    Serial.print("I received: ");
    Serial.println(incomingByte, DEC);
    
    if( incomingByte == 49 ){
      relayState = LOW;
      digitalWrite(relayPin, relayState);
    }else{
      relayState = HIGH;
      digitalWrite(relayPin, relayState);
    }
  }
}

Maruero:
Martin-X and Weedpharma, yes I read all the Digital Pin docs and that is not my problem, because I working with a relay that can be driven by the Digital Pin (it's used in this way in a example project that came with my starter kit).

Sorry, wrong. That relay will draw about 40mA. It is too much for an Arduino pin.

Aarg,

At the doc there is:

Atmega pins can source (provide positive current) or sink (provide negative current) up to 40 mA (milliamps) of current to other devices/circuits.

That is not the exactly value that the relay will draw?
I'm relaying on this. Can you explain why this cannot be true to my case?

Thank you.

Maruero:
Aarg,

At the doc there is:
That is not the exactly value that the relay will draw?
I'm relaying on this. Can you explain why this cannot be true to my case?

Thank you.

From the Atmel datasheet:

*NOTICE: Stresses beyond those listed under “Absolute
Maximum Ratings” may cause permanent damage
to the device. This is a stress rating only and
functional operation of the device at these or
other conditions beyond those indicated in the
operational sections of this specification is not
implied. Exposure to absolute maximum rating
conditions for extended periods may affect
device reliability.

...and the dead horse gallops back from the slaughterhouse yet again... (this comes up several times a month)

Stupid question:
Can I use a resistor to drop current, or with a resistor it's not going to work?

A resistor is not the solution, a transistor or mosfet would be.

Assuming the current draw is OK for the Arduino (20mA would be an ideal maximum), then you should also consider if the voltage is dropping below the working range of the IR receiver (datasheet?) or if interference from the motor/relay is affecting normal operation. Does it work without the motor, just the relay?

A schematic would really help.

And do you have a diode reverse connected across the relay coil?

Weedpharma

Weedpharma, yes I have a diode connected across the relay coil for guarantee. But DC relay do need diode indeed? I found some articles saying that DC relays have diode inside, is that true?

Anyway, I found a solution to my problem, its due to interference like Martin-X said: arduino - Supply noise due to Motor - Electrical Engineering Stack Exchange

I cut the wires of the IR receiver and it started working even when the motor is on.

So my question changed to: is there some component to put at my circuit that can avoid or decrease the noise created by the motor.

Tks!

I do not know of relays in general that have an in built diode. It would mean that they HAVE to be connected in a particular orientation.

Weedpharma

Maruero:
So my question changed to: is there some component to put at my circuit that can avoid or decrease the noise created by the motor.

Two people have asked you for a schematic. It is really hard to answer that without one.

Here is the schematic.

Motor is a 130 sized 4.5 to 9V.
Transistor is a BC337
Diode is a 1N4007.

The Arduino UNO is supplied by USB, and all 5V pin showed is 5V pin of the Arduino Protoboard.

Thank you. Are the two +5V connections in the schematic connected to the same power supply? Does the proto board not get it's 5V power from the Arduino (as described in your last post?).

Anyway, try putting a 0.1 uF ceramic capacitor directly across the motor terminals.

Proto board was put on top of Arduino UNO, so all +5V showed is supplied by the same USB. Tks.

You really shouldn't run a motor from the same 5V supply as the Arduino. You didn't say whether you added the capacitor that I recommended. Changing one or both of these conditions, will probably fix your problem.