96Views5Replies

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.

Discussions

0
None
RoshanC1

3 years ago

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);

pinMode(relay,OUTPUT);

}

void loop() {

reading = analogRead(sensorPin);

int celsius = reading/2;

lcd.setCursor(0, 0);

lcd.print("Temperature: ");

lcd.setCursor(0,1);

lcd.print(celsius, DEC);

lcd.print((char)223);

lcd.print("C");

if (celsius<38) {

digitalWrite(7,HIGH);

} else {

digitalWrite(7,LOW);

}

delay(500);

lcd.clear();

}

===========================================================

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.

0
None
gmoonRoshanC1

Reply 3 years ago

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...

0
None
Antzy Carmasaic

3 years ago

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.

0
None
gmoon

3 years ago

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.