Monitoring 24V LED stack tower lights status

See this make things easy:

makes it straight ahead. There's even a guy in the comments section using it to deal with getting logic levels for a 24 system to his 5 volt device…

Two channels on one board. Cheap enough.

You can find through-hole ICs and spend less money trade off for the time and fun (or hassle) of making your own equivalent.

a7

The time I have is limited, all I have for the moment is three 24V relays.
This is why I'm asking if there is a way to use them and if it will do the work

Perhaps already answered:

Yes. See if you get the relays to energize and de-energize by tapping the voltage that the lamps get.

Relay coil in parallel with the lamp.

Then use a standard method of connecting a switch to an Arduino.

Wire one relay contact to Arduino ground.

The other relay contact to Arduino input pin.

A pull-up resistor of unimportant value anything like 4K7 or 10K wired from the input pin to Arduino 5 volts.

A 0.1 uF cpacitor across the relay switch contacts can't hurt, but isn't strictly necessary.

Use the relay's NO normally open contacts.

Use

  pinMode(theInputPin, INPUT);

and

  char someVariable = digitalRead(theInputPin);

will be LOW when the lamp is energized, HIGH when not.

In a nutshell.

a7

The current in the tower light is 0.3A. I think relays in this case would be limited.

OK a quick scan shows you have not shared the specifications of the 24 volt relays you using.

Imma bet they would not be a significant extra burden to the power consumed by the lamps they are in parallel with.

But no way to know without knowing the exact relay.

How are the lamps energized? It is possible that you would need a diode across the relay coil if they are driven by a solid state circuit.

a7

Hello,

I tried to work with only one relay, and make this code to display its status, but the only thing I get is when relay is “ON” when it’s hight in all cases : with or without 24V power supply.

The code :

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C LCD(0x27,16,2);

const int relay = 1;

int relayState = 0;

void setup(){
Serial.begin(9600);
Serial.println(F(“Initialize system”));

LCD.init();
LCD.backlight();
pinMode(relay, INPUT);
}

void loop(){
relayState = digitalRead(relay);

if(relay == HIGH) {
LCD.setCursor(3, 0);
LCD.print(“ON”);

}
else {
LCD.setCursor(3, 0);
LCD.print(“OFF”);
}
}

Thank you for helping

Nope! You want to check relayState, not compare the relay pin number to HIGH.

Also: Autoformat your code and place it in between three ``` ticks so it looks better

    three ticks on a line before your code

    three ticks on a line after your code

And before you put your code in there, use the Tools/AutoFormat to make it look pretty.

a7

Ok.
I changed but doesn't make differnce. It's like lcd meomrize the last displayed thing.
It gives me now "OFF" even if the relay contacts are closed

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C LCD(0x27,16,2);

const int relay = 2;

int relayState = 0;

void setup(){
  Serial.begin(9600);
  Serial.println(F("Initialize system"));

  LCD.init();
  LCD.backlight();
  pinMode(relay, INPUT);
}

void loop(){ 
  relayState = digitalRead(relay);
  
  if(relayState == HIGH) { 
    LCD.setCursor(3, 0); 
    LCD.print("Machine ON");
    
  }  else {
    LCD.setCursor(3, 0); 
    LCD.print("Machine OFF");
    }
}

You should post a sketch, your drawing, of what you are doing.

Place

 Serial.print(" relay sez ");
 Serial.println(RelayState ? "HIGH" : "LOW");

after you digitalRead(), to see what you are getting.

Temporarily replace the relay contacts you are using with a pushbutton or switch.

Divide and conquer, divide and rule.

Can you hear the relay opening and closing?

a7

Hello,
sorry to be late responding.

1 - Relays NO is wired with Arduino analog pins, because when I use digitalread(), it is still stuck on one single statut.
2 - When I use analogread(relay), both status are displayed on LCD. Power on, gives me "ON", but when it's off, I see two status : ON and OFF.

What I did :

  • I fed relay coils with 24V.
  • The COM with Arduino 5V
  • NO contact with an analog pin, through a resistor

What I want :

  • Read this relay status and display it on lcd. When it is high, display "ON", when it is LOW, "OFF" should be displayed.

And yes I can hear the relay closing/opening

Change to INPUT_PULLUP.

It can't hurt.

Analog input pins should work perfectly well as digital inputs.

With a pushbutton and serial printing, see the pushbutton go up and down, pressed and not. Then see the relay, hear it click and see it going up and down, closed and open.

Using the LCD as you only feedback is OK, but you should always try to test at the simplest possible level.

a7

There is something wrong here I think.

void loop(){ 
  relay1_State = digitalRead(relay1);
  
   if(relay1_State == HIGH) { 
    LCD.setCursor(0, 0); 
    LCD.print("ON");

  relay2_State = digitalRead(relay2);
   if(relay2_State == HIGH) 
   LCD.setCursor(0, 1);  
   LCD.print("OFF");
    
   }

Citation

As in - what should happen if, say !relay1_State or !relay2_State ?

I don't know what you are tryinh to do.

void loop(){ 
  relay1_State = digitalRead(relay1);
  
   if(relay1_State == HIGH) { 
    LCD.setCursor(0, 0); 
    LCD.print("ON");

  relay2_State = digitalRead(relay2);
   if(relay2_State == HIGH) 
   LCD.setCursor(0, 1);  
   LCD.print("OFF");
    
   }

Read your code.

If relay1 is HIGH, print ON at one position.

If relay2 is HIGH , print OFF at another position.

If you have verified that you can read the state of two relays, this code is probably doing exactly what it sez.

a7

displays "ON" when relay1_State == HIGH
displays "OFF" when relay2_State == LOW

What's it supposed to 'display' if "relay1_State == LOW" or relay2_State == HIGH ?

But none of these two if statements is doing what I want

I am sorry
I mean :
displays "ON" when relay1_State == HIGH
displays "OFF" when relay2_State == HIGH