Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Program odczytuje temperaturę z czujnika i pipczy gdy temperatura spada ponizej 24C
- #include <OneWire.h>
- #include <DS18B20.h>
- // Numer pinu do którego podłaczasz czujnik
- #define ONEWIRE_PIN 2
- int BUZZER = 3; /// okreslamy pin dla buzzera
- // Adres czujnika
- byte address[8] = {0x28, 0xFF, 0x84, 0x92, 0x50, 0x15, 0x1, 0x4C};
- OneWire onewire(ONEWIRE_PIN);
- DS18B20 sensors(&onewire);
- void setup() {
- while(!Serial);
- Serial.begin(9600);
- sensors.begin();
- sensors.request(address);
- pinMode(BUZZER, OUTPUT);
- }
- void loop() {
- if (sensors.available())
- {
- float temperature = sensors.readTemperature(address); // odczyt
- Serial.print(temperature); // wypis do konsoli
- Serial.println(F(" 'C"));
- sensors.request(address);
- if (temperature < 24) // warunek na buzzer - poniej 24 C zacznie pipczec
- {digitalWrite(BUZZER, HIGH); /// bzyt
- delay(1000);
- digitalWrite(BUZZER, LOW); // wylaczenie bzyt
- delay(1000);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment