

Show HN: Arduino-based current sensor.  My first electronics project. - trafficlight
http://trafficlightads.net/2011/09/06/an-arduino-current-sensor/

======
0x12
I just had a look at the 'guts' of your project box, please make sure that you
maintain minimal spacing between the high voltage and low voltage parts of
your circuit.

As it is it looks like they are _much_ too close to each other.

Just having them electrically separated is not enough, you have to account for
arcing in all kinds of conditions as well as temporary over voltage (spikes)
on the current carrying wires.

~~~
theatrus2
[Disclaimer: I've put products successfully through UL]

The OP is correct, for a non-isolated product (one with user exposed metal
bits and connectors) you're not paying enough attention to separation and
protection. UL would probably require double insulated wires, wire guides, and
moving your wire lug away from logic circuits, adding a fuse, along with all
sorts of requirements on labeling, etc etc.

Also, are you calculating RMS current or average current? Without a voltage
tap, you also can't determine power due to power factor.

~~~
trafficlight
Do you have any recommended documentation for doing these things properly? I'm
pretty naive when it comes to this stuff, so any information about best
practices would be appreciated.

~~~
0x12
I think the easiest way for you to significantly improve the circuit from a
safety perspective is to modify the layout in such a way that the high voltage
part of the circuit is on one end of it and the low voltage part on the other.

A (very safe) alternative to using the hall sensor the way it is wired up
right now: consider wrapping the current carrying wire around a ferrite core
and putting a number of turns around the other side of the core to pick up the
current (a very basic transformer). That way there is absolutely no need to go
'near' to the low voltage part of the circuit with the high voltage portion of
the wiring.

That's called a current sensing transformer.

You could also place the hall sensor if you really want to use that in the gap
of a slotted toroid around which the primary wire is wound a number of turns.

Adding a fuse is a basic precaution, you should size it based on the wire
thickness that you are using.

You are doing pretty good but beware of knowing 'just enough to be dangerous'.

Alternatively once you've finished prototyping the circuit you could hand off
the process of packaging it in a way that complies with the various standards
to an electrical engineering firm, from a liability perspective that might be
a good idea anyway.

hth

------
jrockway
Interesting, but I wonder if passing the load through any physical device is
necessary? I would think that a few loops of wire wrapped around the power
cable would be good enough for detecting on/off.

It works for these things, anyway:
[http://www.fluke.com/images/products/Industrial/Electrical_T...](http://www.fluke.com/images/products/Industrial/Electrical_Test_Tools/320_app.jpg)

Also, your high-voltage connections look a little scary to me. Are those big
bolts sticking out of the current sensor live!?

~~~
trafficlight
Yeah they are live. I honestly didn't think it was that big of a deal. I mean
they have photo of that exact setup on the current sensor product page.

<http://www.pololu.com/catalog/product/1185>

~~~
jrockway
Yes, but they aren't connecting it to line voltage. I imagine the intended
application for this particular chip is to be part of a battery charge
circuit, and so those pins are going to be at 1.2V instead of 120V as in your
application.

(The datasheet doesn't mention this because the IC can theoretically sink
infinite voltage. The input current is put into the chip only to go through a
carefully-placed piece of copper that maximizes the effectiveness of the Hall
effect sensor. The only limit that matters to the chip is heat production,
which depends on the resistance of that piece of copper and the amount of
current flowing through it. Voltage simply doesn't affect the chip in any way,
so there's no reason to set any limits.)

The problem I see with your current design is that isolating the line voltage
from the container is going to be difficult. Line voltage appears on 8
different places; the four connection areas (top and bottom), and the four
input pins on the IC itself. Without potting it in epoxy, you're not going to
be able to isolate all that from an errant chip of metal that happens to enter
the enclosure. And that's all it would take to burn down your house; a little
chip of metal gets between the pins but doesn't make very good contact. As
current flows, it gets hotter and hotter until it sets the enclosure on fire.
(Your circuit breaker will trip if this causes your device to draw more than
20 amps, as a clean short would, but 2400W is more than enough to start a
fire.)

Ultimately, you have to keep in mind that you can pull a lot of power out of
your house's outlets. This power can kill you or start a fire, so when you are
wiring it up to something, you need to think about how your device could
possibly fail and protect against it. What if the cover falls off? What if a
piece of metal shorts the line voltage to your Arduino's USB port? What if a
connection is faulty and gets hot?

This much paranoia is warranted when a minor mistake could kill someone. Is
knowing that your TV is on worth dying in a fire for? :)

Now, the good news is that you can make a device that works just as well as
this one without having to touch the wire going to the TV. The only reason you
have the TV connected through the current-sensing chip is to get the current
that the TV's drawing very close to the Hall effect sensor. This will let you
make milliamp-level measurements very accurately. But you don't need that
accuracy, so taping a Hall effect sensor to the TV's cord will be just as
good, and will be intrinsically safe. (I think a few loops of wire will work
too, but I just tried this and it didn't work. YMMV. I didn't have any magnet
wire, so I used a long piece of wire stolen from a radio antenna.)

(This is assuming that my photoresistor-near-the-TV's-power-LED idea doesn't
work, of course.)

Finally, the Arduino is likely overkill for this application. Something like
an op-amp set up as a comparator and connected to a free serial port pin would
work just as well, and cost you 1 cent instead of 20 bucks :)

Anyway, I'm looking forward to version two; this is a great project and your
proof of concept is excellent. But you can make the device simpler, safer, and
cheaper; so why not spend an afternoon doing that. The increase in sleep from
not having nightmares about the thing catching on fire should definitely make
up for the time invested in doing so :)

~~~
trafficlight
I really appreciate your input. This is extremely helpful.

I also picked up some epoxy this afternoon to do exactly what you said.

I realize the Arduino is overkill, but I'm complete newbie and it seemed like
the quickest solution. Whenever my next revision is ready, can I send you an
email?

~~~
jrockway
Yes, please send me email. I find this project very interesting and you've
done a great job documenting it. I'm going to order some Hall effect sensors
and see what results I get with them. I'll let you know what I find out.

Also, be careful with the epoxy. You need to get some specific kind (that is
non-conductive), and I'm not sure what that is. There are all sorts of effects
materials have on electronics; the epoxy could add resistance, capacitance,
inductance, and any of those could adversely affect your circuit. Hopefully
you can get specific advice from someone more qualified than I am.

------
yellowbkpk
If you do ever create your own, you might want to try siphoning some power
from the mains to power your Arduino and while you're at it attach a XBee or
Wifi unit to the Arduino for remote monitoring.

(And then once you get to that point take a look at the Tweet-A-Watt:
<http://www.ladyada.net/make/tweetawatt/>)

~~~
trafficlight
The Tweet-A-Watt was one of the first things I came across. In my situation,
wireless seemed overkill considering my power plug is always within 10 feet of
the PC.

~~~
yellowbkpk
Yea, good point. I was thinking of the case where you wanted to monitor
something like your refrigerator. I suppose my TV has a computer next to it at
all times too. Great project!

------
Jun8
This looks great. One very important application for such a device is for
viewer analytics. A lot of companies, e.g. Nielsen, would like to
automatically gather data on what you are watching. Now, its relatively easy
(well, if you have access to the cable box) to know what channel you are tuned
to but they don't know if you actually watching the TV or not. One necessary
(but not sufficient) condition for watching is, of course, for the TV to be
on, which can be detected by a gadget like this.

------
derobert
You could also use a photodetector placed over the TV's power light, and I bet
you could even input that to a PC with very minimal hardware, over a serial
port or microphone jack.

Cost would be very low, even if you have to buy USB<->Serial adapters. And you
can run many feet of serial over CAT5.

Also, you may want to check xrandr, that strikes me as the correct way to ask
the X server what is connected.

~~~
trafficlight
xrandr doesn't give any useful information. There is a "monitor connected"
value, but it always reports Yes.

The photodetector idea is interesting. Do you think the ambient room light
would cause any problems?

~~~
jrockway
The best answer is "try it and see". You already managed to build a device
that uses the Hall effect to measure the amount of current your TV is pulling,
so hooking up a photoresistor to an ohm meter and taping it to your TV while
you turn the lights on and off should not be too difficult :)

Also, electrical tape is black and blocks light pretty well, so slather enough
of that on there and you should be good :) I guess _you_ won't know whether or
not your TV is on, in that case, but you can always add another LED that
mimics the status of the TV's LED.

(According to Wikipedia, you can use an LED as a photodiode. So you may not
even have to buy anything to try this idea out!
[http://en.wikipedia.org/wiki/LEDs_as_Photodiode_Light_Sensor...](http://en.wikipedia.org/wiki/LEDs_as_Photodiode_Light_Sensors#LED_as_light_sensor)
)

(Also, a hacked VGA cable may help xrandr report the TV power status. By
default, VGA cables supply +5V to the DDC chip in the TV, so it can detect its
presence even when off. Since you don't want this to happen, perhaps clipping
that pin off will prevent the DDC information from being queried until the TV
is turned on.)

------
HeyLaughingBoy
@trafficlight:

How much did Polycase quote for having the enclosures milled and printed? In
what quantity?

~~~
trafficlight
I don't have an official quote. I was just basing my numbers of their ballpark
pricing guide: <http://www.polycase.com/uploads/131981312383254.pdf>

For 100 quantity, milling would be $1.15 each, printing would be $0.76 each
and about $200 is setup fees.

~~~
HeyLaughingBoy
Awesome. Thanks. I was about to email them for a quote for a project I'm
working on, but this is good enough for me to budget with.

