Low when fan is ON


#1

Hello,
I hava a control that is LOW when the fan is on and HI when the fan is off. How I can display invert in dashboard ?? I need to display 1 ( ON - green ) on generic input when the pin of arduino is low.

Thank all for suggestion .


#2

Hello,
What about “Invert Logic” tick?
You are using relay widget?
Also if you are using relay - what kind of relay is - active LOW or active HIGH? :slight_smile:


#3

No. Is a input. I need something like invert Logic of relay but on generic input.


#4

But your logic seems a little bit confusing

LOW when the fan is on and HI when the fan is off

I have similar behavior with a LED that is connected anode to +5 and cathode to i/o pin. It was behaving this way. When I change the wires, it behaves as I expect.

Do you want your way to be on purpose or?


#5

to be precise. I have to check if a load to 220v is turned on or not. to do this, I have created a type of optocoupler formed on one side with a led to 220v other by a photoresistor. The photo resistor is connected to gnd and I have a pullup resistor. so when the LED is off (the load is off) I have 5V on the Arduino pin, when it’s on I have 0v.


#6

Can you put your code? Delete the token and other sensitive data!


#7

There isn’t code. I read directly digital pin3.


#8

My idea is to reverse the logic when you read the digital pin3. If it is 0 send 1 and vise versa. Try to “lie” the widget with opposite logic.


#9

how ??

I was thinking whether to put the widget to a virtual pin and in the sketch put something like:

digital_pin_3 = digitalRead (3);
if (digital_pin_3 == HIGH) then cayenne.virtualwrite (virtual_pin, 0);
else cayenne.virtualwrite (virtual_pin, 1);

what do you think about it ?


#10

Exactly, from yesterday I was thinking of something like this - just to reverse the logic to fit the Widget.
Can you try it and update us if it is working because I don’t have possibility to try it right now.

Thank you.

digital_pin_3 = digitalRead (3);
if (digital_pin_3 == HIGH) 
{
cayenne.virtualwrite (virtual_pin, 0);
}
else 
{ 
cayenne.virtualwrite (virtual_pin, 1);
}

#11

Seems that works!!!

Great.

Thanks.


#12

Glad to hear it!


#13

this is the code

CAYENNE_OUT(VIRTUAL_PIN3)
{
//IF DIGITAL PIN IS LOW THEN VIRTUAL PIN IS HIGH
bool stato=digitalRead (DIGITAL_INPUT3);
if (stato == HIGH) {
Cayenne.virtualWrite (VIRTUAL_PIN3, 0);
}
else
{
Cayenne.virtualWrite (VIRTUAL_PIN3, 1);
}
}