Need help measuring voltage (10 V)

TL;DR: How can I detect a voltage change from 5V to 10V?

I am hoping to retrofit some door/window/motion sensors from an old security system. Using a multimeter I’ve deduced that when “active” the voltage between the wires of each sensor changes from 5 V to 10 V. In reading the docs, it appears that I can use the analog input pins A0-A7 to read voltage, but the voltage on those pins must be < 3.3V.
a. Is this correct?
b. Any ideas how I can make this project work?

There are 4 different “things” (4 pairs = 8 wires; some might be shared, that’s moot at this point) I’d like to sense, and I’d like to keep the cost as low as possible.

Thanks!

A voltage divider should do the trick :slight_smile:

Thanks! Would this be 4 separate voltage dividers probably then, correct?

Edit: https://learn.sparkfun.com/tutorials/voltage-dividers
Cool!

@Moors7 hopefully you can help me thru my next question with as much ease!

Here is (I think) the circuit diagram:


When the switch is Open V_AB = 10V. When the switch is Closed V_AB is 5V. (Where A = Node 1, B = Node B, see next pic.)

So here’s the circuit I then made to try voltage dividing:

(Sorry for the picture quality… I need to find a free circuit site that doesn’t block me out randomly.)
This circuit changes the V_AB readings and doesn’t produce helpful output between R4 or R5 etc.

Any ideas? Thanks!

@jschwalbe I prefer to use just the INA219 sensor to measure voltage up to 26v and current if you want.

2 Likes

I think this is what you want.

I ended up adding a second resistor after R1 and measuring the voltage between R1 and the new resistor. Turns out it’s either 0 or 3.33 V which is perfect for my application. I don’t think it screws up the alarm system (which I’m not using anyhow).

But now to figure out how to use this programmatically(!). The value for the voltage seems to be jumping all over the place, and I can’t make out why.

I have the wire connected to A0 and nothing else is connected except the mini-USB powering the device.
My code:

int analogPin = A0;           
int val = 0;                   

void setup() {}

void loop()
{
  val = analogRead(analogPin);  // read the analogPin
  Spark.publish("Voltage", String(val));
  delay(2000);
}

And some example output from the terminal. (TL;DR: the “voltage” variable is jumping all over the place.)

event: Voltage
data: {"data":"110","ttl":60,"published_at":"2017-07-24T02:45:20.487Z","coreid":"54ff72066672524841241267"}

event: Voltage
data: {"data":"3831","ttl":60,"published_at":"2017-07-24T02:45:22.493Z","coreid":"54ff72066672524841241267"}

event: Voltage
data: {"data":"2125","ttl":60,"published_at":"2017-07-24T02:45:24.499Z","coreid":"54ff72066672524841241267"}

event: Voltage
data: {"data":"140","ttl":60,"published_at":"2017-07-24T02:45:26.503Z","coreid":"54ff72066672524841241267"}

event: Voltage
data: {"data":"3882","ttl":60,"published_at":"2017-07-24T02:45:28.512Z","coreid":"54ff72066672524841241267"}

event: Voltage
data: {"data":"2042","ttl":60,"published_at":"2017-07-24T02:45:30.514Z","coreid":"54ff72066672524841241267"}

event: Voltage
data: {"data":"91","ttl":60,"published_at":"2017-07-24T02:45:32.518Z","coreid":"54ff72066672524841241267"}

Now I verified that the voltage isn’t infact jumping all over the place with my multimeter. I physically touched A0 and GND and it is only changing between something like 1.67 and 1.68 (or something similar) with my multimeter set to VDC.

What have I done wrong? Many thanks!

How clean (free of noise and ripple) is your signal?
The ADCs are fast and having a 50/60Hz hum on the signal would explain the volatile readings, while a slow/damping DMM wouldn’t respond to that.

I concur the results suggest that the voltage could be in a wave, notice how the first result is around 100 then its 1 above 3800 and then above 2000 than around 100 and than over 3800, over 2000 and back to around 100.
Sure the data set is a small one, but if that pattern continues it would suggest waveform in the voltage and of course a DC voltage measurement on a multimeter wouldn’t pick that up if the frequency is high enough.
You need an oscilloscope to pick it up to know for sure.
You may need to add some caps to the circuit to smooth the power out.

Wouldn’t you better of using a zener diode of the right voltage threshold and wire them to digital pins? You would still need a the right value resister to drop the voltage but a divider wouldn’t be necessary

Thanks all for your help and thought-provoking questions. It’s a lot for a newbie to digest.

I certainly don’t have an oscilloscope (though wouldn’t mind one), so I can’t answer most of the questions. Here are a few thoughts I’d like to try, but anxious that I might break my Spark Core.

  1. Can I take a wire directly from the alarm panel’s GND and plug it into the Core’s GND?
    (1.5.) If that would/might cause damage, maybe I could plug the panel’s GND into A1 and take readings of both A0 and A1 and calculate a difference. My concern is that it’s not measuring against the same ground which may cause interference/improper readings.
  2. When I get a chance, I’m going to try taking readings from D0. But when does it go from 0->1? I assume there’s some tolerance.
  3. I’m going to try taking readings from A0 without anything connected to see if the output is any different.

Yes, you absolutely need common GND to do proper voltage readings, but whether it’s safe or not to connect the two GND levels depends on the actual setup - so it’s up to your discretion not to cause harm (=disclaimer :sunglasses:).
Generally speaking with a 10VDC supply for your sensors connecting GND to the Core’s GND is safe and common way to do it.

About digital threshold levels you should consult the STM32F1xx (for Core) datasheet, but as a rule of thumb you can assume below 33% Vcc digital pins should give you a reliable LOW and above 66% a reliable HIGH (actually the gap is a bit less than 1/3).

You won’t get any valid readings from a floating A0 pin.

@jschwalbe, can you post a picture of your security system “innards”? What type of sensors does it use - Motion? Windows/Doors?

Will do - when I get home from work.

Interestingly enough, before I left for work I took the wire out of A0 and plugged it into A1 and made appropriate changes to the code, and now the readings are holding VERY steady… 3904, 3907, 2795, 2926, 2770, 3895... Once the wife returns from grocery shopping I’ll have her open the door to see if that indeed changes the value as I suspect it will.

I’ll get a pic up when I return home.

Question regarding the max voltage on A_ inputs and D_ inputs: is the max input voltage to mean “anything above 3.3 V (such as 10 V) will fry the device” or “anything above 3.3 V may work but isn’t guaranteed”? Because if I can use the Core to safely detect the difference from 10V to 0V (and not care about anything in between), then a lot of these shannagins might be avoidable. I ask before just trying because I don’t want to break my shiny new toy! :smile:

@jschwalbe, on a pin configured as analog input, anything above 3.3v will damage the GPIO input or possibly your entire device, guaranteed. When a pin is configured as a digital input with NO pull-up or pull-down, anything above 5v will damage the GPIO input.

1 Like

Food for thought…how about using an opto-isolator to electrically isolate the Particle device from the security system? Some amount of capacitance may still be required in order to smooth out the signal being read, but at least this should eliminate some of the challenges/risks, I believe.

[update] For instance, I looked at controleverything.com and found a 4 channel optical isolated digital input board. You may still need to introduce a couple of resistors on each input to make a voltage divider to get the “low” voltage below the 3V threshold. I realize this may not be as “low cost” as desired, but avoiding frying one Photon would make this fairly appealing, I would think. The folks at Control Everything are also very helpful if you have any questions.

1 Like

Try this. It will clamp the input down to 3v3 if you go over that or up to 0v if you put in the reverse. And give you a range of 0 - 10v.

You can also use this 3 input Voltage / Current sensor to read 3 input sources up to 26v.

I think I can mark this as solved. The answer is the best one for me, but it doesn’t answer the original question… read lots of the other awesome replies to get at that if needed.

As always, the simplest way tends to be the best. Since the door sensor is just a pressure switch (open door = open circuit), I decided to stop messing around with the stupid alarm panel since I’m not really using it anyways.

So I just grabbed the two wires (to_door and from_door) and plugged them into ports on the Core such that to_door is digitalWrite’ing HIGH and from_door is set to digitalRead. Door closed = HIGH, Door open = LOW. (I probably should be using a pull resistor, but it seems to be working fine without one.)

Some day down the road I may figure out a way to make it work with the built in alarm panels, but right now that’s pretty low on the list of priorities.

This has been my first go-round with the Particle community, and I want to thank everyone for assisting me in this project :smile: you all rock. I look forward to doing more fun stuff to come. Once I get it all connected to homeassistant, I’ll post a write up somewhere.

3 Likes