Cooloo
Posts: 27
Joined: Sun Nov 01, 2015 5:46 pm

Current Sensing

Fri Jan 22, 2016 8:59 pm

I am trying to measure current using the ACS712 module along with the MCP3008 ADC.
Is the module connected to the live or neutral of the supply? I am getting a large current reading (when it is connected to the neutral) whether current is flowing in the circuit or not.

ElEscalador
Posts: 839
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Re: Current Sensing

Fri Jan 22, 2016 9:07 pm

Without looking up your device - a current sensor will read the current in the wire that its on which normally would be the same in hot and neutral, but isn't always if you have leakage through ground. I'd put on the hot.
Robotics tips, hacks, book extras https://youtube.com/practicalrobotics

Cooloo
Posts: 27
Joined: Sun Nov 01, 2015 5:46 pm

Re: Current Sensing

Sun Jan 24, 2016 6:09 pm

I switched the sensor to the hot (live) and I'm getting the same reading (1023=5V) whether the appliance is on or off. I should be getting 2 different values for on and off. Any thought on this?

User avatar
Burngate
Posts: 6302
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Current Sensing

Mon Jan 25, 2016 10:15 am

How are you connecting the device to your Pi? (I assume you know the output is an analogue voltage, and the Pi only has digital inputs)

Cooloo
Posts: 27
Joined: Sun Nov 01, 2015 5:46 pm

Re: Current Sensing

Mon Jan 25, 2016 4:21 pm

Yes I'm using an ADC but I'm only getting a High/on reading whether the appliance is on or off

User avatar
mikronauts
Posts: 2783
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Current Sensing

Mon Jan 25, 2016 4:57 pm

The ACS712 sense inputs need to be connected in-line with the power to the device whose current you are trying to measure.

https://www.sparkfun.com/datasheets/Bre ... s/0712.pdf
Cooloo wrote:I am trying to measure current using the ACS712 module along with the MCP3008 ADC.
Is the module connected to the live or neutral of the supply? I am getting a large current reading (when it is connected to the neutral) whether current is flowing in the circuit or not.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

User avatar
Burngate
Posts: 6302
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Current Sensing

Mon Jan 25, 2016 6:27 pm

What reference are you providing the MCP3008, and are you using it single-ended or differentially?

Can you provide a schematic of how it's all connected?

Cooloo
Posts: 27
Joined: Sun Nov 01, 2015 5:46 pm

Re: Current Sensing

Thu Jan 28, 2016 1:14 am

I've connected the Vout from the sensor directly to channel 0 in the ADC and getting 1023 reading wether the appliance is on or off.
Is connecting Vout directly to the ADC correct or are other components (resistors capacitors etc) needed?

User avatar
mikronauts
Posts: 2783
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Current Sensing

Thu Jan 28, 2016 1:20 am

You also need to connect the GND on the sensor, and feed it +5V from the Pi.

You need to divide Vout in two, unless you run the MCP3008 at 5V, in which case you need to divide MISO
Cooloo wrote:I've connected the Vout from the sensor directly to channel 0 in the ADC and getting 1023 reading wether the appliance is on or off.
Is connecting Vout directly to the ADC correct or are other components (resistors capacitors etc) needed?
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

Cooloo
Posts: 27
Joined: Sun Nov 01, 2015 5:46 pm

Re: Current Sensing

Thu Jan 28, 2016 2:34 am

Thanks for your speedy response Mikronauts. I greatly appreciate your advice.

Of course the circuit was connected with the sensor grounded and 5V from the pi (even though I did not indicate that in my previous posts). The code is in fact running but the issue is, as I explained earlier the 1023 reading whether the appliance is on or off.
You suggested dividing Vout in two.(the ADC is running on 5V from the pi) Do I have to put some resistors between Vout and the adc?

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Current Sensing

Thu Jan 28, 2016 8:39 am

Cooloo wrote:Thanks for your speedy response Mikronauts. I greatly appreciate your advice.

Of course the circuit was connected with the sensor grounded and 5V from the pi (even though I did not indicate that in my previous posts). The code is in fact running but the issue is, as I explained earlier the 1023 reading whether the appliance is on or off.
You suggested dividing Vout in two.(the ADC is running on 5V from the pi) Do I have to put some resistors between Vout and the adc?
Why don't you tell us ALL the connections between the Pi and the ADC and the ADC and the device? At the same time a close-up photo would be useful so we could double check the connections.

In addition post the script you are using to read from the ADC.

Cooloo
Posts: 27
Joined: Sun Nov 01, 2015 5:46 pm

Re: Current Sensing

Thu Jan 28, 2016 8:14 pm

This is how all the parts are connected. I hope you can understand this information.

From Current sensor:->
1) Vcc -> 5V on the RPi2
2) GND -> GND on RPi2
3) Vout -> CH0 (pin 1) on MCP3008 (the ADC)

From ADC to RPi2
1) Vdd and Vref -> 5V
2) AGND and DGND -> GND
3) CLK -> SPI_SCLK
4) Dout -> SPI_MISO
5) Din -> SPI_MOSI
6) CS/SHDN -> SPI_CE0_N

Additionally the IP+ and IP- terminals are connected in series with a lamp connected to the 120 V ac supply.

User avatar
mikronauts
Posts: 2783
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Current Sensing

Sat Jan 30, 2016 5:37 pm

Dout -> SPI_MISO will fry the MISO pin on your Pi if you don't divide it down.

Never hook up a 5V output to a 3v3 input without dividing the voltage down tot the 3v3 range.
Cooloo wrote:This is how all the parts are connected. I hope you can understand this information.

From Current sensor:->
1) Vcc -> 5V on the RPi2
2) GND -> GND on RPi2
3) Vout -> CH0 (pin 1) on MCP3008 (the ADC)

From ADC to RPi2
1) Vdd and Vref -> 5V
2) AGND and DGND -> GND
3) CLK -> SPI_SCLK
4) Dout -> SPI_MISO
5) Din -> SPI_MOSI
6) CS/SHDN -> SPI_CE0_N

Additionally the IP+ and IP- terminals are connected in series with a lamp connected to the 120 V ac supply.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

Cooloo
Posts: 27
Joined: Sun Nov 01, 2015 5:46 pm

Re: Current Sensing

Sun Jan 31, 2016 1:41 pm

mikronauts wrote:Dout -> SPI_MISO will fry the MISO pin on your Pi if you don't divide it down.

Never hook up a 5V output to a 3v3 input without dividing the voltage down tot the 3v3 range.
Cooloo wrote:This is how all the parts are connected. I hope you can understand this information.

From Current sensor:->
1) Vcc -> 5V on the RPi2
2) GND -> GND on RPi2
3) Vout -> CH0 (pin 1) on MCP3008 (the ADC)

From ADC to RPi2
1) Vdd and Vref -> 5V
2) AGND and DGND -> GND
3) CLK -> SPI_SCLK
4) Dout -> SPI_MISO
5) Din -> SPI_MOSI
6) CS/SHDN -> SPI_CE0_N

Additionally the IP+ and IP- terminals are connected in series with a lamp connected to the 120 V ac supply.
Good day and thanks again. I'm thinking that between Dout and SPI_MISO I have to put a resistor. My calculations for the are (5-3.3)/2A = 0.85 ohms. As the rating of the dc supply to the Pi is 5V/2000mA.

User avatar
rpdom
Posts: 17170
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Current Sensing

Sun Jan 31, 2016 1:57 pm

Cooloo wrote:I'm thinking that between Dout and SPI_MISO I have to put a resistor. My calculations for the are (5-3.3)/2A = 0.85 ohms. As the rating of the dc supply to the Pi is 5V/2000mA.
The 2000mA of the supply doesn't have anything to do with the resistor value.

You'll need two resistors to make a divider circuit. One from Dout to SPI_MISO and one from SPI_MISO to GND. The idea is to split the 5V across the two resistors so that the connection between them is at somewhere about 3V.

Use a 2K2 resistor for the first one and 3K3 for the second and the voltage to SPI_MISO will be 5V / ( 3300 + 2200 ) * 3300 = 3V

Cooloo
Posts: 27
Joined: Sun Nov 01, 2015 5:46 pm

Re: Current Sensing

Mon Feb 08, 2016 8:33 pm

Thanks as always for your assistance.
I switched to using the MCP 3208 as I blew the 3008. I connected the voltage divider 2k4 and 4k7 as shown in the attachment.
(please excuse the tiny pic, I cropped the photo to get the 65k limit).
I'm now getting a reading of 310 (remember I was getting 1024 before) without a load connected to the sensor. I know that I'm supposed to get 512. Below is the code I used.

import spidev
import time
spi = spidev.SpiDev()
spi.open(0, 0)
def readADC(channel):
r1 = spi.xfer([1, (8 + channel) << 4, 0])
r2 = ((data1[1] & 3) << 8) + data1[2]
return r2
while True:
num1 = getData(0)
print(num1)
time.sleep(5)
Attachments
Pot.PNG
Pot.PNG (55.04 KiB) Viewed 4007 times

grahamed
Posts: 277
Joined: Mon Jan 30, 2012 7:01 pm

Re: Current Sensing

Tue Feb 09, 2016 9:33 pm

Does the 310 come and go as the lamp is turned on and off?

How do know that you should b getting 512?

RichardatWillow
Posts: 25
Joined: Fri Jan 08, 2016 8:33 am

Re: Current Sensing

Wed Feb 10, 2016 9:19 pm

Hi all

May be a bit late but we offer a board designed around Microchip MCP3424 quad ADC. There is also an on-board instrumentation amplifier and a fully isolated +/-20A current sensor using the ACS712ELCTR-20.

It plugs directly into the 40 way GPIO and we will be publishing a link to sample code in the next week or so.

Image

for more info, check our website at http://www.willowcomponents.co.uk

good luck
Richard
Willow Components

fsr
Posts: 88
Joined: Wed Jan 13, 2016 2:29 am

Re: Current Sensing

Fri Feb 12, 2016 12:22 am

Cooloo wrote: r2 = ((data1[1] & 3) << 8) + data1[2]
)
the mcp320x are 12 bit. you are only getting 2 bits from byte 1.(3 = 0b11)

try
r2 = ((data1[1] & 0x0f ) << 8) + data1[2]

Cooloo
Posts: 27
Joined: Sun Nov 01, 2015 5:46 pm

Re: Current Sensing

Sun Feb 14, 2016 9:57 pm

Thanks for all the help. I finally got the MCP 3008 working properly with the sensor. The voltage divider that I didn't have in initially was the problem. Thanks a lot again
Now onto connecting the relay. Will let you all know how it goes.

Choy
Posts: 2
Joined: Wed Oct 05, 2016 1:52 pm

Re: Current Sensing

Wed Oct 05, 2016 1:59 pm

Hi, i have the same problem also.. can you post or send some pictures on the actual circuit of yours? on how you've done it please I have also a project the same as yours

We have the same connection on Sensor->ADC->RPi 2 except for mine, Ive connected my ADC to RPi with 3.3v

Choy
Posts: 2
Joined: Wed Oct 05, 2016 1:52 pm

Re: Current Sensing

Wed Oct 05, 2016 2:10 pm

Cooloo wrote:Thanks for all the help. I finally got the MCP 3008 working properly with the sensor. The voltage divider that I didn't have in initially was the problem. Thanks a lot again
Now onto connecting the relay. Will let you all know how it goes.

Hey! Can you help me on how you solved the problem? I have the same problem with these...

Return to “Automation, sensing and robotics”