Hi Everyone,
My project working on a 24V signal alarm system using NodeMCU and Blynk.
When a 24V signal is ON, it will be converted into 3.3V and input to one pin onboard.
When the pin sense it becomes HIGH, a bit value will be sent,
(e.g. D0 pin sent bit(0), D1 pin sent bit(1), D2 pin sent bit(2)…till D10)
otherwise, ZERO will be sent.
(i.e. the program would like to know the hardware status on the board, NOT the widget status)
The program will scan the pin status for every 15 seconds, and the status and the real time will be written into V1 pin, so that I can view V1 value on HTTP API.
However, by the characteristic of D3 / D4 pin on NodeMCU, it is always HIGH when the board is reset, even I defined those are INPUT pin.
For example, if Now D0, D1, D2 are HIGH, the status now should be 000 0000 0111,
but if the board is disconnected from the WiFi or power, after re-connected the board,
the status will be 000 0001 1111.(in real condition, D3 and D4 do not have any 24V signal come in)
I need to reset the D3 D4 pin by clicking the responding button widgets on BLYNK app once, then the problem will be solved, but I dont want to do this by manually, even I try to use digitalWrite(D3, LOW) in setup(), it can’t work. Any one could help me on this?
Below are my codes
#define BLYNK_PRINT Serial //#define BLYNK_MAX_SENDBYTES 128 #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> #include <WiFiUdp.h> #include <NTPClient.h> char auth[] = "xxx"; char ssid[] = "xxx"; char pass[] = "xxx"; const String SiteNo = "YYY"; String formattedDate; WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP); volatile word bFlag; //Status of whole system volatile word bFlag0; //Status of air blower 1 volatile word bFlag1; //Status of air blower 2 volatile word bFlag2; //Status of air blower 3 volatile word bFlag3; //Status of air blower 4 volatile word bFlag4; //Status of air blower 5 volatile word bFlag5; //Status of air blower 6 volatile word bFlag6; //Status of air blower 7 volatile word bFlag7; //Status of air blower 8 volatile word bFlag8; //Status of air blower 9 volatile word bFlag9; //Status of air blower 10 volatile word bFlag10; //Status of air blower 11 int powerpin = 16; int eqHigh = 5; int eqLow = 4; int mbrHigh = 0; int mbrLow = 2; int b1pin = 14; int b2pin = 12; int p1pin = 13; int p2pin = 15; int p3pin = 3; int p4pin = 1; BlynkTimer timer; BlynkTimer timer1; void setup() { // Debug console Serial.begin(115200); Blynk.begin(auth, ssid, pass); Blynk.notify(String(SiteNo) + " online"); pinMode(powerpin, INPUT); //Initial is 0V pinMode(eqHigh, INPUT); //Initial is 0V pinMode(eqLow, INPUT); //Initial is 0V pinMode(mbrHigh, INPUT); //Initial is 0V pinMode(mbrLow, INPUT); //Initial is 0V pinMode(b1pin, INPUT); //Initial is 0V pinMode(b2pin, INPUT); //Initial is 0V pinMode(p1pin, INPUT); //Initial is 0V pinMode(p2pin, INPUT); //Initial is 0V pinMode(p3pin, INPUT); //Initial is 0V pinMode(p4pin, INPUT); //Initial is 0V digitalWrite(mbrHigh, LOW); digitalWrite(mbrLow, LOW); timer.setInterval(30000L, system_status); timer1.setInterval(15000L, signal_read); timeClient.begin(); timeClient.setTimeOffset(28800); } void signal_read() { int PowerFault = digitalRead(powerpin); //Power Supply if (PowerFault == HIGH) //if this pin is 3.3V bFlag0 = bit(0); //this byte changes to 000 0000 0001 else if (PowerFault == LOW) bFlag0 = 0x00; //if this pin is 0v, changes to 0000 0000 int EQTankH = digitalRead(eqHigh); //Eq tank high level if (EQTankH == HIGH) //if this pin is 3.3V bFlag1 = bit(1); //this byte changes to 000 0000 0010 else if (EQTankH == LOW) bFlag1 = 0x00; //if this pin is 0v, changes to 0000 0000 int EQTankL = digitalRead(eqLow); //Eq tank low level if (EQTankL == HIGH) //if this pin is 3.3V bFlag2 = bit(2); //this byte changes to 000 0000 0100 else if (EQTankL == LOW) bFlag2 = 0x00; //if this pin is 0v, changes to 0000 0000 int MBRTankH = digitalRead(mbrHigh); //mbr high level if (MBRTankH == HIGH) //if this pin is 3.3V bFlag3 = bit(3); //this byte changes to 000 0000 1000 else if (MBRTankH == LOW) bFlag3 = 0x00; //if this pin is 0v, changes to 0000 0000 int MBRTankL = digitalRead(mbrLow); //mbr low level if (MBRTankL == HIGH) //if this pin is 3.3V bFlag4 = bit(4); //this byte changes to 000 0001 0000 else if (MBRTankL == LOW) bFlag4 = 0x00; //if this pin is 0v, changes to 0000 0000 int B1Fault = digitalRead(b1pin); //Air Blower No.1 fault if (B1Fault == HIGH) //if this pin is 3.3V bFlag5 = bit(5); //this byte changes to 000 0010 0000 else if (B1Fault == LOW) bFlag5 = 0x00; //if this pin is 0v, changes to 0000 0000 int B2Fault = digitalRead(b2pin); //Air Blower No.2 fault if (B2Fault == HIGH) //if this pin is 3.3V bFlag6 = bit(6); //this byte changes to 000 0100 0000 else if (B2Fault == LOW) bFlag6 = 0x00; //if this pin is 0v, changes to 0000 0000 int P1Fault = digitalRead(p1pin); //P1 pump fault if (P1Fault == HIGH) //if this pin is 3.3V bFlag7 = bit(7); //this byte changes to 000 1000 0000 else if (P1Fault == LOW) bFlag7 = 0x00; //if this pin is 0v, changes to 0000 0000 int P2Fault = digitalRead(p2pin); //P2 pump fault if (P2Fault == HIGH) //if this pin is 3.3V bFlag8 = bit(8); //this byte changes to 001 0000 0000 else if (P2Fault == LOW) bFlag8 = 0x00; //if this pin is 0v, changes to 0000 0000 int P3Fault = digitalRead(p3pin); //P3 pump fault if (P3Fault == HIGH) //if this pin is 3.3V bFlag9 = bit(9); //this byte changes to 010 0000 0000 else if (P3Fault == LOW) bFlag9 = 0x00; //if this pin is 0v, changes to 0000 0000 int P4Fault = digitalRead(p4pin); //P4 pump fault if (P4Fault == HIGH) //if this pin is 3.3V bFlag10 = bit(10); //this byte changes to 100 0000 0000 else if (P4Fault == LOW) bFlag10 = 0x00; //if this pin is 0v, changes to 0000 0000 } void system_status() { bFlag = bFlag0 |= bFlag1 |= bFlag2 |= bFlag3 |= bFlag4 |= bFlag5 |= bFlag6 |= bFlag7 |= bFlag8 |= bFlag9 |= bFlag10; timeClient.update(); formattedDate = timeClient.getFormattedDate(); String message = String(bFlag, BIN) + " " + String(formattedDate); Blynk.virtualWrite(V1, String(message)); Blynk.notify(String(SiteNo) + " "+ String(message)); } void loop() { Blynk.run(); timer.run(); timer1.run(); }