Hi guys, I'm trying to use the Arduino Beginner Kit (DFRobot Starter Kit for Arduino with 15 Arduino Projects Tutorial - DFRobot) to simply create a fan that turns on and off based on temperature. I can already measure the temperature and have a buzzer to beep when it hits a certain level, I'm just having trouble with the relay (I'm not very good with electronics).
Basically I can't simply just turn the relay off and on to turn the fan off and on. Obviously I just want the relay to provide power when temp > xx else off sort of thing.
LOW is meant to turn the relay off, correct? Well it stays on, and when I change the value to HIGH, it turns off after 3 seconds or so and makes a click sound, I'm assuming potentially shorting?
How are you driving the relay, directly from the UNO output pin?
If so then you are overloading the pin. You need to include a transistor to switch the relay coil.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
The OPs pic.
That picture of the setup is far too small. Rather post a scan / photo of a hand-drawn one.
But looking at that picture, you're in the process of blowing up your Arduino. You should not directly control a relay from the Arduino; use a transistor or something like that. It also looks like you're missing a flyback diode.
And don't use stupid images to post code but post here using code tags
Thanks for the responses, I'm afraid me trying to draw the setup will just make it more confusing since I'm so new to this, so I've removed everything but how the fan is setup. Hopefully this is fine.
I believe I am driving the relay directly from the output pin? Do you believe that's the issue? How should I setup the transistor?
Usually driving a relay directly is very unhealthy.
Now this might be a special relay; I followed the product link that you gave and eventually ended on the page for motor fan and it seems to be possible to use this relay directly (if dfrobot did not make mistakes).
Looks like you followed that guide and I can not immediately spot a mistake.
Thanks, I'm pretty sure the guide says HIGH = on and LOW = OFF but now that I've isolated my setup, LOW is on and HIGH is off. I've tested this with delays to turn off and on and it seems fine. I'm just worried now that I might accidentally short the board.
Alright I believe I've gotten it working for the most part, the only issue now I believe is the code.
float sinVal;
int toneVal;
unsigned long tepTimer;
int relayPin = 3;
int relayState = HIGH;
void setup(){
pinMode(8, OUTPUT);
Serial.begin(9600);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, relayState);
}
void loop() {
digitalWrite(3, HIGH);
int val;
double data;
val=analogRead(0);
data = (double) val * (5/10.24); //convert voltage to temperature
if(data>21){
digitalWrite(3, LOW);
}
if(data>35){ //if temperature greater than xx
for(int x=0;x<180;x++){
sinVal = (sin(x*(3.1412/180)));
toneVal = 2000+(int(sinVal*1000));
tone(8, toneVal);
delay(2);
}
} else {
noTone(8);
}
if(millis() - tepTimer > 50){
tepTimer = millis();
Serial.print("temperature: ");
Serial.print(data);
Serial.println("C");
}
}
I only want the fan to turn on when the temperature is > 21 (if statement in the loop) however that's not working at the moment. At the moment the sensor and the alarm are working with that code, just not the fan.
Hi,
Does the alarm, buzzer work in place of the motor, that is get the relay to tuen the motor on and off.
If you are powering the motor with the UN 5V, again a no no, and you should have a protection diode across the fan motor to prevent any damage to the UNO.
Tom...
Please Attach your pictures as files, if you use REPLY rather than QUICK REPLY you will find an ATTACHMENT facility.
Hi,
I managed to find the spec for that relay, 125R at 5V = 40mA, just on the limit of the UNO output, also it does not have a protection diode on the relay coil, so this may be causing your problem.