jfriend00
Posts: 14
Joined: Sun Aug 24, 2014 12:32 am

How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 12:53 am

I am building some home automation control for attic ventilation with the Pi. I've figured out how to get multiple temperature sensors hooked up to the Pi, but the third piece of input I need is to know when a house fan is on or off and I'm looking for ideas for how to sense that?

I was hoping to do that sensing non-invasively (e.g. without messing with the house fan at all). My naive idea is to use a non-invasive current sensor that I can merely clamp around the power wires to the house fan and it should tell me when current is flowing in the power line (that's good enough for this application). But, the current sensors I can find such as this current sensor all output a current which can be turned into a voltage with a resistor. So, I've got an analog voltage. As best I can tell the Pi doesn't have inputs for an analog voltage.

So, two questions:

1) How can I read an analog voltage on the Pi?

or

2) What other ways can I sense when the house fan is running?

P.S. I'm a software guy that's a noob with hardware so I'm looking for something simple or something that has good directions/writeup on how to make it work, but I am excited about what I can do with the Pi + various sensors.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 14281
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 2:48 am

[moderated your subject line to make sense]

no, a PI doesn't have analog inputs, its purely a digital chip!

to add the ability to sense an analog signal you will need to add an analog to digital converter chip, normally connected to the I2C (slow, but with the ability to connect many devices), or SPI for faster, (but fast = audio, not video) A/D converters.

An a/d converter is not needed to sense that a mains connected device draws current, the fact that that current can flow through a LED (with a diode anti-parralel connected to it) means that you can use an opto-isolator. The photo transistor acts like a "switch", that can be connected to a GPIO, which will see a 50 (60) Hz square wave when the current (up to a 100mA or so) flows through the mains wire, and LED of the opto-isolator. a max of 100mA means (for a 220V appliance) a maximum of about 22 Watt, above that very low resistance is needed where most of the the current flows through.

be careful with mains voltages, it can kill you! :|

ddahms
Posts: 77
Joined: Tue Mar 18, 2014 3:38 pm

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 3:40 am

You might consider sensing the airflow from the fan using a sail switch. It is a simple microswitch with a paddle on a long arm that is located near the fan so the airflow causes the switch to close. It is completely non-invasive and electrically separated from the fan. They are commonly used in HVAC applications. You could connect the switch directly to a Pi GPIO pin. A pull-up resistor is necessary, either enable the internal one or attach an external one.

Here's an example of a sail switch:
Image

jfriend00
Posts: 14
Joined: Sun Aug 24, 2014 12:32 am

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 4:07 am

mahjongg wrote:[moderated your subject line to make sense]

no, a PI doesn't have analog inputs, its purely a digital chip!

to add the ability to sense an analog signal you will need to add an analog to digital converter chip, normally connected to the I2C (slow, but with the ability to connect many devices), or SPI for faster, (but fast = audio, not video) A/D converters.

An a/d converter is not needed to sense that a mains connected device draws current, the fact that that current can flow through a LED (with a diode anti-parralel connected to it) means that you can use an opto-isolator. The photo transistor acts like a "switch", that can be connected to a GPIO, which will see a 50 (60) Hz square wave when the current (up to a 100mA or so) flows through the mains wire, and LED of the opto-isolator. a max of 100mA means (for a 220V appliance) a maximum of about 22 Watt, above that very low resistance is needed where most of the the current flows through.

be careful with mains voltages, it can kill you! :|
I really don't want to put anything on the main power line as I'd rather not mess with that. That's why I was interested in the non-invasive AC voltage sensor that you can just clip around the outside of one of the insulated power lines and it will detect the AC voltage flowing through. Do you have a specific A/D converter you would recommend - something like an expansion board that plugs into the Pi? My google search landed on this one, but I was hoping for a recommendation from someone here who has some experience with one.

jfriend00
Posts: 14
Joined: Sun Aug 24, 2014 12:32 am

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 5:40 am

ddahms wrote:You might consider sensing the airflow from the fan using a sail switch. It is a simple microswitch with a paddle on a long arm that is located near the fan so the airflow causes the switch to close. It is completely non-invasive and electrically separated from the fan. They are commonly used in HVAC applications. You could connect the switch directly to a Pi GPIO pin. A pull-up resistor is necessary, either enable the internal one or attach an external one.

Here's an example of a sail switch:
Image
Thx for the idea. Do you have a specific sail switch recommendation? I like the "non-invasive and electrically separated" part of this solution, but I'm not sure I'm keen on having the moving parts in a hot attic since I want this to last a very long time without maintenance. So, would you just enable pull-up on the GPIO port and then the switch would either be open or closed to give you on/off on the port? Is that how you would use it?

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

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 6:08 am

You don't really need an ADC to do what you're trying to do. You're not trying to measure exactly how much current is flowing, just that it is either flowing or not (if I understand your description correctly).

So all you need is something that converts the output of the sensor into a on or off state with a 3.3V DC logic level.

I'm not familiar with that model of current-clamp sensor, but I suspect it would only need something simple to do that. The problem is that there possibly isn't a pre-built device to do that. It would probably only need a few components to do it though, I'm sure one of the more awake than I am at the moment electronic savy people on here could design something in a few seconds. I suspect a diode to rectify the output, capacitor to smooth it and transistor to switch the 3.3V would be the basic setup.

jfriend00
Posts: 14
Joined: Sun Aug 24, 2014 12:32 am

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 6:40 am

rpdom wrote:You don't really need an ADC to do what you're trying to do. You're not trying to measure exactly how much current is flowing, just that it is either flowing or not (if I understand your description correctly).

So all you need is something that converts the output of the sensor into a on or off state with a 3.3V DC logic level.

I'm not familiar with that model of current-clamp sensor, but I suspect it would only need something simple to do that. The problem is that there possibly isn't a pre-built device to do that. It would probably only need a few components to do it though, I'm sure one of the more awake than I am at the moment electronic savy people on here could design something in a few seconds. I suspect a diode to rectify the output, capacitor to smooth it and transistor to switch the 3.3V would be the basic setup.
You're right. I don't need the voltage level, just a binary yes/no whether it's above some threshold. I does seem like it should be possible to turn some voltage threshold out of the current sensor into a binary on/off that you could just hook to a GPIO pin. Anyone out there know exactly what circuit would do that?

After some time on Google, it looks like a Schmitt Trigger circuit does this. The output switches from low to high when the input voltage passes some threshold and the advantage of the Schmitt Trigger is that it has some hysteresis to it so the output doesn't jump around if there's some noise on the input as it nears the threshold value. I understand the principle - now I need to find something that helps me choose the exact parts that need to go in the circuit (which transistors, resistor values, etc...) and also how to deal with the AC nature of the input voltage (it will have to be turned into some average voltage, I presume).

Hmmm, further reading suggests that the GPIO pins themselves can be configured to have some Schmitt Trigger - like behavior built in. I may need to just get the AC voltage turned into some average DC level and then put into the right voltage range for the GPIO pin. I might not need my own Schmitt Trigger.

Or, if I need to use my own Schmitt Triggers, you can buy them in a chip.
Last edited by jfriend00 on Sun Aug 24, 2014 7:29 am, edited 1 time in total.

ame
Posts: 4154
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 7:10 am

Another option is to use an optical switch. Either install it so that the optical beam is broken by the movement of the fan's blades, or so that the blades reflect light back to the sensor (maybe you can stick some reflective tape on the blades, or on the hub).

The advantage of this is that it is entirely disconnected from the ac mains, and it will tell you that the fan is actually running (not just that power is applied- maybe the fan gets stuck, or slows down due to the accumulation of debris).

Incidentally, what controls the fan? Is it a circuit inside the fan housing, or is it an external circuit? i.e. is the fan powered all the time, and operates by itself, or is the fan powered only when an external sensor decides to apply power?
Hmm. What can I put here?

jfriend00
Posts: 14
Joined: Sun Aug 24, 2014 12:32 am

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 7:20 am

ame wrote:Another option is to use an optical switch. Either install it so that the optical beam is broken by the movement of the fan's blades, or so that the blades reflect light back to the sensor (maybe you can stick some reflective tape on the blades, or on the hub).

The advantage of this is that it is entirely disconnected from the ac mains, and it will tell you that the fan is actually running (not just that power is applied- maybe the fan gets stuck, or slows down due to the accumulation of debris).

Incidentally, what controls the fan? Is it a circuit inside the fan housing, or is it an external circuit? i.e. is the fan powered all the time, and operates by itself, or is the fan powered only when an external sensor decides to apply power?
It isn't obvious to me how to make an optical beam detect rotation of the fans or how that would be less complicated than other approaches. I only have access to one side of the fan and the blades can stop at any position when it stops. Plus, I'm not sure an optical sensor is an ideal choice for a dusty attic environment.

The fan is switched manually from a location inside the house and runs on 110 AC voltage. The switching of the fan itself isn't simple though as it has multiple speeds and timers. Even the electrician installing it was thinking the controlling switch was a bit complicated and I haven't attempted to understand how that switch works plus I don't really want to get involved with any direct connect to the 110.

Incidentally, we will know immediately if the fan isn't working because we turn it on manually and will notice if that has no effect so detecting power applied to the fan is perfectly fine for this application.

ame
Posts: 4154
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 7:37 am

jfriend00 wrote:It isn't obvious to me how to make an optical beam detect rotation of the fans or how that would be less complicated than other approaches. I only have access to one side of the fan and the blades can stop at any position when it stops. Plus, I'm not sure an optical sensor is an ideal choice for a dusty attic environment.
Ok, then that suggestion is no good for you.
The fan is switched manually from a location inside the house and runs on 110 AC voltage. The switching of the fan itself isn't simple though as it has multiple speeds and timers. Even the electrician installing it was thinking the controlling switch was a bit complicated and I haven't attempted to understand how that switch works plus I don't really want to get involved with any direct connect to the 110.

Incidentally, we will know immediately if the fan isn't working because we turn it on manually and will notice if that has no effect so detecting power applied to the fan is perfectly fine for this application.
Is there an LED or some sort of indicator on the control box?
Hmm. What can I put here?

User avatar
Paul Webster
Posts: 850
Joined: Sat Jul 30, 2011 4:49 am
Location: London, UK
Contact: Twitter

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 8:52 am

This might be over the top, but how about a clamp that sends data via Zigbee and then add a Zigbee board to the RPi?
If you have plans to monitor other things around the home as well then this could be a good starting point.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 14281
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 12:51 pm

jfriend00 wrote: Do you have a specific A/D converter you would recommend
more or less the I2C MCP23008 (8 inputs) or MCP23017 (16 inputs) is the standard solution for slow signal applications, there are many boards sold with it, but I would take a look at the adafruit site. https://learn.adafruit.com/mcp230xx-gpi ... i/overview

for converting a logic level to a binary signal, you should use a "Comparator", like an LM339, the input signal is compared with a set level made by dividing VCC (3V3) with a resistor divider. a comparator normally has an open collector output, so it also needs a pull-up (4K7) and for a GPIO an 1K series (safety) resistor in series with the GPIO pin.

jfriend00
Posts: 14
Joined: Sun Aug 24, 2014 12:32 am

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 4:44 pm

mahjongg wrote:
jfriend00 wrote: Do you have a specific A/D converter you would recommend
more or less the I2C MCP23008 (8 inputs) or MCP23017 (16 inputs) is the standard solution for slow signal applications, there are many boards sold with it, but I would take a look at the adafruit site. https://learn.adafruit.com/mcp230xx-gpi ... i/overview

for converting a logic level to a binary signal, you should use a "Comparator", like an LM339, the input signal is compared with a set level made by dividing VCC (3V3) with a resistor divider. a comparator normally has an open collector output, so it also needs a pull-up (4K7) and for a GPIO an 1K series (safety) resistor in series with the GPIO pin.
I like the idea of using the MCP23008 as I think knowing how to use the A/D on the Pi would be useful for other things I may contemplate doing also. Now, I just have to figure out how to convert the AC voltage coming out of the current sensor to a DC voltage in the right range that I can feed into the MCP23008.

Also, is there any particular advantage of the MCP23008 (8 channel, 8-bit, i2C) vs. MCP3008 (8 channel, 10-bit, SPI) for my use?

Hmmm, I may go for this already built A/D board. It's way more than I need, but it's convenient to be already built on a board and comes with sample code.
Last edited by jfriend00 on Sun Aug 24, 2014 5:13 pm, edited 1 time in total.

jfriend00
Posts: 14
Joined: Sun Aug 24, 2014 12:32 am

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 4:56 pm

Paul Webster wrote:This might be over the top, but how about a clamp that sends data via Zigbee and then add a Zigbee board to the RPi?
If you have plans to monitor other things around the home as well then this could be a good starting point.
I think that's more than I need to go for. Thx for the idea though.

ddahms
Posts: 77
Joined: Tue Mar 18, 2014 3:38 pm

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 5:39 pm

One important detail about the clamp-on current sensor is that only one conductor goes through the sensor. If you put both conductors through the sensor, the magnetism will cancel and the sensor will read nothing. If your house has plastic-sheathed cable (aka Romex) you will have to remove a section of the plastic sheath and separate the conductors so you can attach the sensor around just one conductor.

ame
Posts: 4154
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to sense when an appliance is running with a Pi

Sun Aug 24, 2014 10:36 pm

Is there an LED or some kind of indicator on the control box?
Hmm. What can I put here?

jfriend00
Posts: 14
Joined: Sun Aug 24, 2014 12:32 am

Re: How to sense when an appliance is running with a Pi

Mon Aug 25, 2014 2:07 am

ddahms wrote:One important detail about the clamp-on current sensor is that only one conductor goes through the sensor. If you put both conductors through the sensor, the magnetism will cancel and the sensor will read nothing. If your house has plastic-sheathed cable (aka Romex) you will have to remove a section of the plastic sheath and separate the conductors so you can attach the sensor around just one conductor.
Yes, I'm aware of this. The wiring is Romex and I will just strip a short section to get access to one of the wires.

gwu888
Posts: 6
Joined: Mon Jul 13, 2020 10:30 pm

Re: How to sense when an appliance is running with a Pi

Thu Dec 10, 2020 1:55 am

I have just quickly glance at the feedbacks above but just curious if someone just make this suggestion: imaging your fan has a power supply plug (male) to plug into the wall (female), and you might already have a wall switch to turn it on-and-off. you buy a power extension bar with six electricity plugs, then pull your fan plug to one of the six plugs and connect the power extension bar head to the wall. Now you have other fix outlets when the wall switch turns on, the fan is running and you have other five plugs with electricity. You simply plug a old phone charger to one of the five. When the fan is running, your phone charger has 5V output, then use this as your signal to connect to your PI's GPIO with a resistor and LEP....is this what you want?

emma1997
Posts: 1669
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: How to sense when an appliance is running with a Pi

Thu Dec 10, 2020 2:10 am

Wow.. this really is necro-day in Piland.

IME a simple 10 cent ferrite toroid around AC line or even Hall device is cheaper and easier to implement. Full isolation, no separate switch, 6 outlet strip, or bulky wall wart. Also unlike wall wart you can actually measure current levels with small additional circuit.

jfriend00
Posts: 14
Joined: Sun Aug 24, 2014 12:32 am

Re: How to sense when an appliance is running with a Pi

Thu Dec 10, 2020 2:19 am

emma1997 wrote:
Thu Dec 10, 2020 2:10 am
Wow.. this really is necro-day in Piland.

IME a simple 10 cent ferrite toroid around AC line or even Hall device is cheaper and easier to implement. Full isolation, no separate switch, 6 outlet strip, or bulky wall wart. Also unlike wall wart you can actually measure current levels with small additional circuit.
How do you interface a 10 cent ferrite toroid to the Raspberry Pi?

emma1997
Posts: 1669
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: How to sense when an appliance is running with a Pi

Thu Dec 10, 2020 2:39 am

Easy. You just add wire and loop mains lead around one and with little more than cap and resistor interface directly to GPIO. Even cap is not really required if you don't mind tweaking a pot. Full isolation and cheap as chips. If you want to measure actual levels instead of on/off then add ADC.

Here's an example of mains interface that uses these. I have several in operation around the house. For Pi you don't need the meter part, just the ferrite/coil and they can be purchased separately for less than 1/10 the cost. Smaller versions even cheaper.
AC_ammeter.jpg
AC_ammeter.jpg (188.62 KiB) Viewed 1371 times

BMS Doug
Posts: 4423
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: How to sense when an appliance is running with a Pi

Thu Dec 10, 2020 6:30 am

There are lots of this style of breakout board around these days:

Image

They have an adjustment to set a dugital output at a chosen current level and also have an analogue output alongside it.
They are also available with terminal block for wired toroid ring (as Emma1997 has shown) instead of having the toroid ring integrated into the board.
Doug.
Building Management Systems Engineer.

LTolledo
Posts: 6463
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: How to sense when an appliance is running with a Pi

Thu Dec 10, 2020 10:32 am

I briefly saw on a different site (sorry I dont remember which site it was) a "non invasive type" of unit, like a clamp ammeter, but both halves must be screwed (or bolted) for proper operation....

no need to splice up the existing wire to insert the sensor to it....
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

JohnsUPS
Posts: 273
Joined: Fri Jul 06, 2018 2:13 am
Location: USA

Re: How to sense when an appliance is running with a Pi

Thu Dec 10, 2020 12:57 pm

In the environment that I now work in, we use these to sense the presence of current. I'm primarily posting this because devices with an integrated closure output are available, not because they are cheap. Shop around. The output is solid state (Form A contacts in this case, not an analog output) and has a low threshold. Super easy to interface to a GPIO pin.

https://www.veris.com/ASSETS/DOCUMENTS/ ... 0_i0g2.pdf

ghp
Posts: 2132
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: How to sense when an appliance is running with a Pi

Thu Dec 10, 2020 6:45 pm

Airflow sensor FLW-122 ?

Return to “Automation, sensing and robotics”