/**
ESP32 + DHT22 Example for Wokwi
https://wokwi.com/arduino/projects/322410731508073042
*/
#include "DHTesp.h"
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#define PIN_RED 27
#define PIN_GREEN 14
#define PIN_BLUE 12
Servo servoMotor; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int DHT_PIN = 15;
DHTesp dhtSensor;
void setup() {
pinMode(PIN_RED, OUTPUT);
pinMode(PIN_GREEN, OUTPUT);
pinMode(PIN_BLUE, OUTPUT);
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
lcd.init();
lcd.backlight();
lcd.print("Hello lool");
delay(100);
lcd.clear();
analogWrite(PIN_RED, 0);
analogWrite(PIN_GREEN, 151);
analogWrite(PIN_BLUE, 157);
servoMotor.attach(2); // attaches the servo on pin 9 to the servo object
}
void loop() {
// rotates from 0 degrees to 180 degrees
for (int pos = 0; pos <= 180; pos += 1) {
// in steps of 1 degree
servoMotor.write(pos);
delay(15); // waits 15ms to reach the position
}
// rotates from 180 degrees to 0 degrees
for (int pos = 180; pos >= 0; pos -= 1) {
servoMotor.write(pos);
delay(15); // waits 15ms to reach the position
}
}
void setRGB(int RED_VAL, int GREEN_VAL, int BLUE_VAL) {
// color code #00C9CC (R = 0, G = 201, B = 204)
analogWrite(PIN_RED, RED_VAL);
analogWrite(PIN_GREEN, GREEN_VAL);
analogWrite(PIN_BLUE, BLUE_VAL);
}
void test() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
lcd.print("Temp: " + String(data.temperature, 2) + "%");
lcd.setCursor(0, 1);
lcd.print("Humidity: " + String(data.humidity, 1) + "%");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
}