Arduino trouble

Hello, could someone help me or has it happened to you?

It turns out that in the arduino I have two sensors, a DHT11 and a LDR sensor. And due to two conditions they activate some actuators.

  1. If the temperature reaches 24 degrees a fan is activated.
  2. If the brightness reaches 350 lux a light is activated.

The thing is that when the actuators must be activated (when they reach the desired level), what they do first is like blinking, that is to say, they turn on and off, until after a moment they manage to stabilize at the desired point. This is not PID control or anything.

This in arduino may not bother, however, taking it to real life can be cumbersome. Can someone tell me what it is?

Translated with DeepL Translate: The world's most accurate translator (free version)

Read up on hysteresis

1 Like

Example code (test code) is intended to just demonstrate; not become production quality. You need to enhance by making the software compliant with real world conditions.

Maybe add averaging, time delay, on for "x" seconds before "On" state notification, etc.

It may be, actually I only have the IF conditioner, but I really don't know what it could be.

One would like that when the temperature reaches 24 degrees C the fan is activated immediately. But it's not like that, first "play (on-off)" around the desired value (24 degrees)

Show your circuit and your code.

You can easily achieve such behavior, but somewhere the concept of hysteresis must be applied: up-swing or down-swing:

hysteresis

  1. The lagging of an effect behind its cause, as when the change in magnetism of a body lags behind changes in the magnetic field.
  2. A lagging of one of two related phenomena behind the other.
  3. A lagging or retardation of the effect, when the forces acting upon a body are changed, as if from velocity or internal friction; a temporary resistance to change from a condition previously induced, observed in magnetism, thermoelectricity, etc., on reversal of polarity.

Turn fan on when the temperature goes over 25. Then turn it off when temperature goes under 23.

No. However, when you reach a desired point (whatever it may be), the same thing happens. Even if it is within a range.

Now, how to do that in arduino? hahahaha.

//Codigo INVERNADERO AUTOMATIZADO.

//Estas librerias son necesarias para trabajar con el sensor DHT11 y el LCD con su modulo I2C.
#include <LiquidCrystal_I2C.h> //Libreria DISPLAY con modulo I2C.
#include <Wire.h>
#include <DHT.h> //Libreria DHT11.

//Estas librerias se usan para ocupar el sensor digital DS1820B.
#include <OneWire.h>
#include <DallasTemperature.h>

//Crear el objeto LCD dirección 0x3F y 16 columnas x 2 filas
LiquidCrystal_I2C lcd(0x3f,16,2); //Ya no es necesario determinar todos los pines.

//OBSERVACION: La dirección I2C del 8574 en proteus es 0x20

//Simulacion en software: LiquidCrystal_I2C lcd(0x20,16,2).

//Simulacion en hardware: LiquidCrystal_I2C lcd(0x3f,16,2).

//DEFINIMOS LOS PARAMETROS PARA DHT11
#define DHTPIN 12 // Pin donde se conecta el sensor.
#define DHTTYPE DHT11 // Dependiendo del tipo de sensor.

int temp,humedad; //Humedad y temperatura se definen como enteros.
int ventilador = 13; //Ventilador se define como entero y asignamos un pin (IN1 del relé)
int umbral = 24; //Umbral se designa como entero (umbral es una condicionante que activa el ventilador)
DHT dht(DHTPIN, DHTTYPE); // Inicializamos el sensor DHT11

//DEFINIMOS LOS PARAMETROS PARA SENSOR ANALOGICO DE LUMINOSIDAD LDR
int LEDPin = 11; // PIN digital donde se concecta el LED que se encendera o apagara dependiendo del sensor.
int LDRPin = A0; // PIN analogico donde se ubica el sensor LDR

//DEFINIMOS LOS PARAMETROS PARA DS18B20
#define Pin 7 //Se declara el pin donde se conectará el sensor
OneWire ourWire(Pin); //Se establece el pin declarado como bus para la comunicación OneWire
DallasTemperature sensors(&ourWire); //Se llama a la librería DallasTemperature

void setup() {

Serial.begin(9600); // Inicializamos comunicación serial con el puerto COM_6.
dht.begin(); // Comenzamos el sensor DHT.
lcd.init(); //Iniciamos el LCD.
lcd.backlight(); //Encender la luz de fondo
pinMode(LEDPin, OUTPUT); // Define LED como salida del sensor LDR.
pinMode(ventilador, OUTPUT); //Se define el ventilador como salida.
sensors.begin(); //Se inicia el sensor 1

delay(1000);

}

void loop() {

////////////////////////////DHT1: HUMEDAD Y TEMPERATURA. SE ACTIVA O APAGA EL VENTILADOR////////////////////////////

temp = dht.readTemperature();
humedad=dht.readHumidity();

Serial.print("Temperatura ambiente: "); //Escribe en el monitor serial.
Serial.print(temp);
Serial.println("ºC");
Serial.print("Humedad relativa: ");
Serial.print(humedad);
Serial.println("%");

lcd.setCursor(0,0);
lcd.print("T:"); //Escribe en el LCD.
lcd.print(temp);
lcd.print("C");

lcd.setCursor(6,0);
lcd.print("H:");
lcd.print(humedad);
lcd.print("%");

if(temp >= umbral){
digitalWrite(ventilador,HIGH); //En proteus ir HIGH aqui.
Serial.println("Ventilador encendido");
lcd.setCursor(0,1);
lcd.print("Ventilador ON");
}

if(temp < umbral){
digitalWrite(ventilador,LOW); //En proteus debe ir Low aqui.
Serial.println("Ventilador apagado");
lcd.setCursor(0,1);
lcd.print("Ventilador OF");
}

delay(4000);

///////////////////LDR: SE ENCIENDE O APAGA UN LED DEPENDIENDO LUMINOSIDAD: LUXIMETRO////////////////////

int ldr = analogRead(LDRPin);                     //Definimos el sensor LDR analogico en el pin A0.

if (ldr >= 350 && ldr < 990) {                    //El sensor LDR mide de 0 a 1000, donde 1K es la intensidad de luz maxima.
digitalWrite(LEDPin, LOW);
Serial.print("Intensidad luminica media-alta: ");
Serial.print(ldr);
Serial.println(" Lux");
Serial.println("LED OF");

}

else  {
digitalWrite(LEDPin, HIGH);
Serial.print("Intensidad baja: ");
Serial.print(ldr);
Serial.println(" Lux");
Serial.println("LED ON");

}

/////////////////////DS18B20: SENSOR QUE MIDE LA TEMPERATURA DE UN LIQUIDO X//////////////////////////////

sensors.requestTemperatures(); //Se envía el comando para leer la temperatura
int temp1= sensors.getTempCByIndex(0); //Se obtiene la temperatura en ºC del sensor
Serial.print("Temperatura H20: ");
Serial.print(temp1);
Serial.println(" C");
delay(500);

}

You know how to read the temperature
You know how to turn on the fan
You know how to turn off the fan

Do you know how to test the value of the temperature ?

YES, i know.

Then you know everything required to do what @mrburnette suggested to implement hysteresis

Often new experimenters underestimate that they are walking a well-worn path of those who have struggled before them:
https://create.arduino.cc/projecthub/pandhoit/arduino-temperature-control-397dad

The system starts and shows the temperature, if the temperature reaches 25 degrees, then the green led is activated and the room starts to cool until the temperature drops to 23 degrees, the air conditioner turns off (red led) until the temperature rises again.

https://www.google.com/search?q=arduino+add+hysteresis+to+temperature+controller

More reading material to broaden knowledge:

PDF Industrial Temp Controller

Please edit the post with your code, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.

Hi,
Have you built your project in the real world OR are you running in a simulation?

What is your native language?

Thanks... Tom... :grinning: :+1: :coffee: :australia:

Hello, if I have simulated it real. There this happens to me

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.