Hey all, thank in advance for any help or suggestions.
I’m creating a project to keep an eye on a garden, and have run into some issues. I am using a nodemcu esp and am trying to connect 5 water temp probes, DHT11, and a reed sensor (letting me know if I have left the door open).
I have been able to get code for each sensor to work separately, but then when I try to get them all together I cannot get it to work properly. It looks as though the water probes (all on 1 pin) work just fine no matter what, but then the DHT11 seems to work intermittently and will show “NAN%” on my blynk dashboard - and seems like the temp/humidity numbers may not be correct. The reed sensor just seems to not work at all with the below code.
I’m pretty much a newbie, but can’t figure out where I’m going wrong with the code. I’m thinking something with the timers? or sequence? If you can help or point me to some help that’d be wonderful.
Thanks again!
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <OneWire.h>
//DHT sensor
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
//water temp sensor
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Assign the addresses of your 1-Wire temp sensors.
DeviceAddress Probe01 = { 0x28, 0xFB, 0xD7, 0x34, 0x17, 0x13, 0x01, 0x0A }; //S1
DeviceAddress Probe02 = { 0x28, 0xA0, 0x8C, 0x16, 0x17, 0x13, 0x01, 0x4E }; //S2
DeviceAddress Probe03 = { 0x28, 0xC8, 0x57, 0x33, 0x17, 0x13, 0x01, 0xF3 }; //S3
DeviceAddress Probe04 = { 0x28, 0x38, 0x8E, 0x31, 0x17, 0x13, 0x01, 0x2B }; //S4
DeviceAddress Probe05 = { 0x28, 0xAB, 0x58, 0x2D, 0x17, 0x13, 0x01, 0x2B }; //S5
//Door Sensor
const int switchPin = 4;
SimpleTimer timer;
//Blynk token
char auth[] = "xxx";
// WiFi credentials.
char ssid[] = "FiOS-xxx";
char pass[] = "xxx";
//DHT Sensor
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(true);
Blynk.virtualWrite(V2, h);
Blynk.virtualWrite(V3, t);
}
//water temp sensor
void getTempData()
{
sensors.requestTemperatures();
Blynk.virtualWrite(V4, sensors.getTempFByIndex(0));
Blynk.virtualWrite(V5, sensors.getTempFByIndex(1));
Blynk.virtualWrite(V6, sensors.getTempFByIndex(2));
Blynk.virtualWrite(V7, sensors.getTempFByIndex(3));
Blynk.virtualWrite(V8, sensors.getTempFByIndex(4));
}
void setup()
{
Blynk.begin(auth, ssid, pass);
//DHT Sensor
dht.begin();
//watertemp sensor
sensors.begin();
sensors.setResolution(10);
//Door Sensor
pinMode(switchPin, INPUT_PULLUP);
digitalWrite(switchPin, LOW);
timer.setInterval(1000L, sendSensor);
timer.setInterval(1500L, getTempData);
}
void loop()
{
Blynk.run();
timer.run();
}