Electrical – 12V DC relay control from raspberry pi

relay

my reference circuit

please ignore the lamp and 220vAC supply
when i use 12v DC insted of 5v and changed relay to 12v the circuit doesnt work
how to use the circuit and modify it to work for 12v.
i need to connect and disconnect 2 points(for controlling my 3d printer on and off)

edit:I have connected the circuit exactly like the circuit i have given (i dont really know to use any software to make the circuit so i havent put my original one but its the same!)
changes i made to this circuit
1. changed 5VDC supply to 12VDC supply
2. changed 5VDC relay to 12VDC relay
switched on the supply and relay is always ON i.e the relay gets 12V even if i remove the transistor

so my question is
will this circuit actually work? Can it be made to work for 12VDC supply with 12VDC relay? IF this transistor as switch doesnt work then can anyone suggest a better circuit?
How to calculate the base resistor value?

edit2: i had a bad transistor so now i checked the transistor before using it
enter image description here
note: i used hfe as 75 is that correct value for using 12v source? how to determine that value from datasheet from the graph

Best Answer

Use ~20 for the hFE to ensure the transistor is deep into saturation. The hFE figures stated on the datasheet are for the transistor in the linear mode and not fully switched on.

So your resistor should be 20*(3.2V-0.7V)/0.03A or about 1.7K. Using 1K or 1.5K should be no problem. Check that the output is really giving you 3.2V under load or check specs on the Pi's Broadcom chip if you can find them.

And check that nothing bad is coming from the base of the transistor before wiring it up (you can common the 12v and Pi supply grounds). A wiring mistake could damage the Pi, especially when voltages outside the range of 0..3.3V are involved.