manhoosbilli1

esp32 sensor code

Nov 16th, 2019
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. #include "DHT.h"
  4. #define DHTPIN 32
  5. #define oneWireBus = 33;
  6. #define DHTTYPE DHT22
  7. #define moistPin = 35;
  8. #define ldrPin = 34;
  9. int LDRValue = 0;
  10. DHT dht(DHTPIN, DHTTYPE);
  11. OneWire oneWire(oneWireBus);
  12. DallasTemperature sensors(&oneWire);
  13.  
  14. void setup() {
  15.   // Start the Serial Monitor
  16.   Serial.begin(115200);
  17.   sensors.begin();  //starts ds18b20
  18.   dht.begin();   //give 2 second delay to all sensors
  19.   pinMode(lDRpin, INPUT);
  20.   pinMode(moistPin, INPUT);
  21. }
  22.  
  23.  
  24. void loop() {
  25.   //get values and send to website only once and then go deep sleep
  26. }
  27.  
  28. void getSensorValues() {
  29.   sensors.requestTemperatures();
  30.   float soilTemp = sensors.getTempCByIndex(0);
  31.   float h = dht.readHumidity();
  32.   float t = dht.readTemperature();
  33.   if (isnan(h) || isnan(t) || isnan(f)) {
  34.     Serial.println(F("Failed to read from DHT sensor!")); //print to server
  35.     return;
  36.   }
  37.   LDRValue = analogRead(LDRpin); // read the value from the LDR
  38.   light = map(ldrValue, 0,1023,0,100);   //map light value as percentage
  39.   moistVal = analogRead(moistPin);
  40.   moisture = map(moistVal, 0,1023,0,100);
  41. }
Add Comment
Please, Sign In to add comment