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