Programme ds18b20 avec lampe chauffante

Bonjour membres

je suis un éléve de terminal sti2d , nous avons un projet a faire moi et mon groupe ma tache et de reguler la température dans un terrarium avec une lampe chauffante le matin de 11 °à 20 °et le soir de 23° à 30° .
J'ai un capteur ds18b20
Un arduino
Un ecran lcd
Un relay
Jai besoin d'aide pour avoir un programme sur ce projet je n'arrive pas du tt , j'aimerais que vous m'aider merci.

Please, repeat/edit the post in English Language!

Hello members of the forum

I am a student terminal sti2d, we have a project to me and my group my task and regulate the temperature in a terrarium with a heat lamp in the morning from 11 ° to 20 ° and the evening from 23 ° to 30 °.
I have a ds18b20 sensor
An arduino
LCD screen
A relay
I need help to have a program on this project I do not arrive at the beginning, I would like you to help me thank you.

1. Build your project as per following block diagram. You may use equivalent components. By the way: How are you going to track the time of the day? Probabaly, you need a RTC -- DS1307 or DS3231.

Figure-1: Block diagram for UNO-DS18B20-I2CLCD based Temperature Controller

2. The Flow Chart (given below) is the approximate program that will regulate your temperature cycle.

Figure-2: Flow Chart describing the Control Program for the Temperature Controller of Fig-1.

3. I am giving below the basic two functions of the Arduino IDE. Try to put some codes based on the given Flow Chart or of your own strategy. Please post your codes to get the next help. If you find problems to write codes for the DS18B20, substitute it (for the time being) calling the function getTemp();

void setup()
{

}

void loop()
{
    getTemp();           //acquiring Temperature from DS18B20
    delay(2000);           //acquire temp at 2-sec interval (adjustable)
}

void getTemp()
{
    //code here to acquire Temperature from DS18B20 using DallasTemperatures Library functions
}

thank you you very much you helped me a lot. I have that as a beginning of program, I would like to know how to regulate the temperature morning (at 8 in the morning, at 8 in the evening) beetween 11° and 30 ° and evening(at 8 in the evening , at 8 in the morning) beetween 20° and 30°

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;
#define DS18B20 0x28     // Adresse 1-Wire du DS18B20
#define BROCHE_ONEWIRE 7 // Broche utilisée pour le bus 1-Wire
#define RELAY 2
OneWire ds(BROCHE_ONEWIRE); // Création de l'objet OneWire ds

// Fonction récupérant la température depuis le DS18B20
// Retourne true si tout va bien, ou false en cas d'erreur
boolean getTemperature(float *temp){
byte data[9], addr[8];
// data : Données lues depuis le scratchpad
// addr : adresse du module 1-Wire détecté

if (!ds.search(addr)) { // Recherche un module 1-Wire
 ds.reset_search();    // Réinitialise la recherche de module
 return false;         // Retourne une erreur
}
 
if (OneWire::crc8(addr, 7) != addr[7]) // Vérifie que l'adresse a été correctement reçue
 return false;                        // Si le message est corrompu on retourne une erreur

if (addr[0] != DS18B20) // Vérifie qu'il s'agit bien d'un DS18B20
 return false;         // Si ce n'est pas le cas on retourne une erreur

ds.reset();             // On reset le bus 1-Wire
ds.select(addr);        // On sélectionne le DS18B20
 
ds.write(0x44, 1);      // On lance une prise de mesure de température
delay(850);             // Et on attend la fin de la mesure
 
ds.reset();             // On reset le bus 1-Wire
ds.select(addr);        // On sélectionne le DS18B20
ds.write(0xBE);         // On envoie une demande de lecture du scratchpad

for (byte i = 0; i < 9; i++) // On lit le scratchpad
 data[i] = ds.read();       // Et on stock les octets reçus
 
// Calcul de la température en degré Celsius
*temp = ((data[1] << 8) | data[0]) * 0.0625;
 
// Pas d'erreur
return true;
}

// setup()
void setup() {
 Serial.begin(57600);
 Wire.begin();
 RTC.begin();
pinMode(RELAY, OUTPUT); 
digitalWrite(RELAY, HIGH);
Serial.begin(57600); // Initialisation du port série

if (! RTC.isrunning()) {
 Serial.println("RTC is NOT running!");
 // following line sets the RTC to the date & time this sketch was compiled
 RTC.adjust(DateTime(__DATE__, __TIME__));}}

// loop()
void loop() {
DateTime now = RTC.now();
float temp;
// Lit la température ambiante à ~1Hz
if(getTemperature(&temp)) {
   
 // Affiche la température
 Serial.print("Temperature : ");
 Serial.print(temp);
 Serial.write(176); // caractère °
 Serial.write('C');
 Serial.println();

Thank you for the codes. I will certainly look into it. In the meantime, please re-format your codes:
1. Goto Edit/Modify option of your post (Post#4).

2. Bring the cursor just at the beginning of your code and type this: [ c o d e ] (I have shown here spaces for technical reason; when you type the word, do not place space; you keep them together)

3. Bring the cursor to the end of the code and type this: [ / c o d e ].(I have shown here spaces for technical reason; when you type the word, do not place space; you keep them together.)

4. Click on save button of your page.

Check that your codes look so beautiful!

thank you

Your program codes of Post#4 is fine; but, you know that the logic for the solution of an engineering problem does not vary much from person to person; however, the ways of implementation differs a lot due to knowledge, experience and technological culture. If it would be my project, I would follow this implementation methodology:

//declare global parameters as needed----------
#include<Wire.h> //to handle DS1307 using I2C Bus; I have problem with RTClib.h Library
#include <DallasTemperature.h>  //to handle DS18B20 sensor
#include<LiquidCrystal_I2C.h>    //to handle I2CLCD
LiquidCrystal_I2C lcd(0x27, 16, 2); //wiring function for I2CLCD
unsigned int dsTemp;                     //to hold integer value for the Temperature given by DS18B20

#define ONE_WIRE_BUS 10  //DPin-10 is the signal wire for DS18B20 with 2.2k pull-up
OneWire oneWire(ONE_WIRE_BUS);      //DS18B20 is an 1-Wire device        
DallasTemperature sensors(&oneWire);  //we are using dallas library

void setup()
{
   Serial.begin(9600);      //Initialize Serial Monitor at 9600 Bd
   Wire.begin();               //Intialize I2C Bus
   //------------------------------------------------------------------

   lcd.init();                    //initialize I2CLCD
   lcd.backlight(); 
   //------------------------------------------------------------------

   pinMode(12, OUTPUT);  //relay control is DPin-12
  //------------------------------------------------------------------
   
   setIntialTimeInRTC();    //set initial time in 24 hrs format

}

void loop()
{
    showTimeOnLCD();      //acquire Time and show on Top Line of LCD
    showTempOnLCD();     //acquire temperature and show on Bottom line of LCD
    makeDecisionMorning(); //8am - 8pm  ---> 08:00:00 -- 20:00:00
    makeDecisionEvening(); //8pm - 8am  ---> 20:00:00 -- 08:00:00
}



void setIntialTimeInRTC()   //set initial time manually at: (say) 23 : 58 : 36
{
  Wire.beginTransmission(0x68); //START, Roll Cal
  Wire.write(0x00); //set SEC Register address
  Wire.write(0x36); //set SEC Register value (BCD)
  Wire.write(0x58); //set MIN Register value 
  Wire.write(0x23); //set HRS Register value
  Wire.endTransmission(); //Execute the above queued data, ACK, STOP
}

void showTimeOnLCD()
{ 
  Wire.beginTransmission(0x68); //START, Roll Cal
  Wire.write(0x00); //set SEC Register address
  Wire.endTransmission(); //Execute the above queued data, ACK, STOP

  Wire.requestFrom(0x68, 3);   //SEC, MIN, and HRS to read from RTC as BCD
  byte bcdSeconds = Wire.read();
  byte bcdMinutes = Wire.read();
  byte bcdHours = Wire.read();
  //bcdHours = bcdHours & 0b00111111;

   lcd.setCursor(0, 0);
   lcd.print("Time = ");
   //show HRS--
  lcd.write((bcdHours>>4) + 0x30);
  lcd.write((bcdHours & 0x0F) + 0x30);
  lcd.write(':');
  
  //show MIN--
  lcd.write((bcdMinutes>>4) + 0x30);
  lcd.write((bcdMinutes & 0x0F) + 0x30);
  lcd.print(':');
 
 //show SEC
 lcd.write((bcdSeconds>>4) + 0x30);
 lcd.write((bcdSeconds & 0x0F) + 0x30);
 
}

void showTempOnLCD()
{
  
  sensors.requestTemperatures();  // Temp conversion command; waiting here until comversion is done
  dsTemp = sensors.getTempCByIndex(0);  //read temp data from Sensor #0 and convert to celsius float 
  lcd.setCursor(0, 1);
  lcd.print("Temp = ");
  lcd.print(dsTemp);
  lcd.write(0xDF);
  lcd.print('C');
 // delay(500);    //sample temperature at 2-sec interval
}

void makeDecisionMorning()  //8am - 8pm  Heater ON when Temp is >=10 C and <=30 C
{
   dsTemp = sensors.getTempCByIndex(0); 
   if(dsTemp >=10)
   {
      if(dsTemp <= 30)
      {
        digitalWrite(11, HIGH);  //Heater ON
        return;
      }
   }
   digitalWrite(12, LOW);   //Heater OFF
 }

void makeDecisionEvening()
{
  dsTemp = sensors.getTempCByIndex(0); 
   lcd.setCursor(14, 1);
   lcd.print(dsTemp);
   if(dsTemp >=20)
   {
      if(dsTemp <= 30)
      {
        digitalWrite(12, HIGH);
        return;
      }
   }
   digitalWrite(12, LOW);
}

to be continued to implement the Time Zone…

#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 7

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress fish = { 0x28, 0xEE, 0xFA, 0xC3, 0x1D, 0x16, 0x01, 0xCC }; // cherche le code oneWire finder pour avoir l'adresse de ton capteur

void setup() {
  sensors.begin();
  sensors.setResolution(fish, 12); // de 9 à 12, plus la valeur est grande, plus de temps il faudra au capteur pour mesurer la température.
}

void loop() {
  sensors.requestTemperatures();
  Serial.print(sensors.getTempC);
float temp;
    
  // Lit la température ambiante à ~1Hz
  if(getTemperature(&temp)) {
      
    // Affiche la température
    Serial.print("Temperature : ");
    Serial.print(temp);
    Serial.write(176); // caractère °
    Serial.write('C');
    Serial.println();
  }
Serial.print(now.year(), DEC);
   Serial.print('/');
   Serial.print(now.month(), DEC);
   Serial.print('/');
   Serial.print(now.day(), DEC);
   Serial.print(' ');
   Serial.print(now.hour(), DEC);
   Serial.print(':');
   Serial.print(now.minute(), DEC);
   Serial.print(':');
   Serial.print(now.second(), DEC);
   Serial.println();


if( temp <= 11 && now.hour() >= 8 && now.hour() <= 20 && { // si on est entre 8h et 20h que la T° < 11° 
   digitalWrite(RELAY,HIGH);
  ; 
 }
 else if( temp >= 20 ){ // si T° dépasse 20° on coupe le relais
 digitalWrite(RELAY,LOW);
    delay(10000);
}
 
else  digitalWrite(RELAY,LOW); // sinon, les conditions ne sont pas réunis, on coupe le relais
 
}  }  } 
if( temp <= 20 && now.hour() >= 20 && now.hour() <=8 { // si on est entre 20 et 8h que la T° < 17° 
   digitalWrite(RELAY,HIGH);
  ; 
 }
 else if( temp >= 30 ){ // si T° dépasse 30° on coupe le relais
 digitalWrite(RELAY,LOW);
    delay(10000);
}
 
else  digitalWrite(RELAY,LOW); // sinon, les conditions ne sont pas réunis, on coupe le relais
 
}  }  }

Thank you very much (I worked a little on my side I did this program) Is it good?

The program structure looks good; but, a little bit clumsy! Why don’t you follow the principle of ‘Modular Programming?’ There are many things in your program which are not consistent. For example: you are comparing with integer type temperatures; why have you declared it as float temp? there is no DPin definition for RELAY. If you are using DallasTemperatures Library, is there any need to key the address of the DS118B20 device? You should first document the meanings of the available methods of the Dallas Library before you use them in your program.

I tested mine one and that was working except the time zone. I suspect that your program will work; anyway, give a try!

It is always good practice to begin with a program that works! And then, you add/subtract ideas with the working program!

One of the features of Modular Programming is its clean main line program (ML) which contains minimum number of instructions; the required jobs are performed using subroutines. In your current project, you have the following jobs to do; which you are required to encompass within modular structure.

1. Global variable declarations.
2. Initialization
3. Time Acquisition and Display on LCD
4. Temperature Acquisition and Display on LCD
5. Select Time Zone (08:00:00 (080000) – 20:00:00(200000)) and make heater ON/OFF to comply with this requirement: >=10 Temp <= 30.

6. Select Time Zone (20:00:00(200000) – 08:00:00(080000)) and make heater ON/OFF to comply with this requirement: >=20 Temp <= 30.

Thank you very much, you help me a lot thank you very much. How to set up the time zone, I did not understand you too much.

How to add the ds1307 sensor and where to connect it in the following block diagram.
(Figure-1: Block diagram for UNO-DS18B20-I2CLCD based Temperature Controller)((Post#3)

Fatal error: DallasTemperature.h: No file or directory of this type

#include <DallasTemperature.h> // to handle the DS18B20 sensor

I have this error with your program

So, you need to install the DallasTemperature library

Download the DallasTemperature-3.8.0.zip Library and install using IDE. (IDE ---> ToolBar ---> Sketch ---> Include Library ---> Add .ZIp Library... ----> Select zip File and click.)

ah thanks i'm stupid