Go Down

Topic: Problem interfacing arduino and relay (Read 2459 times) previous topic - next topic


Feb 12, 2011, 11:04 am Last Edit: Feb 12, 2011, 11:09 am by lenny1972 Reason: 1
Hi, I'm facing some problem in interfacing my Arduino Mega with a 8 relay shield.
The shield specification can be found here http://cgi.ebay.it/Eight-8-Relay-Module-Board-for-8051-PIC-Project-12V-/130485564595?pt=LH_DefaultDomain_0&hash=item1e618bb4b3.

I've powered the shield with an external 12 V DC power supply (1000 mA) and connect the GND of the power supply with the Arduino Mega GND pin (I've read it in some posts).
I've also set an Arduino DIGITAL pin as OUTPUT (pin 50 on the sketch) and put it to HIGH but the realy remain open and didn't change its state.....?!?!?? :(

Can someone give me some advice on that?

Thanks in advanced

Here is the sketch I used...
Code: [Select]
// look for IR codes and print them as they are received

//You also need to wire the 12 volt supply ground to the Arduino ground, otherwise the transistor will never turn on.

#include <WProgram.h>
#include <NECIRrcv.h>
#define IRPIN 36 // pin that IR detector is connected to

int PinRelay1 = 50;

void setup()
 Serial.begin(9600) ;
 Serial.println("NEC IR code reception");
 ir.begin() ;
 pinMode (PinRelay1, OUTPUT);
 //digitalWrite (PinRelay1,LOW);

void loop()
 unsigned long ircode ;
 while (ir.available()) {
   ircode = ir.read() ;
   //Serial.println (ircode);

   switch (ircode)

   case 3910598400:
     Serial.println ("Hai premuto il tasto 0");
     Serial.println ("attendi, sto accendendo il rele' 1");
     digitalWrite (PinRelay1, HIGH);

   case 4077715200:
     Serial.println ("Hai premuto il tasto 1");
     Serial.println ("attendi, sto spegnendo il rele' 1");
     digitalWrite (PinRelay1, LOW);

   case 3877175040:
     Serial.println ("Hai premuto il tasto 2");

   case 2707357440:
     Serial.println ("Hai premuto il tasto 3");

   case 4144561920:
     Serial.println ("Hai premuto il tasto 4");

   case 3810328320:
     Serial.println ("Hai premuto il tasto 5");

   case 2774204160:
     Serial.println ("Hai premuto il tasto 6");

   case 3175284480:
     Serial.println ("Hai premuto il tasto 7");

   case 2907897600:
     Serial.println ("Hai premuto il tasto 8");

   case 3041591040:
     Serial.println ("Hai premuto il tasto 9");

   case 3860463360:
     Serial.println ("Hai premuto il tasto 100+");

   case 4061003520:
     Serial.println ("Hai premuto il tasto Indietro");

   case 3125149440:
     Serial.println ("Hai premuto il tasto Spegnimento Totale");

 case 3108437760:
     Serial.println ("Hai premuto il tasto Mode");

   case 3091726080:
     Serial.println ("Hai premuto il tasto Mute");

   case 3141861120:
     Serial.println ("Hai premuto il tasto Pagina Precedente");

   case 3208707840:
     Serial.println ("Hai premuto il tasto Pagina Successiva");
    case 3158572800:
     Serial.println ("Hai premuto il tasto Play/Pause");
  case 4161273600:
     Serial.println ("Hai premuto il tasto Volume -");

   case 3927310080:
     Serial.println ("Hai premuto il tasto Volume +");
    case 4127850240:
     Serial.println ("Hai premuto il tasto Equalizzatore");

P.S: in the sketch I use a remote control for switch the realy to OPEN or CLOSED.


If you have a meter I suggest you check the arduino output port to confirm it is going both Hi and Lo on demand.

Is your arduino a 5 volt unit.  If not then a 3.3 volt output is not within the specification of your relay board and will not be switching it.

If it is a 5 volt unit and you are getting 5 volts output then there is a possibility that the relay board isn't being switched - even though its specification states it should switch at 4 volts.



Can someone give me some advice on that?

I suspect your problem is with your program and not the ability to turn on and off the relay. As a quick experiment, load the classic blink program from the Arduino IDE example sketches and just change the pin number used from pin 13 to pin 50. Then see if you can't hear the relay clicking on and off every second.

Those case statements look rather strange with those large values so maybe you aren't handling the IR library functions correctly?



No the problem wasn't the sketch (in addition even the remote control works great).
After testing all the other relay on the board I found that the problem was related to the 1st relay. The other 7 works perfectly.
I've just contacted the chinese seller to ask for a reinbursement...
Thanks a lot anyway for your reply.



Go Up