Upload files to "/"
This commit is contained in:
65
dallas.ino
Normal file
65
dallas.ino
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#include <OneWire.h>
|
||||||
|
#include <DallasTemperature.h>
|
||||||
|
|
||||||
|
#define ONE_WIRE_BUS 8 // Pin, kde je připojen DS18B20
|
||||||
|
|
||||||
|
OneWire oneWire(ONE_WIRE_BUS);
|
||||||
|
DallasTemperature sensors(&oneWire);
|
||||||
|
|
||||||
|
DeviceAddress sensorAddress;
|
||||||
|
bool sensorFound = false;
|
||||||
|
|
||||||
|
void printAddress(DeviceAddress deviceAddress) {
|
||||||
|
for (uint8_t i = 0; i < 8; i++) {
|
||||||
|
if (deviceAddress[i] < 16) Serial.print("0");
|
||||||
|
Serial.print(deviceAddress[i], HEX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
pinMode(8, INPUT_PULLUP);
|
||||||
|
Serial.begin(115200);
|
||||||
|
delay(2000);
|
||||||
|
|
||||||
|
Serial.println("Hledám DS18B20...");
|
||||||
|
|
||||||
|
sensors.begin();
|
||||||
|
|
||||||
|
if (sensors.getDeviceCount() == 0) {
|
||||||
|
Serial.println("Žádné čidlo nenalezeno!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sensors.getAddress(sensorAddress, 0)) {
|
||||||
|
sensorFound = true;
|
||||||
|
Serial.print("Čidlo nalezeno, adresa: ");
|
||||||
|
printAddress(sensorAddress);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
sensors.setResolution(sensorAddress, 12); // 9–12 bitů
|
||||||
|
} else {
|
||||||
|
Serial.println("Nepodařilo se získat adresu čidla.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
if (!sensorFound) {
|
||||||
|
delay(2000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sensors.requestTemperatures();
|
||||||
|
|
||||||
|
float temperature = sensors.getTempC(sensorAddress);
|
||||||
|
|
||||||
|
if (temperature == DEVICE_DISCONNECTED_C) {
|
||||||
|
Serial.println("Čidlo odpojeno!");
|
||||||
|
} else {
|
||||||
|
Serial.print("Teplota: ");
|
||||||
|
Serial.print(temperature);
|
||||||
|
Serial.println(" °C");
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(2000);
|
||||||
|
}
|
||||||
BIN
teplotni cidlo Dallas.jpg
Normal file
BIN
teplotni cidlo Dallas.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Reference in New Issue
Block a user