0

schematic

simulate this circuit – Schematic created using CircuitLab

I have a script that sends me a firebase notification when the doorbell is pressed. It was working fine when it was on the breadboard. After connecting the project to the doorbell it was randomly sending notifications.

So i've stripped the project back and I think it's something on the Pi as I currently just have a wire on GPIO18 and Ground so i can simulate a button press. However the button press is triggered by simply touching the wire or when another wire is attached to the GPIO pin.

I've got my script below:

from os import system, name
from pyfcm import FCMNotification
import json
from firebase import firebase
import RPi.GPIO as GPIO
import time
from datetime import datetime
import calendar


buttonPin = 18
chimePin = 22

GPIO.setmode(GPIO.BCM)

GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(chimePin, GPIO.OUT)

push_service = FCMNotification(api_key="MY_API_KEY")

def send_fcm_messages(reg_ids, body):
        try:
                results = push_service.notify_multiple_devices(registration_ids=reg_ids, message_title='Ding Dong', message_body=body)
        except pyfcm.errors.FCMServerError as e:
                 time.sleep(0.5)
                results = send_fcm_messages(reg_ids, body)
         i = 0
         for k,v in results.items():
                if k == "failure":
                        if v == 1:
                                print("remove device")
                                f.delete('/devices', reg_ids[i])
        i += 1
        return results

while True:
    input_state = GPIO.input(buttonPin)
    if input_state == False:
        GPIO.output(chimePin, GPIO.HIGH)
        time.sleep(0.1)
        GPIO.output(chimePin, GPIO.LOW)
        system('clear')
        d = datetime.utcnow()
        unixtime = calendar.timegm(d.utctimetuple())
        url = 'https://my-firebase-url'
        f = firebase.FirebaseApplication(url, None)
        # your variables are already assigned before this
        data = str(unixtime)
        f.put("/dings/", data, data)
        dateTimeStr = datetime.fromtimestamp(unixtime).strftime('%a %d/%m/%Y %H:%M:%S')
        devices = f.get('/devices', None);
        reg_ids = list()
        for k,v in devices.items():
                reg_ids.append(k)
        result = send_fcm_messages(reg_ids, dateTimeStr)
        print('Doorbell Pressed ' + dateTimeStr)

Door Chime Circuit:

Chime circuit front Chime circuit back

  • Your circuit suggests a 9V chime - where is the 9V coming from? It looks like its connected to ground? – CoderMike Nov 4 '18 at 11:54
  • @CoderMike I've updated the schematic.. hope it helps – jampez77 Nov 4 '18 at 12:02
  • Your schematic makes no sense. No voltage is ever applied to the speaker, and there is no common ground between 9V and 5V parts of your circuit. – Dmitry Grigoryev Nov 6 '18 at 7:46
1

The most likely reason is that the internal pull-up on the button GPIO is not strong enough to counteract the aerial effect of the connected wire.

The internal pulls are about 50k ohm. A wire acts like an aerial and radio pulses can generate a train of pulses. Try using a 10k ohm external resistor between the button GPIO and the 3V3 rail.

  • Thanks for the answer. I've tried your suggestion and it doesn't appear to work. I think you might have a point with radio pulses as when I put the wire on my floor it is constantly activated but if i sit it on the table it's ok. This is with a 10K resistor just before the switch – jampez77 Nov 4 '18 at 13:21
0

I'm not sure your circuit is right. Is the collector of the transistor really connected to ground? If so I don't see how it ever turns on. Not that it would cause the problem you have, but I think there may be some issue with power supplies and grounding. Can you be more specific about how the chime and USB power supplies are wired? And how the chime works - or a link to the manufacturer's data sheet.

  • Thanks for your answer. You're probably right about the schematic being wrong as i've never really made one before and that part of the circuit is working fine. I can't find any info on the door chime (will keep looking). The best I can do is add a photo of it (see updated answer) – jampez77 Nov 4 '18 at 17:02
  • This isn't really an answer. You should take attention that it will not be down voted. You should use comments to ask for clarification. – Ingo Nov 8 '18 at 9:59
-1

What happens id you remove everything except the pusbutton and the wires from it ground and the gpio pin? Do you still have a problem with false alerts? If so, then it seems the wiring IS picking up RF interference. A small capacitor (100nF) wired across the pushbutton ought to kill that. Once have you solved this simple arrangement you can move on to the chime circuit.

  • I have stripped it back and tried it with just the push button wired up and it's still the same. Originally i was using some solid core wires for the switch but after repurposing an old USB cable with a ferrite ring the false alerts are significantly reduced. Would this make sense if it is RF intererence? – jampez77 Nov 4 '18 at 17:56
  • 1
    Yes, I guess that makes sense. What did you do with the outer shield of the USB cable? I would use the power wires (red & black) for your pushbutton, and ground the outer shield ONLY at the PI end. That should kill any interference. Didiyou try a capacitor? – Andrew Malcolm Nov 5 '18 at 5:11
  • Currently the outer shield is just floating. I will try and see if grounding makes an impact. I have yet to try the capacitor yet as I don't have any. I've ordered some that should be here in a few days all going well. – jampez77 Nov 5 '18 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.