Good morning.
While programming a weather station on an ESP8266 NodeMcu v3, I encountered a problem. When nothing is connected on the pin there is a high state, despite changing the state to 0. Here is the program code:
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <DHT.h>
#include <Rtc_Pcf8563.h>
#define DHT_SENSOR_PIN D7 // The ESP8266 pin D7 connected to DHT22 sensor
#define DHT_SENSOR_TYPE DHT22
DHT dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);
#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10
Rtc_Pcf8563 rtc;
Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // SPI hardware
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
int Fc_37 = D6;
int greenLED = 226;
int redLED = 2227;
// you can adjust the threshold value
int thresholdValue = 500;
int sensor = A0; //pin analog A0 connected to the photoresistor leg
int direction wind = 15; //pin D8
int wind direction1 = 5; // Pin D5
int stronawiatru = 0;
int stronawiatru1 = 0;
void setup() {
Serial.begin(9600);
Serial.println(F("BMP280 test"));
dht_sensor.begin();
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}
pinMode(directionwiatr, INPUT);
pinMode(directionwiatr1, INPUT);
pinMode(Fc_37, INPUT);
}
void loop() {
//RTC
Serial.print("Time:");
Serial.print(rtc.formatTime());
Serial.print("Date:");
Serial.println(rtc.formatDate());
//rtc
//direction sensor
stronawiatru=digitalRead(directionwind);
Serial.println(stronawiatru);
stronawiatru1=digitalRead(directionwiatr1);
Serial.println(stronawiatru1);
if(stronawiatru1 == HIGH && stronawiatru == HIGH){
Serial.println("WIEJEEEE from the north!!!");
}
else if(stronawiatru1 == HIGH){
Serial.println("WEEEEE from the west!!!")
}
else if(stronawiatru == HIGH){
Serial.println("KNOWEEE northwest!");
}
else if (stronawiatru1 == LOW && stronawiatru == LOW){
Serial.println("No wind@");
}
// direction sensor
// photoresistor
int war = analogRead(sensor); //read value from A1
Serial.print(war); //display it on the monitor
//when the value exceeds a certain fixed threshold, then the LED on pin 13 will light up
Serial.println(""); // photoresistor
int sensorValue = analogRead(Fc_37);//Fc_37
Serial.print(sensorValue);
if(sensorValue < thresholdValue){
Serial.println(" - It's wet");
}
else {
Serial.println(" - It's dry");
} //Fc_37
// read humidity
float humi = dht_sensor.readHumidity();
// read temperature in Celsius
float temperature_C = dht_sensor.readTemperature();
// read temperature in Fahrenheit
float temperature_F = dht_sensor.readTemperature(true);
Serial.print(Fc_37);
// check whether the reading is successful or not
if ( isnan(temperature_C) || isnan(temperature_F) || isnan(humi)) {
Serial.println("Failed to read from DHT sensor!");
} else {
Serial.print("Humidity: ");
Serial.print(humi);
Serial.print("%");
Serial.print(" | ");
Serial.print("Temperature: ");
Serial.print(temperature_C);
Serial.print("°C ~ ");
Serial.print(temperature_F);
Serial.println("°F");
}
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure());
Serial.println(" Pa");
Serial.print("Approx altitude = ");
Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
Serial.println(" m");
Serial.println();
delay(2000);
}
It's about the reed switch on D5, On D8 it reacts as it is supposed to (when a magnet is approaching it shows a high state, when no magnet is present it shows a low state) When I tried to change to a different location it still shows a high state everywhere (D5). Even when I do not connect anything to the pin I am programming.
While programming a weather station on an ESP8266 NodeMcu v3, I encountered a problem. When nothing is connected on the pin there is a high state, despite changing the state to 0. Here is the program code:
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <DHT.h>
#include <Rtc_Pcf8563.h>
#define DHT_SENSOR_PIN D7 // The ESP8266 pin D7 connected to DHT22 sensor
#define DHT_SENSOR_TYPE DHT22
DHT dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);
#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10
Rtc_Pcf8563 rtc;
Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // SPI hardware
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
int Fc_37 = D6;
int greenLED = 226;
int redLED = 2227;
// you can adjust the threshold value
int thresholdValue = 500;
int sensor = A0; //pin analog A0 connected to the photoresistor leg
int direction wind = 15; //pin D8
int wind direction1 = 5; // Pin D5
int stronawiatru = 0;
int stronawiatru1 = 0;
void setup() {
Serial.begin(9600);
Serial.println(F("BMP280 test"));
dht_sensor.begin();
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}
pinMode(directionwiatr, INPUT);
pinMode(directionwiatr1, INPUT);
pinMode(Fc_37, INPUT);
}
void loop() {
//RTC
Serial.print("Time:");
Serial.print(rtc.formatTime());
Serial.print("Date:");
Serial.println(rtc.formatDate());
//rtc
//direction sensor
stronawiatru=digitalRead(directionwind);
Serial.println(stronawiatru);
stronawiatru1=digitalRead(directionwiatr1);
Serial.println(stronawiatru1);
if(stronawiatru1 == HIGH && stronawiatru == HIGH){
Serial.println("WIEJEEEE from the north!!!");
}
else if(stronawiatru1 == HIGH){
Serial.println("WEEEEE from the west!!!")
}
else if(stronawiatru == HIGH){
Serial.println("KNOWEEE northwest!");
}
else if (stronawiatru1 == LOW && stronawiatru == LOW){
Serial.println("No wind@");
}
// direction sensor
// photoresistor
int war = analogRead(sensor); //read value from A1
Serial.print(war); //display it on the monitor
//when the value exceeds a certain fixed threshold, then the LED on pin 13 will light up
Serial.println(""); // photoresistor
int sensorValue = analogRead(Fc_37);//Fc_37
Serial.print(sensorValue);
if(sensorValue < thresholdValue){
Serial.println(" - It's wet");
}
else {
Serial.println(" - It's dry");
} //Fc_37
// read humidity
float humi = dht_sensor.readHumidity();
// read temperature in Celsius
float temperature_C = dht_sensor.readTemperature();
// read temperature in Fahrenheit
float temperature_F = dht_sensor.readTemperature(true);
Serial.print(Fc_37);
// check whether the reading is successful or not
if ( isnan(temperature_C) || isnan(temperature_F) || isnan(humi)) {
Serial.println("Failed to read from DHT sensor!");
} else {
Serial.print("Humidity: ");
Serial.print(humi);
Serial.print("%");
Serial.print(" | ");
Serial.print("Temperature: ");
Serial.print(temperature_C);
Serial.print("°C ~ ");
Serial.print(temperature_F);
Serial.println("°F");
}
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure());
Serial.println(" Pa");
Serial.print("Approx altitude = ");
Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
Serial.println(" m");
Serial.println();
delay(2000);
}
It's about the reed switch on D5, On D8 it reacts as it is supposed to (when a magnet is approaching it shows a high state, when no magnet is present it shows a low state) When I tried to change to a different location it still shows a high state everywhere (D5). Even when I do not connect anything to the pin I am programming.