DS18B20 Arduino Przykład
DS18B20 to 1-Wire cyfrowy czujnik temperatury firmy Maxim IC. Podaje stopnie w stopniach Celsjusza od -55 do 125 (/-0,5). Każdy czujnik ma wytrawiony unikalny 64-bitowy numer seryjny – pozwala na użycie ogromnej liczby czujników na jednej magistrali danych. Do korzystania z czujnika potrzebujemy dwóch bibliotek: OneWire.h oraz Arduino-Temperature-Control-Library-master. Pin OUT musi być podłączony do Vcc przez rezystora 10K ohm, jeśli tego nie zrobisz, czujnik pokaże -127 stopni Celsjusza.
Cechy:
-Unikalny interfejs 1-Wire wymaga tylko jednego styku portu do komunikacji
0Każde urządzenie ma unikalny 64-bitowy kod szeregowy przechowywany w wbudowanej pamięci ROM
-Nie wymaga elementów zewnętrznych
-Może być zasilany z linii danych.
-Zakres zasilania wynosi od 3,0 V do 5,5 V.
-Mierzy temperatury od –55 ° C do 125 ° C (–67 ° F do 257 ° F) ± 0,5 ° C dokładność od –10 ° C do 85 ° C
-Rozdzielczość termometru jest wybierana przez użytkownika od 9 do 12 bitów

2 wersje sketch : SerialMonitor i wyświetlacz i2c 0.96″:
Biblioteki:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
/* * ForbiddenBit.com * * DS18B20 only Serial Monitor */ // First we include the libraries #include <OneWire.h> #include <DallasTemperature.h> #include <SPI.h> #include <Wire.h> /********************************************************************/ // Data wire is plugged into pin 2 on the Arduino #define ONE_WIRE_BUS 2 OneWire oneWire(ONE_WIRE_BUS); /********************************************************************/ // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); void setup(void) { // start serial port Serial.begin(9600); Serial.println("ForbiddenBit.com"); sensors.begin(); } 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 temperature readings Serial.println("DONE"); /********************************************************************/ Serial.print("Temperature is: "); Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? } |