The transistor gets really hot even though I am using a heatsink. Have I connected something wrong?
- Check the wiring of the transistor, its pinout is B-C-E which is not too intuitional. E goes to GND
- TIP120 is a bipolar transistor, dropping 0.7V when it is fully on. Assuming your motor draws like 2A, this is 1.4W of heat, which is hot by design
- In order to reduce wasting power, you can pick a MOSFET instead of this BJT. Pick e.g. IRFU2405 or AP20N15GI-HF - any N channel incremental mosfet will do. Less on-resistance means less power waste. In short, if you pick a MOSFET rated for 40A, it will essentially have no losses at 1-2A and will make no heat at all.
- Note that the MOSFET has to be a logic-level mosfet, i.e. a device which can turn fully on for less than 5V. The types I am suggesting are logic level MOSFETs.
- You don't need a series resistor between Arduino and the G of a MOSFET. However it is a very good idea to use a pulldown resistor of 1K..10K between G and GND. This ensures that the MOSFET is always OFF if the arduino is not driving its outputs (for example during reporgramming the Arduino).
Not related to the original problem:
- Note that the DPDT relay connection is fishy. It is not very likely that you can actually drive a relay coil directly from a port output, so you might wish to use a small bipolar transistor or a small FET to drive the relay coil. Even if you have the relay coil working, remember that you have a protecting diode missing. Similarly as you need diode for the motor, you need a similar protecting diode for the relay coil, otherwise when turning off the relay, the energized coil may destroy the Arduino.