Electronic – Connecting a 12v relay to microcontroller circuit

atmegadc motormicrocontrollerrelay

I am trying to build an automatic plant watering system using ATmega16. We are using moisture sensor for our project.
The circuit diagram is as follows:

We are using the following 12V relay:

I have no experience of using relay. How I will connect the relay across D1 as shown in the circuit. I mean which pin of relay (there are 5 in total) will be connected to the two terminals of the diode as shown in the above figure and which two pins will be connected to a dc motor so that I can drive a dc motor. And how will I test the relay is working properly using multimeter (before connecting the motor) when I am getting 5v or 0v from PC0 as output?

Best Answer

From the data sheet's wiring diagram, we can figure out the pins. The middle pin is the Common pin. The Top Right pin is the Normally Opened switched pin. The Bottom Right pin is the Normally Closed switched pin. The Top and Bottom pins on the Left are the Relay Coil pins.

enter image description here

The diode would be placed, Cathode to the top pin, Anode to the bottom pin. 12V input would be connected to the top pin, the transistor's Collector to the bottom pin.

To test it out, you would use the multimeter's continuity mode to the common pin and the NO pin. When the relay is turned on (PC0 is High, Transistor is on), there will be continuity across the common and NO pin.