/**
   ESP32 + DHT22 Example for Wokwi
   
   https://wokwi.com/arduino/projects/322410731508073042
*/
/*
  example uses ESP32, but should be easily adapted to Arduino or Raspberry Pico
  all of these should be low-cost and available
  
  TEMPERATURE:
    DHT22 is low-cost, resilient and widely available.
    It is digital, but should be accurate to several hundredths of degrees and can be polled at least every few seconds
  
  VIBRATION
    PIR motion sensor is assumed to be accurate enough for vibration data
    Gyro sensor is assumed to be used if more accurate than PIR motion sensor and can be used for greater accuracy
    SW-420 vibration sensor can be used as an alternate, assuming greater accuracy, but is not available in this simulator
  
  COMMUNICATION
    Modem is being used for this simulation with the intent of replacing or adapting that section of the code for other methods
  
  RTC
    This is used for timing, but can be eliminated for costs, assuming timing to be done at the network gateway level

*/
#include "DHTesp.h"
// include PIR sensor library
// include modem library
// include RTC library

const int DHT_PIN = 15;
const int PIR_PIN = 14; // assuming this to be an analog pin
const int MODEM_PIN = 13; // assuming this to be an analog pin, unless analog is not required
const int RTC_PIN = 12; // assuming this to be an analog pin, unless analog is not required
const int WAIT_TIME = 60; // in seconds

DHTesp dhtSensor;
// whatever is required for PIR sensor
// whatever is required for modem
// whatever is required for RTC clock

void setup() {
  Serial.begin(115200);
  dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
  // setup code for PIR sensor
  // setup code for modem
  // setup code for RTC
}

void loop() {
  TempAndHumidity  data = dhtSensor.getTempAndHumidity();
  // read PIR sensor
  Serial.println("Temp: " + String(data.temperature, 2) + "°C");
  Serial.println("Humidity: " + String(data.humidity, 1) + "%");
  Serial.println("---");
  // alter the block above to format data as CSV, XML, or JSON
  // send data via modem or wifi
  // verify time with RTC, if required
  delay(1000); // alter this to use code this is non-blocking
}
GND5VSDASCLSQWRTCDS1307+
Loading
esp-01