I've made a circuit to control a 5v relay through ESP32 signal. Because the voltage and current from ESP32's digital pin isn't enough to drive the relay so I use an external 8v source and a 2n222 NPN transistor to drive the relay. However, the relay just keeps switching on and off really fast even though the base pin of the transistor isn't connected. Here's the full schematic.
I see an emitter follower, where the voltage on the emitter is always 0.7volt lower than the base. So the relay only gets 3.3volt - 0.7volt = 2.6volt. assuming you have shared grounds.
The relay will also receive rectified AC, so will rattle in the rhythm of twice the AC frequency because you didn't use a smoothing capacitor.
Google something like "relay driver" (images) to see correct circuits.
Leo..
What voltage is that relay.
An 8volt AC source, when rectified and buffered (with a cap) is about 10volt DC.
More if it comes from a lightly loaded transformer.
Leo..
okay i got it to work by using an external ac to dc converter but the relay just keep turning on no matter the signal is HIGH or LOW, even if I disconnect the ESP32 from computer. Here is the datasheet of the 5V relay:
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.
If you power your Esp32 from 5V source, you could use that for the 5V relay as well (switched by the transistor) instead of playing with separate AC source.