Buongiorno a tutti.
Premetto che sono alla prime armi nel mondo arduino, quindi perdonatemi se dirò fesserie.
Sto cercando di sviluppare un piccolo progetto per la gestione di una termostufa collegata al riscaldamento e all'impianto sanitario di casa mia.
Leggo 2 temperature tramite ds18b20, le visualizzo su un lcd 20x4 e con un relè gestisco le varie pompe collegate all'impianto.
Avevo già avuto un problema di disturbi sul lcd, che avevo poi risolto grazie al vostro aiuto con uno snubber in parallelo ai carichi.
Qualche setimana fa però mi accorgo che LPO che utilizzo per alimentare esclusivamente il modulo relè comincia a darmi tensioni sempre più basse man mano che le bobine si "eccitano" arrviando a 3 volt con 4 rele accesi.
https://it.aliexpress.com/item/32896697400.html?spm=a2g0s.9042311.0.0.11b44c4dV7Zbu
Decido quindi di provare un altra strada installando un concertitore cc isolato
ora sembra funzionare tutto fin quando non si attiva la seconda bobina a questo punto la scheda impazzisce e mi eccita anche i rimaneti 2 rele collegati.
immagino quindi che si tratti del solito problema di disturbi.
quindi la mia domanda è potrebbe essere utile un altro filto antidisturbo lato cc?
se si quale?
vi posto il codice che sto utilizzando.
grazie in aticipo per le risposte.
#include <MAX6675_Thermocouple.h>
#include <SmoothThermocouple.h>
#include <Thermocouple.h>
#include <Wire.h>
#include <PCF8574_HD44780_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Address 0x27, 16 chars, 2 line display
PCF8574_HD44780_I2C lcd(0x27,20,4);
unsigned long previousMillislcd = 0; // Utilizzata per memorizzare il tempo del ciclo precedente
const long intervallcd = 1000; // Tempo in millisecondi utilizzato per fare refresh schermo
unsigned long previousMillisricircolo = 0; // Utilizzata per memorizzare il tempo del ciclo precedente
const long intervalricircolo = 40000; // Tempo in millisecondi utilizzato per fare ripartire pompa ricircolo
#define ONE_WIRE_BUS 0 // Data wire is plugged into port 9 on the Arduino
#define precision 10 // OneWire precision Dallas Sensor
int sen_number = 0; // Counter of Dallas sensors
#define COLS 20
#define ROWS 4
#define SCK_PIN 10
#define CS_PIN 9
#define SO_PIN 8
/**
Smoothing factor of a temperature value.
*/
#define SMOOTHING_FACTOR 5
char lcdBuf[COLS];
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
DeviceAddress T1, T2, T3, T4, T5, T6, T7, T8; // arrays to hold device addresses
Thermocouple* thermocouple = NULL;
void setup(void)
{
lcd.init(); // LCD Initialization
lcd.backlight(); // Backlight ON
lcd.clear(); // Clear the display
lcd.setCursor(0,0); // Set the cursor to col 0, row 0
lcd.print("Hello"); // Print the first word
lcd.setCursor(0,1); // Set the cursor to col 0, row 1
lcd.print("World!"); // Print the second word
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
Serial.begin(9600); //Start serial port
Serial.println("Dallas Temperature IC Control Library");
Thermocouple* originThermocouple = new MAX6675_Thermocouple(SCK_PIN, CS_PIN, SO_PIN);
thermocouple = new SmoothThermocouple(originThermocouple, SMOOTHING_FACTOR);
// Start up the library
sensors.begin();
// locate devices on the bus
Serial.print("Found: ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" Devices.");
// report parasite power requirements
Serial.print("Parasite power is: ");
if (sensors.isParasitePowerMode()) Serial.println("ON");
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
// zero pad the address if necessary
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
}
// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
Serial.print("Temp : ");
Serial.print(tempC);
Serial.print(" Celcius degres ");
// Serial.print(" Temp F: ");
// Serial.print(DallasTemperature::toFahrenheit(tempC));
}
// function to print a device's resolution
void printResolution(DeviceAddress deviceAddress)
{
}
void printData(DeviceAddress deviceAddress)
{
Serial.print("Device Address: ");
printAddress(deviceAddress);
Serial.print(" ");
printTemperature(deviceAddress);
Serial.println();
}
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature request to all devices on the bus
Serial.print("Reading DATA..."); sensors.requestTemperatures(); Serial.println("DONE");
// print the device information
for (int k =0; k < sensors.getDeviceCount(); k++) {
Serial.print("Sensor "); Serial.print(k+1); Serial.print(" ");
if (k == 0) { printData(T1);
} else if (k == 1) { printData(T2);
} else if (k == 2) { printData(T3);
} else if (k == 3) { printData(T4);
} else if (k == 4) { printData(T5);
} else if (k == 5) { printData(T6);
} else if (k == 6) { printData(T7);
} else if (k == 7) { printData(T8);
}
}
if (sen_number == sensors.getDeviceCount()) {
sen_number = 0; // reset counter
}
float tempandata = sensors.getTempC(T1);
float tempritorno = sensors.getTempC(T2);
const double tempfumi = thermocouple->readCelsius();
//comando relè devitore
if (sensors.getTempC(T1)>(70)){
digitalWrite(4,HIGH);
}
else digitalWrite(4,LOW);
//pompa ricircolo
unsigned long currentMillisricircolo = millis();
if(tempfumi<60){
if((sensors.getTempC(T1))>=(sensors.getTempC(T2)+6)){
digitalWrite(1,HIGH);}
else if((sensors.getTempC(T1))<(sensors.getTempC(T2)+4)){
digitalWrite(1,LOW);}
else if((sensors.getTempC(T1))>=84){
digitalWrite(1,HIGH);}}
else if (tempfumi>=60) {
if((sensors.getTempC(T1))>=(sensors.getTempC(T2)+3))
digitalWrite(1,HIGH);
else if((sensors.getTempC(T1))<(sensors.getTempC(T2)+2)){
if (currentMillisricircolo - previousMillisricircolo >= intervalricircolo) {
if((currentMillisricircolo - previousMillisricircolo) <= (intervalricircolo+10000)){
digitalWrite(1,HIGH);}
else{
previousMillisricircolo = currentMillisricircolo;
digitalWrite(1,LOW);}}}}
//pompa giorno
if (sensors.getTempC(T1)>90)
digitalWrite(3,HIGH);
else if((tempandata>84)&&(tempritorno>80))
digitalWrite(3,HIGH);
else {
if((sensors.getTempC(T1)<81)||(sensors.getTempC(T2)<78))
digitalWrite(3,LOW);
}
//pompa acqua sanitaria
if (sensors.getTempC(T1)>90)
digitalWrite(2,HIGH);
else if ((sensors.getTempC(T1)>80)&&(sensors.getTempC(T2)>77))
digitalWrite(2,HIGH);
else {
if((sensors.getTempC(T1)<78)||(sensors.getTempC(T2)<75))
digitalWrite(2,LOW);
}
//lcd
unsigned long currentMillislcd = millis();
if (currentMillislcd - previousMillislcd >= intervallcd) {
previousMillislcd = currentMillislcd;
snprintf(lcdBuf, COLS, "Fumi:3 Temp:%d.%d %dC", (int)tempfumi, (int) (tempfumi*100) %100); // 2 cifre dopo la virgola
lcd.setCursor(0, 0);
lcd.print(lcdBuf);
snprintf(lcdBuf, COLS, "Andata:1 Temp:%d.%d %dC", (int)tempandata, (int) (tempandata*100) %100); // 2 cifre dopo la virgola
lcd.setCursor(0,1);
lcd.print(lcdBuf);
snprintf(lcdBuf, COLS, "Ritorn:2 Temp:%d.%d %dC", (int)tempritorno, (int) (tempritorno*100) %100); // 2 cifre dopo la virgola
lcd.setCursor(0, 2);
lcd.print(lcdBuf);}
Serial.print("Sensor Number="); Serial.println(sen_number);
}