danjperron
Posts: 3261
Joined: Thu Dec 27, 2012 4:05 am

Fan174
Posts: 171
Joined: Tue Mar 20, 2018 6:10 am

danjperron wrote:
Thu Sep 13, 2018 10:57 am
Yes

This is reading for IN0. Its look perfect.

Code: Select all

0:19278 1.205V 0.0A	1: 4365	2: 4401	3: 4350
0:19366 1.210V 0.2A	1: 4373	2: 4398	3: 4409
0:19361 1.210V 0.2A	1: 4393	2: 4347	3: 4423
0:19372 1.211V 0.2A	1: 4395	2: 4378	3: 4402
0:19375 1.211V 0.2A	1: 4393	2: 4407	3: 4376
0:19379 1.211V 0.2A	1: 4357	2: 4401	3: 4355
0:19365 1.210V 0.2A	1: 4352	2: 4399	3: 4369
0:19367 1.210V 0.2A	1: 4401	2: 4392	3: 4428
0:19357 1.210V 0.2A	1: 4399	2: 4363	3: 4421
0:19270 1.204V 0.0A	1: 4393	2: 4355	3: 4422
0:19359 1.210V 0.2A	1: 4397	2: 4346	3: 4423
0:19283 1.205V 0.0A	1: 4397	2: 4352	3: 4421
0:19363 1.210V 0.2A	1: 4397	2: 4359	3: 4413
0:19249 1.203V -0.0A	1: 4394	2: 4375	3: 4419
0:19364 1.210V 0.2A	1: 4393	2: 4395	3: 4392
0:19364 1.210V 0.2A	1: 4382	2: 4404	3: 4371
0:19373 1.211V 0.2A	1: 4355	2: 4402	3: 4353
0:19372 1.211V 0.2A	1: 4363	2: 4398	3: 4390
0:19349 1.209V 0.2A	1: 4401	2: 4388	3: 4423

danjperron
Posts: 3261
Joined: Thu Dec 27, 2012 4:05 am

Perfect.

I did an average of your A/D IN0 results and it is 1.209V.

You should change the ACS712VoltageOffset in the script to

ACS712VoltageOffset = 1.209

Averaging sampling will also help but not for the 5V fluctuation.
If I assume that your resistors divider is perfect your VCC is not 5V but (1.209 * 4) = 4.84V.

You will notice that your A/D fluctuate. The main reason is the 5V.

https://www.allegromicro.com/~/media/fi ... sheet.ashx
On the datasheet , page 4, Zero current output voltage is VCC * 0.5. This mean that if your VCC is noisy the output will be also. this is one of the reason you have fluctuation.

If you want to reduce the noise use a LM7805 with specified capacitor for your 5V instead of the RPi 5V. Your signal will be less noisier and the 5V will more constant using a linear regulator then a 5V from an adapter.
The only draw back is that you will need an external power supply from 9V to 12V and this 5V is only for the ACS712.

Fan174
Posts: 171
Joined: Tue Mar 20, 2018 6:10 am

danjperron wrote:
Thu Sep 13, 2018 1:08 pm
Perfect.

I have two doubts
1. If I want to measure 1 A to 30 A. Do I need any other part in circuit to measure 30 A DC current ?
I don't think because I have seen some arduino based circuit they don't use any extra parts

2. sensor can sense AC or DC current so if i replace DC battery with AC main Is that circuit capable to measure AC current ?
I think circuit can measure both AC and DC current I don't need any extra part to measure AC current

Please correct me if I am wrong somewhere ?

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Fan174 wrote:
Thu Sep 13, 2018 1:26 pm
2. sensor can sense AC or DC current so if i replace DC battery with AC main Is that circuit capable to measure AC current ?
I think circuit can measure both AC and DC current I don't need any extra part to measure AC current
Before I answer that question. What is the mains voltage that you are using? Because, this is essential to answer this question!

danjperron
Posts: 3261
Joined: Thu Dec 27, 2012 4:05 am

There is a method to counteract the 5V from the adapter if you don't want to use an external 5V.

1 - Use IN1 to check the 5V real Voltage. Make a resistor divider like 10K/4.7K to reduce the 5V to a readable Voltage for the ads1115.
2- Do average readings of IN0 (acs712) and IN1 (5V) in alternance.
3- From IN1 get the real Voltage of VCC using a conversion function. if you are using 10K/4.7K the conversion should be close to

- resistor divider formula
Vout = Vin * R1 / (R1+R2) => Vin = Vout *(R1+R2)/R1

Vout = IN1 voltage value
R1 = 4.7K ohm
R2 = 10K ohm

then VCC = (IN1 voltage) * (14700/4700)

Code: Select all

def ConversionToVCCVolt(a2dValue):
return  ConversionToVolt(a2dValue)  * 3.1276
4- From the average IN0 get the current but using the VCC voltage found at (3) divide by 4 for ACS712VoltageOffset

Code: Select all

def ConversionFromVoltToAmp(value, VoltageOffset):
return((value - VoltageOffset ) * 1000.0 / ACS712Slope_mVPerA)

def ConversionToAmp( IN0Value,IN1Value)
return ConversionFromVoltToAmp(ConversionToVolt(IN0Value), ConversionToVCCVolt(IN1Value)/4.0)

Et voila! less fluctuations and if VCC changes it will auto correct. (Vcc will change because it is from an adapter. Temperature, power grid Voltage and load from the Rpi will change VCC.

N.B. there is still a problem with the 66mv per A that will need to be updated to take care of 5V change. (theorical 5V / real 5V detected). But first thing first.

And now is up to you to modify your code. I think that I give you a lot of hint on how to do it!

Fan174
Posts: 171
Joined: Tue Mar 20, 2018 6:10 am

Brandon92 wrote:
Thu Sep 13, 2018 1:52 pm
Fan174 wrote:
Thu Sep 13, 2018 1:26 pm
2. sensor can sense AC or DC current so if i replace DC battery with AC main Is that circuit capable to measure AC current ?
I think circuit can measure both AC and DC current I don't need any extra part to measure AC current
Before I answer that question. What is the mains voltage that you are using? Because, this is essential to answer this question!
main supply is 240v - 230 V

I am asking this question because I have seen in several link they are measuring AC current using arduino and acs712 http://microcontrollerslab.com/ac-curre ... 2-arduino/ so I think we can also do with pi

danjperron
Posts: 3261
Joined: Thu Dec 27, 2012 4:05 am

I have two doubts
1. If I want to measure 1 A to 30 A. Do I need any other part in circuit to measure 30 A DC current ?
I don't think because I have seen some arduino based circuit they don't use any extra parts
No just change the resistor divider. This will of course change the resolution.

2. sensor can sense AC or DC current so if i replace DC battery with AC main Is that circuit capable to measure AC current ?
I think circuit can measure both AC and DC current I don't need any extra part to measure AC current
But for AC you will need to get a lot of points inside the (50Hz or 60Hz). The average method won't work here but you should be able to get enough point to calculate the RMS Voltage and the peak voltage.
FFT or bayesian algorithm should be use there to reconstruct the sinewave. But at 860 samples per second you should be OK without those elaborate math. The are problematic anyway because you need real time kernel.

Another simple method is to rectify the wave using Opam(operational amplifier) and get the peak. then the AC Current is the peak Current divide by square of 2 (for sinus wave).
Last edited by danjperron on Thu Sep 13, 2018 2:15 pm, edited 1 time in total.

davidcoton
Posts: 3612
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Fan174 wrote:
Thu Sep 13, 2018 1:26 pm
1. If I want to measure 1 A to 30 A. Do I need any other part in circuit to measure 30 A DC current ?
I don't think because I have seen some arduino based circuit they don't use any extra parts

2. sensor can sense AC or DC current so if i replace DC battery with AC main Is that circuit capable to measure AC current ?
I think circuit can measure both AC and DC current I don't need any extra part to measure AC current
1. You need thick wires for 30A.
• you will have to convert to RMS, using additiional hardware; or
• you will have to take readings fast enough to avoid aliasing, then either convert to RMS or use the instantaneous values (processing them at you sampling rate)
You need to be aware of your local electrical regulations when connecting to mains electricity. You need to be aware of the risks of electrocution and fire. If in doubt (and unless you have professional experience, you should be in doubt) please do not work the mains electricity. On the plus side, the ACS712 can do the job with appropriate design and use of secondary safety. Whether you can build a device that maintains the same degree of safety I don't know. At the very least you should get a professional electrician to check your design before you build it, and check your construction before you connect it to the mains.

Edited to emphasise the need for proper design of the safety aspects of the system. See following posts.
Last edited by davidcoton on Thu Sep 13, 2018 9:58 pm, edited 1 time in total.
Signature retired

Fan174
Posts: 171
Joined: Tue Mar 20, 2018 6:10 am

danjperron wrote:
Thu Sep 13, 2018 1:59 pm
There is a method to counteract the 5V from the adapter if you don't want to use an external 5V.

And now is up to you to modify your code. I think that I give you a lot of hint on how to do it!
Yes you helped me a lot. I can take 5v DC supply from external source I have development board that give 5v Dc there 7085 ic

But I was testing with no load and now I want to test with load so I have 5 ohms resistor and 2A Adapter so Can I test with that load

Fan174
Posts: 171
Joined: Tue Mar 20, 2018 6:10 am

danjperron wrote:
Thu Sep 13, 2018 2:13 pm

No just change the resistor divider. This will of course change the resolution.
so I have to use 10K/4.7K circuit for both AC and DC anyway I just want to measure DC first

Can I measure DC with 5 ohms just for testing. I just wanted to make sure that program is taking the reading

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

davidcoton wrote:
Thu Sep 13, 2018 2:14 pm
--
On the plus side, the ACS712 can do the job.
--
Well, I disagree with this answer. This device is not fully save* to use it in this case. And I will give a detailed explanation in a couple of hours, why (I think) this is the case.

danjperron
Posts: 3261
Joined: Thu Dec 27, 2012 4:05 am

[quoteBut I was testing with no load and now I want to test with load so I have 5 ohms resistor and 2A Adapter so Can I test with that load][/quote]

yes it should work.

danjperron
Posts: 3261
Joined: Thu Dec 27, 2012 4:05 am

I'm kind of agree with Brandon92.

if you are using the ACS712 30A adapter gadget from dx.com or similar company, the connector is not really made for 30A and the copper wire are a little bit to small.

Also there is no way to screw the board in a secure fashion! no mounting hole. I will expect a bigger PCB with mounting hole and some cuts into the pcb where the power trace are, to prevent short by burning material if the device blew.

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

As propmist my explanation about the safety with the ACP712:

To say it a bit bluntly:
At the beginning of the topic I expected that you would use this to measure the mains current, and were we are . And to give you some (background) information, why you should not use this sensor. In this topic I had the feeling that you doesn't know much about electronics. And especially at this level (design you own product). As a example, you did't know how to use a voltage divider. What is part of the basics.
And because of this, you would probably touch the electronics when you want to measure the AC load. Because, you think you are save. And this is not true, for the reasons I going to tell and what danjperron mention.

Explanation:
As I stated you will touch the design what you are going to make when it is live. For example to add a simple buttom, or you going to touch the USB connector, or the attached PC, the power supply itself, ect.

If you will read the datasheet thoroughly, you find this characteristic: "Working Voltage for Reinforced Isolation". And in this case this is rated at 184 VDC, or +/- 130VRMS. And that is lower than your requirement: 240VRMS.

So, what does Working Voltage for Reinforced Isolation means. It is your safety barrier that protect you or others again electric shocks. And in your case this is necessarily. And yes, the basic isolation is rated for your voltage, but it will not protect you from getting shocks, and according to the safety standard, you need to add an extra insulation barrier if humans can touch it.

Conclusion
For you own safety and form others, don't use this sensor to measure the ac mains current.

Here you can read it for yourself:
What is Reinforced Isolation? -TI
High-voltage reinforced isolation - TI
Reinforced Isolation Passes the Test

danjperron
Posts: 3261
Joined: Thu Dec 27, 2012 4:05 am

Brandon92 is completely correct. Too much High Voltage, risk of electrocution and fire.

I would'nt use a Raspberry Pi with all that power and wire near it. You are asking for a potential hazard!

B.T.W. This is just the basic specification of one part. In reality you have to consider the full instrument!

To get around that isolation problem there is solution by adding another isolation level. Use a small microprocessor to read the acs712.
This microprocessor could be isolated way more than the acs712 does and could transmit data via optical coupler. The signal could even be calculated via the processor by itself.
A arduino mini with DC/DC or AC/DC power isolator, will do the trick and the only connection will be a opto coupler sending the data digitally to your Raspberry Pi.
Or you could use an esp8266 to send the data by wifi with udp packet!

This is like most of the power meter on the market . They use optocoupler , or isolation transformer, to separate High Voltage to the external user service signal.

The small Arduino or esp8266 is a way better approach.
Everything in a small box and way cheaper to replace.
Also the Arduino could run at a constant sampling rate . The Raspberry Pi won't be able to give you constant sampling rate then this is harder to calculate peak and RMS current.

davidcoton
Posts: 3612
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Brandon92 wrote:
Thu Sep 13, 2018 2:40 pm
davidcoton wrote:
Thu Sep 13, 2018 2:14 pm
--
On the plus side, the ACS712 can do the job.
--
Well, I disagree with this answer. This device is not fully save* to use it in this case. And I will give a detailed explanation in a couple of hours, why (I think) this is the case.
I will re-phrase -- On the plus side, the ACS712 can do the job with appropriate design and use of secondary safety.

I think your concerns are fully justified. I do not think the OP is sufficiently experienced to consider designing any mains voltage equipment. My comment was purely about the ACS712 chip, without any consideration of the board it is mounted on. According to the spec the Hall Effect sensor has adequate isolation even for 240V high side use -- but as you say the carrier board must be properly designed to maintain that isolation. If I were designing something to measure 30A mains (using the current chip, not ACS712 which is end of life), I would consider measuring the return current (in the UK usually but not always at near earth potential), although that can introduce more dangers if the path through the Hall Effect sensor fails when non-functional equipment is at mains potential. I would also certainly consider "belt and braces" safety by opto-isolating the Pi interface and putting sacrificial TVS (or something) on the power supply connection. Of course the best protection will come from proper use of RCDs on the circuit under test -- this could be built in the the measurement input as well.

I think your concern about the reinforced isolation voltage rating is overstated. It is measured from pins to frame, not input to output. The chip package itself will not be the only insulation for the product (it can't be, there are external connections) so there must be an enclosing isolated (or earthed) box. The relevant safety isolation is the pins 1-4 to pins 5-8 value, which is adequate. Or have I missing something here? If you require fault tolerant isolation that continues to protect in the event of ACS712 failure, it will require opto-isolation of all signals and protection/isolation of the power supply.

To summarise, the design of mains voltage equipment is tricky, and working with mains voltage requires both knowledge and experience to stay safe. There are dangers of death by electrocution or by fire. Most people should not consider it, but the ACS712 chip itself is suitable for those with the necessary skill set.

Source: Allegro ACS712 datasheet
Signature retired

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

davidcoton wrote:
Thu Sep 13, 2018 9:55 pm
I think your concern about the reinforced isolation voltage rating is overstated. It is measured from pins to frame, not input to output. The chip package itself will not be the only insulation for the product (it can't be, there are external connections) so there must be an enclosing isolated (or earthed) box. The relevant safety isolation is the pins 1-4 to pins 5-8 value, which is adequate. Or have I missing something here? If you require fault tolerant isolation that continues to protect in the event of ACS712 failure, it will require opto-isolation of all signals and protection/isolation of the power supply.

To summarise, the design of mains voltage equipment is tricky, and working with mains voltage requires both knowledge and experience to stay safe. There are dangers of death by electrocution or by fire. Most people should not consider it, but the ACS712 chip itself is suitable for those with the necessary skill set.

Source: Allegro ACS712 datasheet
Well, in this case the clearance between the left side and the right side of the chip are also the part of the issue, see the link above the picture.
However the working voltage means, the voltage potential between pin 1-4 and 5-8, that the isolation barrier can handel constant and in a "save" way. And when a human can touch the low voltage side, for example a usb port, you need to take the value of "Working Voltage for Reinforced Isolation".

This is also verified by the company itself:
What is the difference between the basic and reinforced isolation voltage ratings?

At a side note, if you want to power the ACS712, or whatever, from a DC/DC converter from the same power as the product itself. The power supply need to have also the proportionally isolation. For example, take a look at the ADuM6000. page 8 and 15.

I hope by story is a bit clear, it a bit late now

But, I agree with you that the ACS712 (or a brother of him) can do the bushiness, and like you say. You need to have the necessary skill set. What (unfortunately) the OP doesn't have. And better save than sorry in this case.
And it's not, just add a current sense sensor to the wire and I'm done.

davidcoton
Posts: 3612
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

We agree in the end. As you say, better safe than sorry.

It will be better to buy a clamp meter with a digital output, that takes care of all the safety issues. A quick Google found several with USB (which may or may not be easy to use with a Pi, or even any other Linux system), but I can't make any particular recommendation nor speak for their safety and build quality. Cost is less than your wages for the time it takes to build from scratch. Do beware of very cheap versions which may not be built to the necessary standards.

Keep the Pi project but only use it for low voltages.
Signature retired

Fan174
Posts: 171
Joined: Tue Mar 20, 2018 6:10 am

davidcoton wrote:
Thu Sep 13, 2018 2:14 pm
safety. Whether you can build a device that maintains the same degree of safety I don't know. At the very least you should get a professional electrician to check your design before you build it, and check your construction before you connect it to the mains.

Edited to emphasise the need for proper design of the safety aspects of the system. See following posts.
I know how precious is life I would not like to die without the marriage at least. I asked question for AC because just for clarification. I won't attempt to use AC
anyway I just want to measure DC current only

I did the experiment with 5 ohms 10 ohms and 20 ohms resistor with 5V at 2 A supply But the three resistor were burnt after few second also the reading is in minus I think its because power rating of resistor

I had another 5 ohms resistor When I use it, it does not burn but it does not give any reading

I have three supply

5v at 1 A
5v at 2A
20 at 4.5 A

danjperron
Posts: 3261
Joined: Thu Dec 27, 2012 4:05 am

Power rating of the resistor is very important

5V * 2A = 10W then you need at least at 12W resistor. (20% margin)

You could try with a smaller resistor like 5V/.1A = 50R W=V*I => 5V*.1 = .5W Put two 100 ohm 1/2W resistor in parallel.

Your 5V adapter is rated 2A but i'm sure that the 5V will drop when 2A is applied.

Use a 12 Volt car light bulb ,like the flasher one,.It will draw some current.

Also don't use the 5V from your Pi. Use an isolated one. If you draw your Pi 5V you will drop the 5V voltage and then the calculation will be off. Also You PI need all the power it could. Your ACS712 isolated the sensor pin from the PI. Then try to keep it isolated. Better chance to not fried your Pi.

Fan174
Posts: 171
Joined: Tue Mar 20, 2018 6:10 am

danjperron wrote:
Thu Sep 13, 2018 1:59 pm
There is a method to counteract the 5V from the adapter if you don't want to use an external 5V.

1 - Use IN1 to check the 5V real Voltage. Make a resistor divider like 10K/4.7K to reduce the 5V to a readable Voltage for the ads1115.
2- Do average readings of IN0 (acs712) and IN1 (5V) in alternance.
3- From IN1 get the real Voltage of VCC using a conversion function. if you are using 10K/4.7K the conversion should be close to

- resistor divider formula
Vout = Vin * R1 / (R1+R2) => Vin = Vout *(R1+R2)/R1

Vout = IN1 voltage value
R1 = 4.7K ohm
R2 = 10K ohm
I have 4.5k / 10K

R1 = 4.5 K
R2 = 10k
I measured voltage with multimeter

Vin = 2.56 and

voltage across R1
V1 = 0.82 V
voltage across R2
V2 = 1.73 v

I think Vin = 2.56V and Vout = 1.73 V

I am giving external 5v Dc supply to sensor
Last edited by Fan174 on Fri Sep 14, 2018 5:56 pm, edited 1 time in total.

Paul Hutch
Posts: 353
Joined: Fri Aug 25, 2017 2:58 pm
Location: Blackstone River Valley, MA, USA
Contact: Website

Fan174 wrote:
Fri Sep 14, 2018 4:21 pm
I did the experiment with 5 ohms 10 ohms and 20 ohms resistor with 5V at 2 A supply But the three resistor were burnt after few second

For a 5V supply:
5 ohm load = 1A = 5 Watts
10 ohm load =0.5A = 2.5 Watts
20 ohm load = 0.25A = 1.25 Watts

A rule of thumb I use is that the power rating for a load resistor needs to be 5 to 10 times higher than the power applied to prevent burning up without active cooling and the power staying applied for minutes. Proper calculations are complicated do to the heat generated usually also causing a local rise in ambient temperature around the resistor which in turn lowers the power rating of the resistor.

So I'd use resistors with these power ratings:
5 ohm 25 to 50 watt
10 ohm 15 to 25 watt
20 ohm 10 to 15 watt

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Good to hear that you don't try to run it at mains voltage.

Also, what for kind of wire are you using for the current sensor?

Fan174
Posts: 171
Joined: Tue Mar 20, 2018 6:10 am