Detect voltage over input cable

Hello forum,

I'm quite new when it comes to electronics and stuff, thats why I try my question here.

We have an electric door opener which is being triggered from a door phone system. Unfortunately this system doesn't notify the person at the door whether the door is unlocked or not.

I had the great idea to put a RFID module outside the door so the door can also be opened with key tags. So, why not making use of the Arduino (while it's there) to also attach some kind of buzzer.

This is basically what I want;
One there comes voltage over the cable which goes to the door opener (which is 12V) I want Arduino to trigger anything, like being able to turn on a LED, make a sound, things like that.

Is there a way to detect voltage from the input and have a variable inside Arduino such as "doorUnlocked = true/false"?

Thanks in advance

Yes. You make a potential divider with two resistor's to drop the voltage to no more than 5V. Then you put that into one of the digital inputs and read a high to low with the digital read function. You can put the result into a variable to control switching of other things.

Grumpy_Mike:
Yes. You make a potential divider with two resistor's to drop the voltage to no more than 5V. Then you put that into one of the digital inputs and read a high to low with the digital read function. You can put the result into a variable to control switching of other things.

Thanks Mike, you're always a good help here on the Arduino forums. Never thought it would be this easy, works like a charm :slight_smile:

For now I've added 2 times a 1K Ohm resitor, inbetween those resitors I have my cable connecting to A0. The output is always 5 (copied the voltage calculator from Arduino tutorials) so that seems to be good. Is it a wise idea to add higher resitors or should the 1K ones be enough?

One there comes voltage over the cable which goes to the door opener (which is 12V)

If you have 12V then two 1K resistors will only cut this down to 6V. The fact you see 5V is that it is connected to an arduino pin and the protection diodes are kicking in. This is not a good idea.

If you are using an analogue input then you should use a higher resistor from the input to the 12V. A 1K4 resistor will do, or higher.

Grumpy_Mike:

One there comes voltage over the cable which goes to the door opener (which is 12V)

If you have 12V then two 1K resistors will only cut this down to 6V. The fact you see 5V is that it is connected to an arduino pin and the protection diodes are kicking in. This is not a good idea.

If you are using an analogue input then you should use a higher resistor from the input to the 12V. A 1K4 resistor will do, or higher.

When I use a 10K resistor I still get a 5.0v value in my console. Is this correct?

Sounds like it is not, a 1K pulling down to ground and a 10K to 12V should give you 1V at the arduino input.

Are you sure you have connected the ground of your arduino to the ground of your 12V source?

You must divide your voltage to be within 0-5V range which is what your Arduino is capable of detecting.

Your input is 12V, if you divide it with a 2:1 ratio you get 12/3 = 4V which is within your range.

To achieve such voltage division you need to put two resistors in series with one being double value than the other: the absolute value is not important for the voltage, just their ratio is.

So using a 2k and a 1k resistor in series you can get a readable voltage.

The resistor values though play a role regarding the current and the dissipated power: 12V running through a 3k resistor (resistors in series sum up) will absorb 4mA and need to dissipate 48mW. In general this should be ok.

The wiring is like

12V ------ 2kR ---+--- 1kR ------ GND
                  |
                  |
             ANALOG INPUT

Please do not forget you need to have your Arduino share the same GND as the other circuit for this to work.

To get additional help please post your circuit and code.

Is the door solenoid DC or AC?

Grumpy_Mike:
Sounds like it is not, a 1K pulling down to ground and a 10K to 12V should give you 1V at the arduino input.

Are you sure you have connected the ground of your arduino to the ground of your 12V source?

Yes I did, first I didnt and when no voltage was applied it did still read some random values from time to time. once I added the GND it was stable at 0.00 and 5.00 when I applied my 12v source with a 10K resistor.

rlogiacco:
You must divide your voltage to be within 0-5V range which is what your Arduino is capable of detecting.

Your input is 12V, if you divide it with a 2:1 ratio you get 12/3 = 4V which is within your range.

To achieve such voltage division you need to put two resistors in series with one being double value than the other: the absolute value is not important for the voltage, just their ratio is.

So using a 2k and a 1k resistor in series you can get a readable voltage.

The resistor values though play a role regarding the current and the dissipated power: 12V running through a 3k resistor (resistors in series sum up) will absorb 4mA and need to dissipate 48mW. In general this should be ok.

The wiring is like

12V ------ 2kR ---+--- 1kR ------ GND

|
                  |
            ANALOG INPUT




Please do not forget you need to have your Arduino share the same GND as the other circuit for this to work.

To get additional help please post your circuit and code.

Is it needed to have it at a 2:1 ratio? I dont need to know the actual voltage, just need to know whether voltage is running over the cable or not :slight_smile:

Paul__B:
Is the door solenoid DC or AC?

I tried it with my PSU from my PC for now, so thats a 12V DC. Im not sure about the door itself, although I guess its DC as well. Does AC or DC matter in this case?

PaulE:

Grumpy_Mike:
Are you sure you have connected the ground of your Arduino to the ground of your 12V source?

Yes I did, first I didn't and when no voltage was applied it did still read some random values from time to time. once I added the GND it was stable at 0.00 and 5.00 when I applied my 12v source with a 10K resistor.

Basic rules of electricity - you need a circuit - a complete loop for the current to flow. Without a ground connection you have an antenna instead.

PaulE:
Is it needed to have it at a 2:1 ratio? I don't need to know the actual voltage, just need to know whether voltage is running over the cable or not :slight_smile:

Then you do not need an analog input. As long as the resultant voltage is well over the threshold of half the supply voltage to the Arduino, it will register as HIGH. But you may need de-bouncing. In fact, a 47k resistor and a diode to clamp the voltage above 5V would do the job.

PaulE:
I tried it with my PSU from my PC for now, so that's a 12V DC. I'm not sure about the door itself, although I guess its DC as well. Does AC or DC matter in this case?

It certainly does. You need to know what the original system used. An AC solenoid will work on DC, but will draw a much heavier current than on AC which may overload the power supply or if left on for too long, may burn out the solenoid. And a DC solenoid may not work properly on AC at all.

That is a bit of a puzzle, as I said with 10K to the 12V and 1K to the ground you should not be getting 5V.

Can you photograph your resistors so we can see if you have the right values.

Grumpy_Mike:
That is a bit of a puzzle, as I said with 10K to the 12V and 1K to the ground you should not be getting 5V.

Can you photograph your resistors so we can see if you have the right values.

Now that I think of it, wouldn't adding a 10K resistor change the formula to calculate the voltage? I was using the following code: http://arduino.cc/en/Tutorial/ReadAnalogVoltage
On my research to voltage dividers I found the formula: vout = (R2 / (R1 + R2)) * vin. The code I use just expects the max input voltage to be 5.

I did nothing more than wiring it up the folling way:
12V PSU input to my breadboard. From the breadboard I put a 10K Ohm resistor on the + rail. Then my cable which goes to the analog pin, followed by another 10K Ohm resistor which goes to the ground of the PSU. On the same ground rail I joined up the GND of the Arduino. This is the way a voltage divider works, right?

I'm not able to photograph the resistors right now, but im 100% they are 10K ones :slight_smile:

Paul__B:
Then you do not need an analog input. As long as the resultant voltage is well over the threshold of half the supply voltage to the Arduino, it will register as HIGH. But you may need de-bouncing. In fact, a 47k resistor and a diode to clamp the voltage above 5V would do the job.

I have no idea what you just said there, is there any change you could show how the wiring would look?

I'll try to make it simple: by using two 10k resistors you are dividing your 12 volts equally, which means you get 6V coming into your Arduino. This is in excess of your Arduino limit of 5V, which means the exceeding 1V will be "cut out" by the Arduino internal circuitry and dissipated in the form of heat.
To avoid such unnecessary stress to the Arduino I suggested to divide the input 12V in a non equal ratio to obtain 4V on your sensing level.

If all you want to do is to detect when the voltage is above a certain level you can use digitalRead: it returns HIGH if the voltage is above 2V, LOW if it is below 0.8V. As you can see there's a range (0.8,2) which is undetermined so you must stay away from that "grey area".

Paul__B is suggesting another way to cap the maximum voltage received by the Arduino: once divided into 6V he is suggesting to cut out the excess before it reaches the Arduino by using a diode (I would go for a zener diode in this case), but I believe it a little more complex that using an unequal divider.

Putting it simpler, if you have another 10k resistor you can use the following:

12V --- 10kR --- 10kR -+- 10kR --- GND
                       |
                       |
                    ARDUINO

The 4V at the joint point where your arduino is connected will put you outside of the grey area (4V > 2V) and when the 12V input drops to 0V you'll be again outside of the grey area (0V < 0.8V): perfect for digitalRead and good for an interrupt.

De-bouncing is a topic on it's own and I'll not try to cover it here: better for you to read some real documentation

Forgot to add the link...

Thanks rlogiacco, I didn't know that depending on the ratio of the resistors the voltage would change. I thought that adding a 10K resistor would lower the voltage by itself already, like I said I'm very new to electronics and stuff haha.

Would the voltage divider be a good thing to check whether there is a voltage on the input cable, or isn't this an efficient way of doing this check? Like I did mention before, all I need is an indication whether there is voltage on the cable or not, the voltage number itself isn't really necessary for me :slight_smile:

rlogiacco:
Paul__B is suggesting ... cut out the excess before it reaches the Arduino by using a diode (I would go for a zener diode in this case), but I believe it a little more complex that using an unequal divider.

No, it's dead easy. Borrowing your graphics:

12V---47k---+---|>|--- Vcc
            |
            |
         Arduino

If you want to be fussy, use a Schottky diode (as I pointed out elsewhere - somewhere).

Ok, I did misunderstand your suggestion (my bad) as I thought you were suggesting a different configuration. I honestly though don't understand how this works :roll_eyes:

PaulE:
Thanks rlogiacco, I didn't know that depending on the ratio of the resistors the voltage would change.

Well, this is exactly what I said in my first reply: it's not the absolute value which influences the voltage but the ratio. The absolute value influences the current and the power dissipation.

PaulE:
Would the voltage divider be a good thing to check whether there is a voltage on the input cable, or isn't this an efficient way of doing this check?

The "efficient" term can have a lot of meanings... but I would say yes. To perform your voltage check using 3 10k resistors you are wasting as heat 4.8mW of your 12V DC source or, if you prefer, you are absorbing 0.4mA of current... If you believe you can afford such expense...

If you want you can even reduce such energy waste by disconnecting the sensing circuit when it's not in use, at the expense of additional circuitry.

PaulE:
Like I did mention before, all I need is an indication whether there is voltage on the cable or not, the voltage number itself isn't really necessary for me :slight_smile:

That's why I suggested you to use a digital pin and the digitalRead function: digitalRead will be more efficient (in terms of computation time and current consumption) of the analog reading and will return HIGH if the voltage on the sensing pin is above 2V, LOW if it is below 0.8V.
This way you are not aware of the voltage on the line, you are just checking if the voltage is above a certain limit or below another limit. Beware though not to fall in the in-between range as that is an undefined voltage band and your reading will not be reliable.

rlogiacco:
I honestly though don't understand how this works

It works perfectly well!.

If the source voltage is zero, then the input to the Arduino is zero; LOW. The ATmega chip has an extremely high input impedance (certainly when used for digital inputs) so the 47k is no limitation. If the source voltage is 12V, or indeed anything above 5, then the diode clamps it to a little above 5V which is within the tolerance of the ATmega chip. In fact the ATmega chip has internal clamping diodes which are permitted to tolerate up to a milliamp, so the 150µA which the 47k would pass would be tolerated even without the external clamping diode but it is just a good idea to add it.

If in fact, the source is AC and goes below zero, it would be appropriate to add a second clamping diode to ground.

followed by another 10K Ohm resistor which goes to the ground of the PSU.

No that second resistor should be smaller.
As it is you are getting 6V, but measuring anything over 5V will still read 5V.

I have been saying this for quite a few replies now, please re read what I said.