-3

I am trying to automate our front gate. The gate is operated by a 12V remote control. My idea is to get the Raspberry Pi to press the button and automate this.

Working towards this I have connected a 6V battery pack to buzzer through a battery to duplicate the functionality of the remote.

This simple circuit worked. You can press the button and the buzzer sounds.

I added an S9013 transistor across the switch and connected the base to the Raspberry Pi through a 10KΩ resistor.

Here is my circuit diagram:

enter image description here

I have got a simple piece of code running.

import RPi.GPIO as GPIO
import time
 
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
 
while True:
    GPIO.output(18, True)
    time.sleep(1)
    GPIO.output(18, False)
    time.sleep(1)

This should cause the buzzer to beep each time the output goes HIGH.

I have reworked the example to flash an LED. This worked so I know the GPIO pin is correct.

enter image description here

enter image description here If I short the collector to the emitter, the buzzer will sound.

What could I be doing wrong?

Update: Tying the Raspberry Pi GND to the GND of the batteries fixed it.

  • 1
    Perhaps you are not using GPIO 18 in your wiring. A photo of your connections will help. – joan Jul 19 at 11:14
  • 2
    Running a buzzer (or indeed anything) with an emitter follower is a recipe for disaster. It probably won't work, and is likely to melt the transistor. If you want to do this see elinux.org/RPi_GPIO_Interface_Circuits. Even if you got the circuit right this code will just buzz every second. – Milliways Jul 19 at 12:09
  • @joan I am using GPIO18. If I change this to flash the LED with the same code it works. Please see the attached photos. – piaaw Jul 19 at 16:15
2

Your circuit is missing a ground connection from the Pi. You need a common reference so that the circuit can tell the difference between GPIO high and GPIO low.

Connect a Pi ground pin to the circuit ground (e.g. the -ve of the battery).

| improve this answer | |
  • I have now replaced the buzzer with the final gate remote and gone to a 12V battery. It sort of works, but the key fob LED is dimly lit all the time and when the transistor is activated the LED flashes rather than comes on solid as expected. If I wire out the transistor then the LED behaves as expected. Do I need to add any extra resistors? New wiring diagram shown in main question. Thanks – piaaw Jul 19 at 22:18
1

What you need to do is wire the transistor correctly!

Connect the load in the collector circuit as suggested https://elinux.org/RPi_GPIO_Interface_Circuits

What you have will put ~2.7V across the load - the remaining voltage will be across the transistor and be dissipated as heat!

NOTE the S9013 is an NPN transistor - your schematic shows PNP.

| improve this answer | |

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.