I am trying to make a smart plug that activates a relay when it receives a certain message via MQTT. It works, but the Pi shuts down randomly, both when the relay is active and when everything is just idling. It seems to happen more often when it's active, but I haven't really kept track of it.
Here is the circuit:
When an MQTT message within a certain range is received, GPIO27 is set to high, which activates the gate on the transistor (2SC9013), completing the circuit to the solid state relay (Fotek SSR40 DA). There is an LED connected to the TX pin for a status light, and a shutdown button that uses the script provided by Howchoo.
I'm running off a clean install of Buster lite. The Pi is a wifi hotspot that I set up using the rasberrypi.org doc. Besides that, the only other things running are a mosquitto broker, my Python relay script, and the power button script.
Troubleshooting:
Google says that the two most common causes for this problem are overheating and power supply problems.
I started logging the temperature and checking CPU usage with top. Temp floats around 46C and CPU usage occasionally spikes to 20%, but mostly stays around 1%.
Everything is sealed up with shrink tubing and the only place I can access the incoming power is the lugs on the SSR. Voltage consistently levels out at 4.86V from around 4.7V when the relay is activated. I got the same reading even on one of the instances where the Pi shutdown.
There are no errors in syslog. When the Pi shuts down, it has time to shutdown some services, but it doesn't look like it shuts down as many as it does during a regular shutdown. I can post the log info, but it is about 50 lines long. The log entry before the shutdown ones occurs much earlier and doesn't seem to be related.
I thought maybe the power-off script was being triggered somehow, so I added logging to that, but it doesn't log anything unless I actually press the button.
I also tried redoing the whole project on another SD card. Same results.
Questions:
The obvious culprit here is the power supply. I know cell phone chargers are not stable, but I'm need something small. If I am reading 4.86V, is that what the Pi is really getting, or is a voltage dip possibly causing the shutdown?
I chose that transistor mostly because that is what I had lying around. Could the transistor be the problem?
Or, is there something else I am missing completely?
Thanks for any suggestions.