How to control 12 V with Arduino's 5 V pins?
You probably didn't limit the current passing through the transistor.
Your goal is achieved by a simple &quot;inverter&quot; topology.

(Image source: California Polytechnic State University, EE307, Fall Quarter 2003, MoHAT Projects, Group 2)
Where Vin is your 5V pin and VCC is the 12V source. Rc avoids a very large current passing through the transistor. Please note that (as in all inverters) when the input is high, the output will be low, as the current passes through Rc causing a voltage drop. Similarly, when the input is low, the output will be high, as no current passes through the resistor and there is no voltage drop.