I have setup a basic circuit to control a relay using a Raspberry Pi 4B. I have tried controlling it with both a push button and the Bluedot app. When implementing with the push button, the GPIO pins output 3.25V and the circuit works perfectly. However, when using Bluedot and changing nothing except for the main loop in the python script, the GPIO pins suddenly output 1.8V. Not enough to activate the transistor to the relay unless I drop the resistor value from 22k to 4.7k. I need to implement other hardware though and cannot rely on the pins outputting 1.8V. If I run both scripts simultaneously, the voltage is 2.6V with the button and somehow -1.6V with bluedot.
The code when using the button:
#Import GPIO and time library
import RPi.GPIO as GPIO
import time
#Set mode for pin numbering
GPIO.setmode(GPIO.BOARD)
#Define pins and configure data direction
button = 36
relay = 16
def setup():
GPIO.setup(relay, GPIO.OUT)
GPIO.setup(button, GPIO.IN, pull_up_down = GPIO.PUD_UP)
#Monitor button status. Relay goes high for 4 seconds when button is pressed
def loop():
while True:
if GPIO.input(button) == GPIO.HIGH:
print("Door Open")
GPIO.output(relay, GPIO.HIGH)
time.sleep(4)
else:
print("Door closed")
GPIO.output(relay, GPIO.LOW)
time.sleep(0.1)
def destroy():
GPIO.cleanup()
def main():
setup()
try:
loop()
except KeyboardInterrupt: # press Ctrl + C to exit script
destroy()
if __name__ == '__main__':
main()
The code when using Bluedot:
import RPi.GPIO as GPIO
import time
from bluedot import BlueDot
#Import BlueDot
bd = BlueDot()
GPIO.setmode(GPIO.BOARD)
relay = 16
led = 12
def setup():
GPIO.setup(relay, GPIO.OUT)
GPIO.setup(led, GPIO.OUT)
#Relay is active while button is held down
def loop():
while True:
bd.wait_for_press()
GPIO.output(relay, GPIO.HIGH)
GPIO.output(led, GPIO.HIGH)
print("blue button pressed")
time.sleep(0.1)
bd.wait_for_release()
GPIO.output(relay, GPIO.LOW)
GPIO.output(led, GPIO.LOW)
print("blue button released")
time.sleep(0.1)
def destroy():
GPIO.cleanup()
def main():
setup()
try:
loop()
except KeyboardInterrupt: # press Ctrl + C to exit script
destroy()
if __name__ == '__main__':
main()
The circuit diagram with the resistor (R_B=((V_Pi-0.6) h_FE)/I_RC):
simulate this circuit – Schematic created using CircuitLab
Thanks.