Software Code
Open Arduino IDE.
Install the
Grove Temperature and Humidity Sensor(DHT11) library: Navigate to
Sketch -> Include Library -> Manage Libraries… and Search for the keyword “Grove
Temperature and Humidity Sensor(DHT11)” in the Library Manager, then install.
Copy the following code, click Verify to check for syntax errors. Verify that there are no
errors, and you can upload the code.
//Temperature and Humidity Sensor
//Temperature and Humidity Sensor
#include "DHT.h"
#include <Arduino.h>
#include <U8x8lib.h>
#define DHTPIN 3 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT
dht
(DHTPIN, DHTTYPE);
U8X8_SSD1306_128X64_ALT0_HW_I2C
u8x8
(
/* reset=*/
U8X8_PIN_NONE);
void
setup
(
void
)
{
Serial.begin(
9600
);
Serial.println(
"DHTxx test!"
);
dht.begin();
u8x8.begin();
u8x8.setPowerSave(
0
);
u8x8.setFlipMode(
1
);
}
void
loop
(
void
)
{
float
temp, humi;
temp = dht.readTemperature();
humi = dht.readHumidity();
u8x8.setFont(u8x8_font_chroma48medium8_r);
u8x8.setCursor(
0
,
33
);
u8x8.print(
"Temp:"
);
u8x8.print(temp);
u8x8.print(
"C"
);
u8x8.setCursor(
0
,
50
);
u8x8.print(
"Humidity:"
);
u8x8.print(humi);
u8x8.print(
"%"
);
u8x8.refreshDisplay();
delay(
200
);
}
49
Grove Beginner Kit For Arduino
®
Содержание Grove Beginner Kit
Страница 1: ...Grove Beginner Kit For Arduino User Manual ...
Страница 63: ...62 Grove Beginner Kit For Arduino ...