Skip to content

Instantly share code, notes, and snippets.

@suadanwar

suadanwar/DHT_grove.ino

Last active Oct 22, 2020
Embed
What would you like to do?
This sample code is for Read Surrounding Temperature and Humidity using Grove All In One Beginner Kit for Arduino's tutorial.
#include "DHT.h"
#include <Arduino.h>
#include <U8x8lib.h>
#define DHTPIN 3
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
U8X8_SSD1306_128X64_ALT0_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);
#define LED 4
#define PIEZO 5
float temp, humi;
void getReading(){
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);
}
void setup(void) {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
u8x8.begin();
u8x8.setPowerSave(0);
u8x8.setFlipMode(1);
pinMode(LED, OUTPUT);
pinMode(PIEZO, OUTPUT);
}
void loop(void) {
getReading();
if (temp>32){
digitalWrite(LED,HIGH);
tone(PIEZO,1000,500);
delay(700);
}
else{
digitalWrite(LED,LOW);
noTone(PIEZO);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.