daveoxford
Posts: 1
Joined: Sat Jul 13, 2019 5:49 pm

(Possibly pre-beginner!) Sensing simple closed circuit.

Sat Jul 13, 2019 6:50 pm

Just ordered my first RPi - mainly just to play with, but thought this (slightly embarrassing!) project would be a perfect use.
Goal: to have music played in my downstairs loo whenever the light is switched on. (Told you it was embarrassing!)
I though I could exchange the light switch for a two-gang and put a circuit through the second gang that the RPi could sense was closed or not and then play the music. (Am fine with the software side - old hand at Linux & python.)
Does this sound OK so far?
Ideally, I would like it all on one switch - are there sensors that can detect a live mains line, for instance?
What I like most is the idea of being able to do home automation on FOSS terms, rather than spending a fortune on overpriced proprietary stuff.
I have great hopes of this forum!
Dave

User avatar
neilgl
Posts: 520
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: (Possibly pre-beginner!) Sensing simple closed circuit.

Sun Jul 14, 2019 8:32 am

I would go with a light dependent resistor or a photodiode circuit that does not go anywhere near the mains switch, and/or a reed switch on the door when it opens?
For home automation on the pi have a look at openhab2, and re-programming (say) Sonoff switches with Tasmota firmware (using a pi).

User avatar
davidcoton
Posts: 3786
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: (Possibly pre-beginner!) Sensing simple closed circuit.

Sun Jul 14, 2019 11:19 am

daveoxford wrote:
Sat Jul 13, 2019 6:50 pm
I though I could exchange the light switch for a two-gang and put a circuit through the second gang that the RPi could sense was closed or not
Does this sound OK so far?
No, it is not safe to mix mains and low voltage switching in the same enclosure, unless the low voltage side wiring has mains-rated insulation and isolation. Basically, don't do it.

See @neilgl's suggestions above, the light detector should be equivalent to the light switch.
Signature retired

PhatFil
Posts: 1233
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: (Possibly pre-beginner!) Sensing simple closed circuit.

Sun Jul 14, 2019 12:20 pm

Sounds like a fun project to cut your teeth on.

As said above, avoid mixing mains and diy electronics as far as possible.. IT CAN BE LETHAL.

Quite a few options are open to you though, a light sensitive resistor as suggested above is one. A PIR (passive infra red) or similar motion detector inside the bathroom, a reed switch and magnet pair mounted on the loo lid or on the loo door?

For more sophistication how about personalised music depending on who is in the loo?? if everyone carries a phone 24/7 (Or if you can convince them to carry a £shop ble tracker) you could use ble to id which phone/tracker is in the b/room (closest to the pi) Or a load cell under the seat could indicate who is in the b/room based on their mass.

fwiw my own experiments with home automation and using a Pi-0-W as a headless/wireless system controller is based on re-using and in some cases reprogramming off the shelf 'smart' consumer retail devices.
For example to satisfy your requirements for less than a £20 cost i would use any battery operated alarm system PIR which broadcasts a 433mhz RF signal (£5+) and use a sonoff RF bridge reprogrammed with tasmota firmware(£8+)..

the rfbridge is a sonoff brand device for use with sonoff brand smart switches But its chinese firmware can be overwritten with open source code from Theo Arends https://github.com/arendst/Sonoff-Tasmota/wiki
A live, dynamic project with regular updates and support fixes.


A Tasmota flashed RF bridge will sit and decode any and all 433mhz signals it can hear and generate a wifi mqtt topic/payload message for each making the signals visible to any device on the same network. so you can simply subscribe to the relevant mqtt topic in your control app /system and whenever the signal you expect is broadcast you will know..
http://www.steves-internet-guide.com/py ... subscribe/

The s/w I use on my Pi for home automation is Mosquitto Mqtt Broker, and for implementing my logic and control Node Red. all free...


Thats just my take tho, .. Lots of other ways and options.. have fun..

Crowbot
Posts: 2
Joined: Sat Jul 13, 2019 2:03 pm

Re: (Possibly pre-beginner!) Sensing simple closed circuit.

Sun Jul 14, 2019 4:49 pm

It's a shot in the dark but if you coiled a wire around the hot leg to the switch it would induce a small current in the wire, like those clamp-on ammeters. You might be able to work with that.

User avatar
neilgl
Posts: 520
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: (Possibly pre-beginner!) Sensing simple closed circuit.

Sun Jul 14, 2019 5:23 pm

You probably do not want to coil any wires around any mains voltage cable - too dangerous.

User avatar
davidcoton
Posts: 3786
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: (Possibly pre-beginner!) Sensing simple closed circuit.

Sun Jul 14, 2019 7:33 pm

neilgl wrote:
Sun Jul 14, 2019 5:23 pm
You probably do not want to coil any wires around any mains voltage cable - too dangerous.
+1. Unless you understand Wiring Regs, insulation voltage, and isolation voltage don't try it.
If you do understand enough to try it safely, you probably won't want to. :o
Signature retired

Andyroo
Posts: 3324
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: (Possibly pre-beginner!) Sensing simple closed circuit.

Sun Jul 14, 2019 8:34 pm

Do not touch the mains - fried Pi is not nice and fried people are worse!

Not sure if you know that all the past issues of the Pi magazine are available here as PDFs with some available as printed back issues. Note subscriptions get you another Pi (one is NEVER enough - you'll weaken see).

You may find this book of interest as a basic intro to interfacing BUT not electronics. You should be able to use chapter six as a basic motion sensor alarm and chapter 8 is based around a light dependant resistor (OK and a LASER but you can change that if you must).

Enjoy the fun you are about to get and do not worry as you will find your head hardens after a week of banging it against the wall when you get stuck :lol:
Need Pi spray - these things are breeding in my house...

User avatar
davidcoton
Posts: 3786
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: (Possibly pre-beginner!) Sensing simple closed circuit.

Sun Jul 14, 2019 9:17 pm

Crowbot wrote:
Sun Jul 14, 2019 4:49 pm
It's a shot in the dark but if you coiled a wire around the hot leg to the switch it would induce a small current in the wire, like those clamp-on ammeters. You might be able to work with that.
Actually, that's not how clamp meters work. They use a toroidal ferrite with a coil round it, the conductor being monitored goes through the centre to form a one-turn winding.
Still, not safe as a DIY arrangement.
Signature retired

Return to “Beginners”