/*----------------------------------------------------------------------------
Régulation de température
Description:
Matériel: arduino UNO, NANO
Logiciel: Développé en utilisant le logiciel Arduino 1.8.5
atm-so@bbox.fr ------------------------------------------------------------------------------*/
/*
Relai broche 13
Sondes broche 7
*/
#include "LiquidCrystal.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include "Wire.h"
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int lcd_key = 0;
int adc_key_in = 0;
#define btnPlus5 0
#define btnPlus1 1
#define btnMoins1 2
#define btnMoins5 3
int Pel = 13;// sortie relais
#define ONE_WIRE_BUS 3 // sonde raccordée sur la broche 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress Probe01 = { 0x28, 0xDA, 0x72, 0x50, 0x05, 0x00, 0x00, 0x16 }; // adresse a remplacer - sonde exterieur
DeviceAddress Probe02 = { 0x28, 0x71, 0x17, 0xA8, 0x04, 0x00, 0x00, 0xB7 }; // sonde peltier
float settemp;
float compt;
float compt2;
int read_LCD_buttons()
{
adc_key_in = analogRead(0);
if (adc_key_in < 50) return btnPlus5;
if (adc_key_in < 195) return btnPlus1;
if (adc_key_in < 380) return btnMoins1;
if (adc_key_in < 555) return btnMoins5;
}
void setup()
{
pinMode (Pel,OUTPUT);
sensors.begin();
sensors.setResolution(Probe01, 10);
sensors.setResolution(Probe02, 10);
lcd.begin(16, 2);
lcd.setCursor(3,0);
lcd.print("CCD Fresh");
lcd.setCursor(4,1);
lcd.print("ATM-SO");
delay(4000);
lcd.clear();
}
void loop()
{
int temp1 = sensors.getTempC(Probe01);
sensors.requestTemperatures();
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("E:"); // Exterieur
printTemperature(Probe01);
lcd.print(" ");
lcd.print("P:"); // Peletier
printTemperature(Probe02);
lcd.setCursor(1,1);
lcd.print("Cons: "); // Consigne
lcd.print(settemp);
if (settemp < temp1 )
{
digitalWrite(Pel,LOW);
lcd.print (" on"); // Indication On
}
else
{
digitalWrite(Pel,HIGH);
lcd.print (" off"); // Indication off
}
delay (100);
settemp = (compt*1)+(compt2*5);
// possibilité d'augmenter la précision de la consigne incrément 0.5
//settemp = (compt*0.5);
lcd_key = read_LCD_buttons();
switch (lcd_key)
{
case btnPlus1:
{
(compt ++);
break;
}
case btnMoins1:
{
(compt --);
break;
}
case btnPlus5:
{
(compt2 ++);
break;
}
case btnMoins5:
{
(compt2 --);
break;
}
}
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00)
{
lcd.print("Erreur");
}
else
{
lcd.print(tempC);
}
}