Cov txheej txheem:

Tau Txais Tus lej ntawm DS18B20 Nrog Arduino: 5 Kauj Ruam
Tau Txais Tus lej ntawm DS18B20 Nrog Arduino: 5 Kauj Ruam

Video: Tau Txais Tus lej ntawm DS18B20 Nrog Arduino: 5 Kauj Ruam

Video: Tau Txais Tus lej ntawm DS18B20 Nrog Arduino: 5 Kauj Ruam
Video: Tus Cag Cwjpwm Koobhmoov ntawm daim lej #6 2024, Hlis ntuj nqeg
Anonim
Tau Txais Tus lej ntawm DS18B20 Nrog Arduino
Tau Txais Tus lej ntawm DS18B20 Nrog Arduino

Nov yog cov lus qhia nrawm yuav ua li cas kom tau txais tus lej ntawm koj tus DS18B20 1-xaim ntsuas kub.

Qhov no yooj yim rau cov haujlwm uas xav tau ntau lub ntsuas.

Yam koj xav tau:

  • Arduino 5v (UNO, Mega, Pro Mini thiab lwm yam) - Arduino UNO R3 - AliExpress
  • Temp Sensor DS18B20 - AliExpress - eBay
  • 4.7k - 1/4w Resistor THT - AliExpress - eBay
  • Breadboard - AliExpress - eBay
  • Jumper Wires - Txiv neej rau Txiv neej - AliExpress - eBay
  • Lub khoos phis tawj nrog Arduino IDE teeb tsa

Kauj Ruam 1: Ntxiv Cov Tsev Kawm Ntawv Xav Tau rau Arduino IDE

Ntxiv Cov Tsev Kawm Ntawv Xav Tau rau Arduino IDE
Ntxiv Cov Tsev Kawm Ntawv Xav Tau rau Arduino IDE
  1. Qhib Arduino IDE (Kuv siv 1.8.1)
  2. Nyem "Sketch" -> "Xws li Lub Tsev Qiv Ntawv" -> "Tswj Cov Tsev Qiv Ntawv …"
  3. Xaiv lub bar tshawb thiab ntaus "dallas"
  4. Nyem "DallasTemperature" thiab nyem "Install"

Xwb, koj tuaj yeem rub lub Tsev Qiv Ntawv los ntawm no:

Lub Tsev Qiv Ntawv no suav nrog OnWire Library.

Kauj Ruam 2: Txhim Kho DS18B20

Txhim Kho DS18B20
Txhim Kho DS18B20
Txhim Kho DS18B20
Txhim Kho DS18B20

Siv lub khob cij txuas nrog +5V, GND thiab Digital Pin 2 (Tus Pin 2 twb tau teeb tsa hauv qhov piv txwv piv txwv) los ntawm Arduino siv Txiv neej rau Txiv Neej breadboard jumpers.

Txuas DS18B20 txuas mus rau 3x daim kab xev dav dav ntawm lub khob cij.

  • Pin 1 (GND) -> GND (Hauv av 0V)
  • Pin 2 (DATA) -> Digital Pin 2
  • Pin 3 (Vdd) -> +5V

Rau Lub Hwjchim Zoo Li Qub txuas 4.7K Resistor los ntawm +5V rau Digital Pin 2 xaim ntawm lub khob cij.

Cov txuas hauv qab no yog cov peev txheej zoo rau DS18B20 1-xaim ntsuas kub.

www.tweaking4all.com/hardware/arduino/ardu…

Kauj Ruam 3: Thauj Cov Piv Txwv Piv Txwv "Ib Leeg"

Thauj Khoom Piv Txwv
Thauj Khoom Piv Txwv
Thauj Khoom Piv Txwv
Thauj Khoom Piv Txwv

Thaum koj muaj nws txuas koj tau npaj thauj Dallas Kub "Ib Leeg" SketchOpen Arduino IDE (Kuv tab tom siv 1.8.1) Nyem "Cov Ntaub Ntawv" -> "Piv txwv" -> "Dallas Kub" -> "Ib Leeg" Kuv ntxiv qeeb (5000); ntawm kab 103 kom muab sijhawm rau kuv luam tus lej lej Xaiv koj daim ntawv tsim nyog "Cov cuab yeej" -> "Pawg Thawj Coj" Xaiv koj qhov chaw nres nkoj uas tsim nyog "Cov Cuab Yeej" -> "Chaw Nres Nkoj" Tam sim no "Upload" Daim Duab "Sketch" -> "Upload" Nyem "Tools" -> "Serial Monitor" xyuas kom tseeb tias baud tus nqi sib xws rau kuv yog 9600 Yog tias koj kos duab tsis tau upload xyuas koj li Board, Port, USB drivers thiab lwm yam.

Kauj Ruam 4: Luam Tus Zauv Serial

Luam tus lej naj npawb
Luam tus lej naj npawb
Luam tus lej naj npawb
Luam tus lej naj npawb

Los ntawm "Serial Monitor" koj yuav pom kab thib 4 yog "Device 0 Address: xxxxxxxxxxxxxxxx"

Nov yog Tus lej ntawm DS18B20

Yog tias nws yog "0000000000000000" ces muaj teeb meem nyeem koj li DS18B20.

Qhia nws nrog koj tus nas thiab nias CTRL+C ntawm koj cov keyboard tom qab ntawd nws hauv Notepad

Rau kuv lwm qhov haujlwm kuv cov cai siv ntau ntawm cov lej no. Kuv hloov kho HEX txoj hlua rau cov hom ntawv hauv qab no.

DeviceAddress tempSensorSerial [9] = {

{0x28, 0xFF, 0x07, 0xA6, 0x70, 0x17, 0x04, 0xB5}, {0x28, 0xFF, 0xB2, 0xA6, 0x70, 0x17, 0x04, 0x28}, {0x28, 0xFF, 0x42, 0x98, 0x70, 0x17, 0x04, 0xD3}, {0x28, 0xFF, 0x86, 0xA8, 0x70, 0x17, 0x04, 0xA6}, {0x28, 0xFF, 0x2B, 0x65, 0x71, 0x17, 0x04, 0x76}, {0x28, 0xFF, 0x66, 0x62, 0x71,, 0x17, 0x04, 0xF5}, {0x28, 0xFF, 0xD9, 0x9B, 0x70, 0x17, 0x04, 0x9C}, {0x28, 0xFF, 0x98, 0x6A, 0x71, 0x04, 0xED}, {0x28, 0xFF, 0x99, 0x42, 0x71, 0x17, 0x04, 0x4C}};

Kauj ruam 5: Tiav lawm

Tiav lawm
Tiav lawm

Tam sim no koj tuaj yeem txheeb xyuas txhua tus neeg DS18B20 1-xaim ntsuas kub hauv koj tus lej thiab siv ua haujlwm zoo li no:

ntab getTemperature (byte j) {

sensors.requestTemperaturesByAddress (tempSensorSerial [j]);

ntab tempC = sensors.getTempC (tempSensorSerial [j]);

rov qab tempC;

}

Pom zoo: