relay problem

my problem is that i put 2 relays on my Arduino Uno and don´t work

i have conected 2 ultrasonic modules, uno temperature module (ds18b20) and tree leds but only one is high at the same time becouse it depends of the mesuring of 1 ultrasonic. thats things works well, but when i put 2 relays they dont work. For example i put a relay on the 8 digital pin of my arduino and when i replace the relay with a led i saw that the code is working but the led turn on very soft

when i saw that i tried to use a 12v source but the result is the same
The relays are designed for 5v and they are normals relays not relay modules

Code:

#include <OneWire.h>
#include <DallasTemperature.h>

OneWire ourWire(2); //Se establece el pin 2 como bus OneWire

DallasTemperature sensors(&ourWire); //Se declara una variable u objeto para nuestro sensor

const int trigPin = 11;
const int echoPin = 12;
const int trigPin2 = 3;
const int echoPin2 = 4;
const int calentador = 8; //relay 1
const int bomba = 9; //relay 2
long duration;
long duration2;
int distance;
int distance2;
int verde = 5;
int amarillo = 6;
int rojo = 7;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(verde, OUTPUT);
pinMode(amarillo, OUTPUT);
pinMode(rojo, OUTPUT);
Serial.begin(9600);
sensors.begin();

}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
Serial.print("distancia1:");
Serial.print(distance);
Serial.print(" cm ");

digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin2, HIGH);
distance2= duration2*0.034/2;
Serial.print("distancia2:");
Serial.print(distance2);
Serial.print(" cm ");

if(distance<6){
digitalWrite(bomba,HIGH);
Serial.println("Cebando...");
delay (10000);
digitalWrite(bomba,LOW);
}

delayMicroseconds(10);

if(distance2 <= 5){
digitalWrite (verde, HIGH);
digitalWrite(rojo, LOW);
digitalWrite(amarillo, LOW);
}

else if(distance2 <= 10){
digitalWrite (amarillo, HIGH);
digitalWrite(rojo, LOW);
digitalWrite(verde, LOW);
}

else {
digitalWrite (rojo, HIGH);
digitalWrite(verde, LOW);
digitalWrite(amarillo, LOW);
}

sensors.requestTemperatures(); //Se envía el comando para leer la temperatura
float temp= sensors.getTempCByIndex(0); //Se obtiene la temperatura en ºC

Serial.print("Temperatura= ");
Serial.print(temp);
Serial.println(" C");
delay(100);

if(temp<70){
digitalWrite(calentador,HIGH);
Serial.print("calentador on");
}

if(temp>=80){
digitalWrite(calentador,LOW);
Serial.print("calentador off");
}

}

The relays are designed for 5v and they are normals relays not relay modules

5V is not the only restriction you have. Each GPIO pin of the Arduino must not be loaded with more than 40mA. Usually relays are above that value so they are triggered over a transistor. As you failed to provide type information for your relays you have to check yourself if they meet this criteria.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

I don't see:

pinMode(calentador, OUTPUT);

pylon:
5V is not the only restriction you have. Each GPIO pin of the Arduino must not be loaded with more than 40mA. Usually relays are above that value so they are triggered over a transistor. As you failed to provide type information for your relays you have to check yourself if they meet this criteria.

I think he already has. The standard "sensitive" 5 V relay requires no less than 80 mA.

Precisely what "the led turn on very soft" means is in itself uselessly vague. Again, what resistor he has used in series is not mentioned and one suspects he has already partially burnt out the output drivers. Or maybe not. :roll_eyes: