Pages: [1]   Go Down
Author Topic: Problem interfacing arduino and relay  (Read 1675 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Reefduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.....?!?!?? smiley-sad

Can someone give me some advice on that?

Thanks in advanced


Here is the sketch I used...
Code:
// 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

NECIRrcv ir(IRPIN);
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);
      break;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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





« Last Edit: February 12, 2011, 05:09:49 am by lenny1972 » Logged

SW Scotland
Offline Offline
Edison Member
*
Karma: 17
Posts: 1405
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

jack
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17308
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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?

Lefty

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Reefduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Leonardo
Logged

Red Sea, Saudi Arabia
Offline Offline
God Member
*****
Karma: 12
Posts: 579
..On The Red Sea
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here are some 4 and 8 relay boards that only need +5 V.. maybe easier to use for some applications:
=relay&s[title]=Y&s[short_desc]=Y&s[full_desc]=Y&s[sku]=Y&s[match]=all&s[cid]=0]http://arduino-direct.com/sunshop/index.php?l=search_list&s[search]=relay&s[title]=Y&s[short_desc]=Y&s[full_desc]=Y&s[sku]=Y&s[match]=all&s[cid]=0
DISCLAIMER: From my shop... but I've been looking for good relay boards for awhile...
Logged

Regards, Terry King  ..On the Red Sea at KAUST.edu.sa
terry@yourduino.com  LEARN! DO! (Arduino Boards, Sensors, Parts @ http://yourduino.com

Pages: [1]   Go Up
Jump to: