Item:Capteur de température DS18B20 : Différence entre versions

(Page créée avec « {{Item |Main_Picture=Item-Capteur_de_temp_rature_DS18B20_capteurDS18B20.jpg |Description=le DS18B20 est un capteur de température |Categories=Matériel |Cost=1,5 |Currenc... »)
 
 
Ligne 9 : Ligne 9 :
 
<br />
 
<br />
  
=== Schéma de câblage ===
+
=== Bibliothèques ===
 +
Il faut importer les bibliothèque
 +
 
 +
- OneWire
 +
 
 +
- DallasTemperature<br />
 +
 
 +
===Schéma de câblage===
 
{{#annotatedImageLight:Fichier:Item-Capteur de temp rature DS18B20 DS18B20-cablage.png|0=1024px|hash=|jsondata=|mediaClass=Image|type=frameless|alt=cablage DS18B20|align=center|src=https://www.wikidebrouillard.org/images/f/f1/Item-Capteur_de_temp_rature_DS18B20_DS18B20-cablage.png|href=./Fichier:Item-Capteur de temp rature DS18B20 DS18B20-cablage.png|resource=./Fichier:Item-Capteur de temp rature DS18B20 DS18B20-cablage.png|caption=cablage DS18B20|size=1024px}}<br />
 
{{#annotatedImageLight:Fichier:Item-Capteur de temp rature DS18B20 DS18B20-cablage.png|0=1024px|hash=|jsondata=|mediaClass=Image|type=frameless|alt=cablage DS18B20|align=center|src=https://www.wikidebrouillard.org/images/f/f1/Item-Capteur_de_temp_rature_DS18B20_DS18B20-cablage.png|href=./Fichier:Item-Capteur de temp rature DS18B20 DS18B20-cablage.png|resource=./Fichier:Item-Capteur de temp rature DS18B20 DS18B20-cablage.png|caption=cablage DS18B20|size=1024px}}<br />
  
=== Code Minimal ===
+
===Code Minimal===
  
  
Ligne 41 : Ligne 48 :
 
|}
 
|}
  
=== Exemple ===
+
===Exemple===
 
<syntaxhighlight lang="arduino" line="1">
 
<syntaxhighlight lang="arduino" line="1">
 
// Include the libraries we need
 
// Include the libraries we need

Version actuelle datée du 9 mars 2023 à 17:22


Item-Capteur de temp rature DS18B20 capteurDS18B20.jpg

Capteur de température DS18B20

le DS18B20 est un capteur de température

1,5EUR (€)


Description longue

C'est un capteur One Wire qui renvoie donc l'information avec un seul fil.


Bibliothèques

Il faut importer les bibliothèque

- OneWire

- DallasTemperature

Schéma de câblage

cablage DS18B20

Code Minimal

DS18B20
Avant le Setup Importation de la bibliothèque #include <OneWire.h>

#include <DallasTemperature.h>

Création de l’objet OneWire oneWire(ONE_WIRE_BUS); // je crée une instance OneWire

DallasTemperature sensors(&oneWire); //je passe One Wire à Dallas temperature

Dans le Setup Démarrage de l’objet sensors.begin();
Dans le Loop Utilisation sensors.requestTemperatures(); //commande pour récupoérer la température

//Nous utilisons la fonction ByIndex et, à titre d'exemple, nous obtenons la température du premier capteur uniquement.

float tempC = sensors.getTempCByIndex(0);

Exemple

 1 // Include the libraries we need
 2 #include <OneWire.h>
 3 #include <DallasTemperature.h>
 4 
 5 // Data wire is plugged into port 2 on the Arduino
 6 #define ONE_WIRE_BUS 2
 7 
 8 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
 9 OneWire oneWire(ONE_WIRE_BUS);
10 
11 // Pass our oneWire reference to Dallas Temperature. 
12 DallasTemperature sensors(&oneWire);
13 
14 /*
15  * The setup function. We only start the sensors here
16  */
17 void setup(void)
18 {
19   // start serial port
20   Serial.begin(9600);
21   Serial.println("Dallas Temperature IC Control Library Demo");
22 
23   // Start up the library
24   sensors.begin();
25 }
26 
27 /*
28  * Main function, get and show the temperature
29  */
30 void loop(void)
31 { 
32   // call sensors.requestTemperatures() to issue a global temperature 
33   // request to all devices on the bus
34   Serial.print("Requesting temperatures...");
35   sensors.requestTemperatures(); // Send the command to get temperatures
36   Serial.println("DONE");
37   // After we got the temperatures, we can print them here.
38   // We use the function ByIndex, and as an example get the temperature from the first sensor only.
39   float tempC = sensors.getTempCByIndex(0);
40 
41   // Check if reading was successful
42   if(tempC != DEVICE_DISCONNECTED_C) 
43   {
44     Serial.print("Temperature for the device 1 (index 0) is: ");
45     Serial.println(tempC);
46   } 
47   else
48   {
49     Serial.println("Error: Could not read temperature data");
50   }
51 }

Pages liées

Commentaires

Published