Author Options:

Arduino Uno Relay circuit Answered

I am currently involved in a project that requires me to run a fan heater through coding in an arduino.
I have decided to use a relay to act as a switch, to maintain the time period of heater running.
I am using a DOAT 5V 20mA relay.
I was wondering if anyone could help me with the circuit needed using a n-p-n transistor to power it while maintaining switch function.

I know a circuit similar to the one below is needed, but im not sure about the capacitor and resistance values needed for a 5v, 20mA relay.

5 Replies

RoshanC1 (author)2015-05-28

Thank you for the replies.
It is a heater working on AC. I have decided to go with the relay, connected to a transistor circuit to the arduino. It helps with powering the relay, which is connected in parallel to a diode.
My current issue is that the relay is not switching at the given limit.
My code is here :

#include <LiquidCrystal.h>

int reading = 0;

int sensorPin = A0;

int relay =7;

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

// set up the LCD's number of columns and rows:

lcd.begin(16, 2);



void loop() {

reading = analogRead(sensorPin);

int celsius = reading/2;

lcd.setCursor(0, 0);

lcd.print("Temperature: ");


lcd.print(celsius, DEC);



if (celsius<38) {


} else {







Could anyone please help me out with what the issue is ?.
I am using an LM35 temperature sensor which is connected to port A0 on the arduino.
The relay gets it signal from port 7 on the arduino.

Select as Best AnswerUndo Best Answer

gmoon (author)RoshanC12015-05-30

Does the code work if you substitute an LED and resistor for the relay? (simplify the hardware for testing)

Does it toggle the relay (or indicator) at all? (at a different temperature, for instance)

I.E., break the problem down into separate parts...

Select as Best AnswerUndo Best Answer

Antzy Carmasaic (author)2015-05-28

You haven't mentioned if it is a heater working on AC or DC? For high voltages or current in either case, I suggest to sticking with relays. They are easier and safer. If you still want to use a transistor, you'll have to find out all the things gmoon pointed out. Knowing the current and voltage draw of the heater are neccessary.

Select as Best AnswerUndo Best Answer

gmoon (author)2015-05-27

Look to a tutorial such as this one.

You cannot do this without:

--a meter to figure out the current draw of the relay.

--the math!

--that "flyback diode," which protects the transistor from inductive spikes (the relay is an inductor).

BiJ transistors are current in-current out devices. Since the load (relay) is different for each instance, each setup is different. But it's not rocket science, either. The math is pretty simple.

Select as Best AnswerUndo Best Answer

gmoon (author)gmoon2015-05-27

Hey Instructables--I posted this twice, and the links didn't work either time.

OP, here's the link:


Select as Best AnswerUndo Best Answer