- At first, we need to prepare the environment for ESP32 development board programming in arduino, and you can cheak this guide.
- This is a library for our Monochrome OLEDs based on SSD1306 drivers.
#include <Adafruit_SSD1306.h>
- This library allows you to communicate with I2C devices (the OLED is connected by I2C)
#include <Wire.h>
- The Adafruit_GFX library provides a common syntax and set of graphics functions for all of our LCD and OLED displays and LED matrices.
#include <Adafruit_GFX.h>
- An Arduino library for the DHT series.
#include <DHT.h>
- Difine your pins, this determines which pin of the board your device should be connected to.
#define DEBUG true
#define LTE_RESET_PIN 6
#define LTE_PWRKEY_PIN 5
#define pinInterrupt A0
#define DHTPIN 2
#define LIGHT
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3c
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
- Initialise your devices so that they work properly
erialUSB.begin(115200);
Serial1.begin(115200);
pinMode(LTE_RESET_PIN, OUTPUT);
digitalWrite(LTE_RESET_PIN, LOW);
pinMode(LTE_PWRKEY_PIN, OUTPUT);
digitalWrite(LTE_RESET_PIN, LOW);
delay(100);
digitalWrite(LTE_PWRKEY_PIN, HIGH);
delay(3000);
digitalWrite(LTE_PWRKEY_PIN, LOW);
Wire.begin();
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
SerialUSB.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
else{
SerialUSB.println(F("SSD1306 allocation successful"));
}
display.clearDisplay();
delay(1000);
pinMode(pinInterrupt, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(pinInterrupt), onChange, FALLING);
dht.begin();
pinMode(LIGHT, INPUT);
void wind_speed()
{
lastDebounceTime = millis();
Count = 0;
while(!((millis() - lastDebounceTime) > debounceDelay));
if ((millis() - lastDebounceTime) > debounceDelay)
{
speed_value = Count * 8.75 * 0.01;
SerialUSB.print("Wind speed:");
SerialUSB.print(speed_value);
SerialUSB.println("m/s");
Count = 0;
}
}
void onChange()
{
if (digitalRead(pinInterrupt) == LOW)
Count++;
}
- Detecting light intensity
void light_str()
{
lastDebounceTime = millis();
count_light = 0;
while((millis() - lastDebounceTime) < debounceDelay)
{
delay(5);
if (digitalRead(LIGHT) == 0){
count_light++;
}
}
if(count_light>100)
{
SerialUSB.println("Strong ultraviolet ray");
light_intensity =light_intensity +"Strong ultraviolet ray";
light_index = light_index + "1";
}
else
{
SerialUSB.println("Weak ultraviolet ray");
light_intensity =light_intensity + "Weak ultraviolet ray";
light_index = light_index + "0";
}
count_light = 0;
}
- Detecting temperature and humidity
float humidity_value = dht.readHumidity();
float temperature_value = dht.readTemperature();
SerialUSB.print("Humidity:");
SerialUSB.print(humidity_value);
SerialUSB.println(" %");
SerialUSB.print("Temperature:");
SerialUSB.print(temperature_value);
SerialUSB.println(" C");
display.clearDisplay();
display.setCursor(1, 5);
display.setTextColor(WHITE);
display.setTextSize(1);
display.println("Humidity:" + String(humidity_value) + " %" );
display.setCursor(1, 15);
display.setTextColor(WHITE);
display.setTextSize(1);
display.println("Temperature:" + String(temperature_value) + " C" );
display.setCursor(1, 25);
display.setTextColor(WHITE);
display.setTextSize(1);
display.println("Wind speed:" + String(speed_value) + "m/s");
display.setCursor(1, 35);
display.setTextColor(WHITE);
display.setTextSize(1);
display.println(light_l);
display.display();
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.