Voltage sensor digitalRead

I am trying to read with arduino a 12v input that is either on or off.
I got his voltage sensor
but from instructions it seems people use it with analogRead.
I'm not interested in that, i need to read it with digitalRead.
Any ideas if i can do that with this sensor, and if not, what are my alternatives?
Thanks.

A link to the sensor datasheet would help. It looks like a voltage divider, but that is just a guess. Another guess is that the division ration is 5:1. So a 12V input (gnd-Vcc) would be 2.4V on the output (- to S). Check with your meter. That is too low to be reliably recognized as a digital HIGH. Use an analog input and if the voltage is greater than, say, 2 V (410 ADC counts*) the power is on. *Assuming a 5V Arduino.

// boolean power;
if(analogRead(analogInput) > 410)
{
    power = HIGH;
}
else
{
    power = LOW;
}

As you know the input is 12V, you can use a voltage divider that gets you 4.5-5.0V on your digital pin, which should reliably read as HIGH.

If you're not sure about the actual voltage and it could be more maybe a combination of a 4.5-5V zener diode and a resistor would do the job (read the voltage over the zener). That prevents overloading your input port.

The voltage sensor as drawn indeed has the hallmarks of being a simple voltage divider (though I wouldn't know what that + input is supposed to do), so you're actually measuring the voltage.

-> ebay search : voltage sensor arduino

Description (part of)
A simple but very useful module which uses a potential divider to reduce any input voltage by a factor of 5. .....with a 0-5V analogue input range you are able to measure a voltage up to 25V. .... on principle of resistive voltage divider design, ... 5 times smaller. .....(if using 3.3V systems, input voltage not greater than 3.3Vx5=16.5V).

Divider ratio: 5:1.
Resistor Tolerance: 1%.
Max input voltage: 25V.
Resistor Value: 30K/7.5K Ohm.

Hi,
You could use an opto-coupler, which would provide isolation as well as a digital output.

Tom.. :slight_smile:

Use the 0-12v to switch a transistor on and off.
Positive here is Arduino +5v.
Connect 12v GND to Arduino GND.

petronel:
I'm not interested in that, i need to read it with digitalRead.

Let's get back to basics - why do you need to use digitalRead() and what do you expect it to tell you?

...R