(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 | ||
C'est un capteur One Wire qui renvoie donc l'information avec un seul fil.
Il faut importer les bibliothèque
- OneWire
- DallasTemperature
| 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); |
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/*
* The setup function. We only start the sensors here
*/
void setup(void)
{
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
}
/*
* Main function, get and show the temperature
*/
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
// After we got the temperatures, we can print them here.
// We use the function ByIndex, and as an example get the temperature from the first sensor only.
float tempC = sensors.getTempCByIndex(0);
// Check if reading was successful
if(tempC != DEVICE_DISCONNECTED_C)
{
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(tempC);
}
else
{
Serial.println("Error: Could not read temperature data");
}
}Item-Capteur_de_temp_rature_DS18B20_capteurDS18B20.jpg Published
Vous avez entré un nom de page invalide, avec un ou plusieurs caractères suivants :
< > @ ~ : * € £ ` + = / \ | [ ] { } ; ? #