TransWikia.com

GPIO to control 12V switch

Raspberry Pi Asked by piaaw on October 5, 2021

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.

2 Answers

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).

Correct answer by joan on October 5, 2021

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.

Answered by Milliways on October 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP