This is my first post and I'm excited to get started.
My first project is a water meter. I'm using a JSN-SR04T ultrasonic, DHT11, and a ESP-12E.
The ultrasonic seems to work great. I receive consistent, accurate readings.
I've not been so lucky with the DHT11. I receive one reading on reset or upload then the values disappear. I've tried different pullup resistors, no pullup resistor, changed delay times, and always the same result--one reading with no followup readings. I can reset again and get one temp/humidity reading right away then nothing. I just finished a four-saturday Arduino class so I'm a bit green. Can anyone help point me in the right direction?
WiFi connected
IP address:
192.168.0.8
Netmask:
255.255.255.0
Gateway:
192.168.0.1
Humidity: 37.00 % Temperature: 23.00 *C 73.40 *F Heat index: 22.32 *C 72.18 *F
Object: 142cm
Humidity: nan % Temperature: nan *C nan *F Heat index: nan *C nan *F
Object: 147cm
Humidity: nan % Temperature: nan *C nan *F Heat index: nan *C nan *F
Object: 147cm
Humidity: nan % Temperature: nan *C nan *F Heat index: nan *C nan *F
Object: 142cm
Humidity: nan % Temperature: nan *C nan *F Heat index: nan *C nan *F
Object: 142cm
Source:
#include <DHT.h>
#include <NewPing.h>
#include <ESP8266WiFi.h>
const char* MY_SSID = "MYSSID";
const char* MY_PWD = "MYPWD";
#define TRIGGER_PIN 5 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 4 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
#define DHTPIN 14
#define DHTTYPE DHT11
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
DHT dht(DHTPIN, DHTTYPE, 15);
void setup() {
Serial.begin(115000); // Open serial monitor at 115200 baud to see ping results.
// pinMode(DHTPIN, INPUT_PULLUP); experimenting with different pinmodes to see what happens
dht.begin();
connectWifi();
}
void loop() {
delay(5000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
// if (isnan(h) || isnan(t) || isnan(f)) {
// Serial.println("Failed to read from DHT sensor!");
// return;
//}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
delay(1000);
Serial.print("Object: ");
Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.println("cm");
delay(1000);
}
void connectWifi()
{
Serial.print("Connecting to "+*MY_SSID);
WiFi.begin(MY_SSID, MY_PWD);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Netmask: ");
Serial.println(WiFi.subnetMask());
Serial.println("Gateway: ");
Serial.println(WiFi.gatewayIP());
delay(1000);
}