Which one will work ?

Dear All …

I’m building relayboard control with arduino.
I use Analog pin to signal the relay … using simple digitalWrite to analogpin.

The problem is not with the relay … but I want to “status” indicator using Leds.
Since the relay will operated at NC, I need to Inverting the logic state that signal the LED.

That is : When digitalWrite(A0, HIGH) … I want LED#1 Down.

I think that Hex Inverter will do … so I pick 74HC04P for me.

But I failed to interface 74HC04P to my arduino, the LEDS always off.

Attached is my schematic (from eagle).
Kindly please tell me which one of this schematic will work ?
The top one (74HC04P as “source”) ?
or the bottom one (74HC04P as “Sink”) ?
or both will not work .

Sincerely
-bino-

Both of those circuits should control the LEDs, are you saying that neither work?

Have you set the pins to be outputs?

Show us the code.

But I doubt you need either if all you want is a status for the relay. You can put a LED in parallel with the relay coil or directly on the Arduino pin.

How are you controlling the relays?

_____- Rob

Graynomad:
Both of those circuits should control the LEDs, are you saying that neither work?

Unfortunately … yes

Graynomad:
Have you set the pins to be outputs?

Show us the code.

Pin definition and setup()

const int pwr_pin[6]={14,15,16,17,18,19};
void setup() 
{
  for (int i=0; i<6; i++){
    pinMode(pwr_pin[i], OUTPUT);
    digitalWrite(pwr_pin[i],LOW);
    
  }
  Serial.begin(9600);
  delay(2000);
  Serial.println("system startup");
  //Serial.println("Waking up GSM modem ... need some times");
  gsm.TurnOn(9600);          //module power on
  gsm.InitParam(PARAM_SET_1);//configure the module  
  gsm.Echo(0);               //enable AT echo 
  delay(1000);
  Serial.println("Ok .. Let's go !");
  Serial.flush();
}

Function that set the pin HIGH/LOW

void do_pwr(char* sms_rx){
//Serial.println(“Switching Power”);
//Let’s parse power control commands
int sms_rx_pos=0;
char cmd_text[2]={};
int cmd_pos=0;
int thispin = 0;
for (sms_rx_pos=4;sms_rx_pos < strlen(sms_rx);sms_rx_pos++){
if (sms_rx[sms_rx_pos] == ‘,’){
cmd_text[0]=’\0’;
cmd_pos=0 ;
sms_rx_pos++;
} //End of ‘,’
if (cmd_pos==0 && sms_rx[sms_rx_pos]>‘0’ && sms_rx[sms_rx_pos]<‘7’){
//Serial.print("Set Pin “);
cmd_text[0]=sms_rx[sms_rx_pos];
thispin = cmd_text[0]-49;
//Serial.println(thispin);
cmd_pos=1;
sms_rx_pos++;
} // end of cmd_pos =0
if (cmd_pos==1){
//Serial.print(”—>TO : “);
char pwr_ctrl_type = toUpperCase(sms_rx[sms_rx_pos]);
//Serial.print(pwr_ctrl_type);
//Serial.print(” >> ");
switch (pwr_ctrl_type) {
case ‘U’:
cmd_text[1]=toUpperCase(sms_rx[sms_rx_pos]);
cmd_pos=0;
Serial.println(“UP”);
// It’s NC , So “UP” Means LOW
digitalWrite(pwr_pin[thispin],LOW);
break;
case ‘D’:
cmd_text[1]=toUpperCase(sms_rx[sms_rx_pos]);
cmd_pos=0;
Serial.println(“DOWN”);
// It’s NC , So “DOWN” Means HIGH
digitalWrite(pwr_pin[thispin],HIGH);
break;
case ‘R’:
cmd_text[1]=toUpperCase(sms_rx[sms_rx_pos]);
cmd_pos=0;
Serial.println(“RESET”);

//High First
digitalWrite(pwr_pin[thispin],HIGH);
//wait 2 secs
//delay(2000);
//And then LOW
digitalWrite(pwr_pin[thispin],LOW);

break;
default :
break;
//Serial.print("!2");
} //End of Switch Case
} //end of CMD_pos=1
} //end of for-loop
}

Graynomad:
But I doubt you need either if all you want is a status for the relay. You can put a LED in parallel with the relay coil or directly on the Arduino pin.

How are you controlling the relays?

_____-
Rob

Well … since it’s NC relay, I need to set the control pin HIGH.
If I put led just paralel with relay … the LED will “ON” while the relay load “OFF”.
Thats why I put NOT gate between controll pin and LED

Meanwhile … somebody told me to decrease the LED and R size.
I’ll try it and 'll back here.

I realy appreciate your response.

Sincerely
-bino-

somebody told me to decrease the LED and R size.

Yes 1k is a bit high but you should still see them I would think.

The setup looks OK to me. Have you looked at the inputs to the '04?

All that code is way too much to wade through just to see if some LEDs work, but obviously with this code

            digitalWrite(pwr_pin[thispin],HIGH);
              //wait 2 secs
              //delay(2000);
              //And then LOW             
              digitalWrite(pwr_pin[thispin],LOW);

as is you won't see anything.


Rob

const int pwr_pin[6]={14,15,16,17,18,19};

Small problem I see. You define a 6 item array for 6 items, but Arduino needs an extra null character at the end. http://www.arduino.cc/en/Reference/Array This should fix this issue:

const int pwr_pin[7]={14,15,16,17,18,19};

As to your other problem, why not have the relay and LED on the same pin? LED+resistor from +5V to the pin, and Relay from Ground to the same pin. If pin is high, Relay will be energized and LED off. If pin is low, Relay will be de-energized and LED on.

but Arduino needs an extra null character at the end.

Only for strings.


Rob

John_S: As to your other problem, why not have the relay and LED on the same pin? LED+resistor from +5V to the pin, and Relay from Ground to the same pin. If pin is high, Relay will be energized and LED off. If pin is low, Relay will be de-energized and LED on.

Yes I did, i.e: Inverter input-pin1 , goes to Arduino Analog-pin0 ULN2803 input-pin1, also goes to Arduino Analog-pin0

Relay is drived by ULN2803 output-pin

Sincerely -bino-