Need assistance designing transistor circuit for raspberry pi?

I'm trying to use the GPIO pins in my raspberry pi to drive a relay. I have a 12 volt rechargeable battery (12.0 AH) and a 12 volt relay, along with a 2N2222 NPN transistor. I built a simple transistor switch circuit by using the 12V battery positive to a resistor (R1) followed by the relay coil and a diode... show more I'm trying to use the GPIO pins in my raspberry pi to drive a relay. I have a 12 volt rechargeable battery (12.0 AH) and a 12 volt relay, along with a 2N2222 NPN transistor. I built a simple transistor switch circuit by using the 12V battery positive to a resistor (R1) followed by the relay coil and a diode at the collector, and connected the grounds and the emitter of the transistor. I've discovered that without anything connected to the base, the relay still trips if the battery is fully charged. Once the battery discharges a bit the circuit seems to work (GPIO plus R2 at the base turns on the relay). I've attempted to vary the value for R1 but 10K is too much (relay won't trip at all) and 5K is too little (relay always tripped regardless of base). And the charge level in the battery seems to affect this circuit. The relay is 12V.

Any suggestions for this? Thanks so much!
Update: Here's the circuit I'm using (to the best of my abilities with ASCII): +12V from battery ----- Resistor R1 -- Relay Coil ----- Collector of NPN transistor Diode -|<--- tied to relay coil terminals +3.3V GPIO ----- Resistor R2 ----------------------------- Base of NPN transistor Ground of... show more Here's the circuit I'm using (to the best of my abilities with ASCII):

+12V from battery ----- Resistor R1 -- Relay Coil ----- Collector of NPN transistor
Diode -|<--- tied to relay coil terminals
+3.3V GPIO ----- Resistor R2 ----------------------------- Base of NPN transistor

Ground of 12V tied with Ground of Raspberry Pi ---- Emitter of NPN transistor


Relay I'm using: https://www.jameco.com/Jameco/Products/ProdDS/2167453.pdf
Jameco part number: 2167453

Hopefully the formatting of this post don't get messed up when I submit. Thanks so much for the help.
2 answers 2