I hate asking help but this time i need some coding help.
It operates on 5 V and gives a value difference from the reference voltage 2.5 Volts measured on Pin 1.
(yes ik know the imp only measures to 3.3, but ill put a R divider between it, that cuts it in half)
All works fine with this code from the Bearded professor.
local voltage = hardware.voltage();
local reading = hardware.pin1.read();
return (reading / 65535.0 ) * voltage;
server.log(" voltage Pin1 " + getPin1Voltage());
I get the 2.5 Volt measurement logging and streaming to a host, but i’am stuck on the formula to measure on PIN1 and covert it to
a readable mA / Amp .
The formula i tried was : return (reading / 65535.0 ) * voltage - 2.5 /0.185;
output pin 1 - 2.5 = 0, it should give the difference (or used amps) /0.185 (amp scaled).
Can u plz advise or set me on the right track with an example how to do it properly?
Used sensor: http://www.allegromicro.com/en/Products/Current-Sensor-ICs/Zero-To-Fifty-Amp-Integrated-Conductor-Sensor-ICs/ACS712.aspx
Taking a quick look at the transfer function, only thing I can see is that perhaps you’re missing a parenthesis. It appears that A = (Vo - 2.5) / 0.185, so maybe you want …
( (reading / 65535.0 ) * voltage - 2.5) / 0.185
Yes that was it Larry thx !
Learned another thing today
Greetings from Holland
Glad that worked out.
(I do some volunteering work at a local school, and was coincidentally helping the kids out with parentheses earlier today … guess maybe that helped me to notice it ).
I’m also thinking of measuging my AC 230Voltage device’s load with ACS712 based sensor (ACS712 5A Current Sensor Module for Arduino - Blue)
I’d like to ask about the wiring… there is VCC (5v), GND and signal. Imp can handle and give only 3.3V and the ACS712 board output (signal) voltage is VCC/2…
So, how to connect this? level converters?
… 5V for the ACS712 can be drawn from the USB port that power’s the IMP… so then the Signal is VCC/2 = ±2.5V? So PIN1 can handle this?
I’m gettin these odd result … voltage Pin1 0.18105…
The signal idles at VCC/2, but will go up to 5v for current flowing one way, and down to 0v for current flowing the other way.
The output isn’t very “stiff” (minimum Rl on the out is 4k7) so you can’t just divide it down easily.
If you just power the board up (no current being sensed), does VIOUT read as 2.5v? If so, and you still see pin1 as 0.18v, please post your code and also try a different pin.
Thanx… I’m using just your code in order to even understand how this works…
`local voltage = hardware.voltage();
local reading = hardware.pin1.read();
return (reading / 65535.0 ) * voltage;`
will do fine for me now.
So, if the current raises upto 5A (1100W), signal is 5V? But this is too much for 3.3 pins?
yes 5V is too high to apply to the imp. As you stated earlier there should be a voltage divider on the output. Perhaps 10k from the ACS712 output to your imp input pin, also connected to 20k resistor to GND. A capacitor on your signal to GND is also a good idea.
You can refer to the app notes in the datasheet - you’ll see the examples nearly all show an opamp on the output to buffer the signal and drive the ADC. Maybe you can get away without the part but for best performance it is required.
I’ve used the ACS712 and similar parts in the past…didn’t love using them but they do work if you perform a calibration. With the 10k,20k voltage divider at 0 current and 5.0V supply the level out of the divider should be 1.67 volt but this may not be perfect.
thanx… ok… so 10k for singal and 20k for GND… What kind of capacitor would you use between signal and gnd…
As I noted, I don’t think you can just use a resistor divider here because the output of hte ACS isn’t so strong. A buffer op-amp THEN a divider would work fine, though.
hmm… There are level converter chips… Will they do?
No, level converters are for binary signals - you need to effectively multiply the signal by (3.3/5.0). You can do this (as it’s <1) with resistors, but as the output power of the ACS712 is limited, you can’t use very big resistors.
Try this: output of the ACS712 to a 12k resistor, to the imp pin, then 22k from the imp pin to GND.
This gives you a ratio of (22 / (22+12))=0.647, so 5.0v at the input would look like 3.23v at the imp. I’d put a 10nF capacitor in parallel with the 22k resistor too.
marvellous… sir, thank you… 10 uF capasitor between signal and GND?
10uF is too big …most likely. You need to look at the topic of RC filters, time constants, corner frequencies and such. start with a small one as Hugo suggested (10nF 0.01uF) and if the signal is too noisy move up from there. however, 10uF would only be OK if you wanted to check a relatively slow moving DC signal.
10nF not 10uF, across the 22k resistor as I said. 10uF would take forever to stabilize.