Arduino – teploměr
První zapojení Arduina, které “vytváří hodnoty :D”. Použil jsem Arduino Uno, DHT22 a display 1602A.
Potřebné součástky:
- Arduino Uno s USB kabelem
- DHT22
- Display 1602A
- Breadboard
- Kabely F-M a M-M
- Kit součástek (stačil by jen potenciometr 10k a odpornej odpor)
Do začátku uvedu zdroje, ze kterých jsem čerpal:
Návod pro display
Návod pro DHT22
Schéma pro zapojení displaye (popis)
Schéma pro zapojení DHT22 (popis)
DHT22 jsem zapojil na PIN 8.
Kód programu:
/*
1602a LiquidCrystal Library
Demonstrates the use a 16x2 LCD display. The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. This sketch prints "Hello World!" to the LCD and shows the time since the sketch started, in seconds.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K variable resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/
// include the library code:
#include <LiquidCrystal.h>
#include "DHT.h"
#define DHTPIN 8 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
// Initialize the library with the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows
lcd.begin(16, 2);
dht.begin();
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
lcd.setCursor(0, 0);
lcd.print("SENSOR ");
lcd.setCursor(0, 1);
lcd.print("ERROR ");
return;
}
lcd.setCursor(0, 0);
lcd.print("Vlhkost: ");
lcd.print(h);
lcd.print(" %\t");
lcd.setCursor(0, 1);
lcd.print("Teplota: ");
lcd.print(t);
lcd.print(" *C ");
delay(1000);
}
C’est interessant de trouver comme ce genre de postes.