phjo
Posts: 11
Joined: Tue Jan 06, 2015 9:01 am

Doorbell Help

Tue Jan 06, 2015 9:05 am

Hi
I'm looking to attach my doorbell to a raspberry pi (B+ currently running with just the razberry z-wave controller).
It's an old style doorbell with a wired button, two chime bars and a 9v battery.

I've figured half the software setup of grabbing a snapshot from a video camera and pushing it to my mobile but im stuck on how to connect the bell to the pi (the bit I assumed was easy!)

I emailed pimoroni who suggested a level shifter was what I needed (Adafruit 4-channel I2C-safe Bi-directional Logic Level Converter) which was what I ordered and now have on my desk with no idea what to do with it (and suspect now that its probably not the right thing as there is no logic coming from the doorbell). Maybe just some resistors would work?

Can anyone guide me as to where to go from here? I know I need to get some sort of signal from the doorbell to the pi but don't know how at the right voltage. All the instructions I've seen relate to AC doorbells or wireless ones which either need big changes or already run at a suitable voltage (looking at "Door bell project - technical questionss" by angus-uk).

thanks

drgeoff
Posts: 10832
Joined: Wed Jan 25, 2012 6:39 pm

Re: Doorbell Help

Tue Jan 06, 2015 10:36 am

One resistor and one optocoupler is the safe, easy way.

Two resistors and a transistor will work but needs one common connection between doorbell circuit and RPi.

Trying to use just two resistors might lead to damaging the RPi from back-EMF of the bell's coil.
Quis custodiet ipsos custodes?

phjo
Posts: 11
Joined: Tue Jan 06, 2015 9:01 am

Re: Doorbell Help

Tue Jan 06, 2015 11:00 am

I've not come across octocouplers, I'll have a look into them
How do I calculate the resistor I need, is it just to get the 9v down to whatever the octocoupler needs?

Thanks

Phil

drgeoff
Posts: 10832
Joined: Wed Jan 25, 2012 6:39 pm

Re: Doorbell Help

Tue Jan 06, 2015 11:26 am

Ohm's Law: V=IR

V is battery voltage minus the voltage drop of the diode in the opto. Probably about 2 vote drop.

I is the current you want in the diode.

Solve for R.

You need very little current in the output side of the opto if you use the internal RPi PIO pullup. 500 microamps is plenty.

Consult the opto datasheet for its input to output relationship.
Quis custodiet ipsos custodes?

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

Re: Doorbell Help

Tue Jan 06, 2015 11:51 am

I assume that you still want the doorbell to ring?

Your doorbell circuit probably works very similarly to this picture (substituting a 9V battery for the transformer).
Image

you need to connect a sensor for the pi in parallel to the bell, so that both are activated when the bell is rung. An opto-coupler with a resistor in series is probably a good choice of sensing device.
Doug.
Building Management Systems Engineer.

phjo
Posts: 11
Joined: Tue Jan 06, 2015 9:01 am

Re: Doorbell Help

Wed Jan 07, 2015 8:33 am

Excellent, thanks for the help.
I bought an optocoupler and resister lunchtime yesterday and had a test setup sending photos to my phone within a couple of hours.
Hopefully attaching it to the doorbell for real will not affect the circuit too much.

phjo
Posts: 11
Joined: Tue Jan 06, 2015 9:01 am

Re: Doorbell Help

Fri Jan 09, 2015 9:01 am

Right. I now have the pi hooked up to the doorbell and the script is being triggered,
However im having some issues with ghost pushes, that it I get some notifications when the doorbell is not pressed.
I have the output of the optocoupler attached to pin 24 and 26 (so a GPIO and ground), the script I'm using is below

Is there something obvious I'm doing wrong that is causing these triggers?

thank you

Phil

Code: Select all

import RPi.GPIO as GPIO
import wget, os, datetime
from pushbullet import PushBullet

#set up GPIO using BCM numbering
GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)
labelup ="Button pressed"
labeldown ="Button Released"

now = datetime.datetime.now()
now2 = datetime.datetime.now().strftime("%y-%m-%d_%H-%M-%S")
savedir = "Doors"
os.chdir(savedir)
url = 'http://MY_WEBCAM/snapshot.cgi?user=USER&pwd=PASSWORD'
api_key = "MY_API_KEY"
pb = PushBullet(api_key)
oldfilename = "snapshot.cgi"

while True:
	GPIO.wait_for_edge(24, GPIO.FALLING)
	print labelup
	GPIO.wait_for_edge(24, GPIO.RISING)
	print labeldown
	wget.download(url)
	now2 = datetime.datetime.now().strftime("%y-%m-%d_%H-%M-%S")
	print now2
	newfilename = "DoorBell_" + now2 + ".jpg"
	os.rename(oldfilename, newfilename)
	with open(newfilename, "rb") as pic:
		success, file_data = pb.upload_file(pic, newfilename)
	success, push = pb.push_file(**file_data)
		
GPIO.cleanup()

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

Re: Doorbell Help

Fri Jan 09, 2015 9:07 am

phjo wrote:Right. I now have the pi hooked up to the doorbell and the script is being triggered,
However im having some issues with ghost pushes, that it I get some notifications when the doorbell is not pressed.
I have the output of the optocoupler attached to pin 24 and 26 (so a GPIO and ground), the script I'm using is below

Is there something obvious I'm doing wrong that is causing these triggers?

thank you

Phil
do you have a pullup resistor to hold the GPIO high while the doorbell isn't activated?
If you have left it floating then that could be the cause of the ghost pushes.
Last edited by BMS Doug on Fri Jan 09, 2015 9:22 am, edited 1 time in total.
Doug.
Building Management Systems Engineer.

phjo
Posts: 11
Joined: Tue Jan 06, 2015 9:01 am

Re: Doorbell Help

Fri Jan 09, 2015 9:14 am

Hi
I'm new to all this GPIO stuff, I was under the impression that this line did the equivalent of that.
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)

If I need to add another resistor in, what does it need to be and in what position?

thanks for all your help so far, it's much appreciated.

Phil

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

Re: Doorbell Help

Fri Jan 09, 2015 9:32 am

phjo wrote:Hi
I'm new to all this GPIO stuff, I was under the impression that this line did the equivalent of that.
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)

If I need to add another resistor in, what does it need to be and in what position?

thanks for all your help so far, it's much appreciated.

Phil
I'm sorry, I didn't read your earlier post well enough.
phjo wrote:I have the output of the optocoupler attached to pin 24 and 26 (so a GPIO and ground
Pins 24 and 26 are both GPIOs (GPIO8 and GPIO7 respectively) try pin 25 (GND). the internal Pullup that you enabled should be sufficient for the task.
Image
Doug.
Building Management Systems Engineer.

phjo
Posts: 11
Joined: Tue Jan 06, 2015 9:01 am

Re: Doorbell Help

Fri Jan 09, 2015 10:17 am

Hi
This is where I get even more confused!
The cables are attached to physical pins 18 & 20 (sorry I didn't make this clear in my first post), but from what I read when I say "GPIO.setmode(GPIO.BCM)" that is saying that physical pin 18 is referenced as GPIO 24 and physical pin 20 is ground.

Is this right?

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

Re: Doorbell Help

Fri Jan 09, 2015 10:26 am

phjo wrote:Hi
This is where I get even more confused!
The cables are attached to physical pins 18 & 20 (sorry I didn't make this clear in my first post), but from what I read when I say "GPIO.setmode(GPIO.BCM)" that is saying that physical pin 18 is referenced as GPIO 24 and physical pin 20 is ground.

Is this right?
Yes, physical pin 18 is GPIO 24. Physical pin 20 is GND.

you had that correct so perhaps the internal pullup was insufficient, try an external pullup instead (connect a 10k resistor to GPIO 24 and 3v3, so that both the 10k resistor and your optocoupler are connected to the same pin.
Doug.
Building Management Systems Engineer.

phjo
Posts: 11
Joined: Tue Jan 06, 2015 9:01 am

Re: Doorbell Help

Fri Jan 09, 2015 10:34 am

OK, Thank you, I'll try that later.

phjo
Posts: 11
Joined: Tue Jan 06, 2015 9:01 am

Re: Doorbell Help

Mon Jan 12, 2015 10:17 am

Excellent, thank you. Adding the resistor has stopped the false alerts coming through.

Is there a reason why this is needed if the Pi has this built in?

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

Re: Doorbell Help

Mon Jan 12, 2015 10:25 am

phjo wrote:Excellent, thank you. Adding the resistor has stopped the false alerts coming through.

Is there a reason why this is needed if the Pi has this built in?
I'm not sure but this thread might offer some guidance:
simplesi wrote:And a 20 cm loose wire in a hostile EM environment might over-come the software pull-ups :(
You might have to use real resistors :)

Simon
I guess the doorbell might be a hostile EM environment, otherwise I'm just not sure why it wouldn't have worked (But I remembered that an external pull-up is often recommended and indeed seems to work).
Doug.
Building Management Systems Engineer.

phjo
Posts: 11
Joined: Tue Jan 06, 2015 9:01 am

Re: Doorbell Help

Tue Feb 17, 2015 12:22 pm

Hi
This was all running well, with no false alerts until I connected some other switches and now I'm back to getting false alerts again. I now have 5 switches (one of which is the doorbell), each with a 10k resistor connected to the +'ve and whichever pin that switch is using.
I've had two thoughts, I either need to decrease the resistor values from 10k to 4.5k or improve the power supply (the pi is currently powered off the USB port of my draytek router which is handy if I need to force the pi to restart but may be a little low on amps).
Do either of these sound a better thing to start with? or something else?

thanks

Return to “Beginners”