Drive relay with AVR microcontroller

To drive the relay, you need more than 20mA – the current can help one pin drive. This is why you cannot connect the relay directly to the pin of the microcontroller. To drive the relay, you need to connect a simple amplifier made of one transistor. One important part of this circuit is the diode, which protects the circuit from induction caused when switching the relay.