the thing is that everything works fine when I control 1 relay, but controlling both relays at the same time is not working for me. Both relays behave in the same way in my sketch, and when one is ON, the second should be ON as well, but this doesnt happen. While one of them is ON, the other one is OFF and the indicator led for this relay that is OFF, is blinking very weakly at the same pace as the RX led in the arduino.
somebody sees the mistake?
#include "DHT.h"
#define threshold 22 //Setting the temperature threshold
#define DHTPIN 13 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
const int relay1 = 8; // the number of the relay 1 pin
const int relay2 = 9; // the number of the relay 2 pin
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
delay(1000);
Serial.begin(9600);
dht.begin();
delay(1000);
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
if (t < threshold){
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
}
else
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
}
}
With both relays energized, it will draw about 200mA total, (90mA for coil, 10mA fir IRLED driver)x2.
A separate supply will prevent thermal overload of your Arduino's regulator.
Not sure what the exact figure would be - it's highly dependent upon the voltage at Vin. If Vin is lowered (i.e. 7.5V) then more current will be available than with 9 or 12VDC. See reply#3.
ok. I found now some people saying that 450ma should be available when powering the UNO via usb. I am using a 12V 1A power supply, so I think I am pretty safe with the relays using 200ma
It's more than the current rating, it's the power rating you should be following.
If you are drawing 200ma with 12v -.7 input, the power is 2.3 watts.
The regulator will run HOT.
Edit Plus there is power from other circuit components . . .
.
terry's link does a great job!
Read his section on "Powering an Arduino".
Remember there is power consumed: on the Arduino board, your relays and any other electronic components in your circuit.