Could someone verify my Arduino code for electric gates
The electric gates are simply not doing what the code is stating to do. Relay flickering issues, NODE MCU becoming unresponsive and not performing what is meant to happen.
This is for controlling electric gates from multiple phones using the Blynk app.
The setup of the board includes using relays which will be switched on and off to control power going to each of the two gates and changing the direction of the power which inverts the gates directional position, I'm also using a shift register to control signals being sent to the gates as there aren't enough pins on the NODE MCU (I have included at the top of the code in comments of which pin from the shift register does what).
I have tried this system on a much smaller scale which only included using one gate arm to test if the code would work and it did, I then expanded onto the code to include both of the gates - this included having to add additional logic to allow one gate to continue opening/closing if the other gate has already reached its destination (the destination/endpoint of each gate is determined by a button on either end of each of the motors which when the corresponding button is pressed it will then allow the logic to see the state change, this does work however, it does flick the relays on and off and will stop power going to both sides of the gates even if one hasn't reached its destination yet.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Shift Regsiter
// 2 - Power Supply
// 3 - Gate Left Power
// 4 - Gate Right Power
// 6 - Gate Switch
// 7 - LEDs
// Button stoppers
int btnLeftStopperOpened = D5;
int btnLeftStopperClosed = D6;
int btnRightStopperOpened = D7;
int btnRightStopperClosed = D3;
int btnLeftStopperOpenedState = LOW;
int btnLeftStopperClosedState = LOW;
int btnRightStopperOpenedState = LOW;
int btnRightStopperClosedState = LOW;
// Shift register pins
int latchPin = D0;
int clockPin = D1;
int dataPin = D2;
byte data = 0b00000000;
// WiFi details
char auth = "0a5a18c1a9f2457eb842013ec8f5fef3";
char ssid = "SKYCEDB2";
char pass = "LVDLBSBQSC";
// Blynk digital LED
WidgetLED indicatorLED(V3);
// Button booleans
bool openGateBool = false;
bool closeGateBool = false;
bool emergencyStopBool = false;
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Inputs
pinMode(btnLeftStopperOpened, INPUT);
pinMode(btnLeftStopperClosed, INPUT);
pinMode(btnRightStopperOpened, INPUT);
pinMode(btnRightStopperClosed, INPUT);
// Outputs
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
// Clear Shift Register
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
bitClear(data, 7);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Blynk virtual buttons
BLYNK_WRITE(V0) {
openGateBool = !openGateBool;
}
BLYNK_WRITE(V1) {
closeGateBool = !closeGateBool;
}
BLYNK_WRITE(V2) {
emergencyStopBool = !emergencyStopBool;
}
void loop() {
Blynk.run();
// Detect Button States
btnLeftStopperOpenedState = digitalRead(btnLeftStopperOpened);
btnRightStopperOpenedState = digitalRead(btnRightStopperOpened);
btnLeftStopperClosedState = digitalRead(btnLeftStopperClosed);
btnRightStopperClosedState = digitalRead(btnRightStopperClosed);
// Stability Delay
delay(10);
// Open gate function
if((openGateBool == true) && (closeGateBool == false)) {
// Initial Gate Check
if((btnLeftStopperOpenedState == LOW) && (btnRightStopperOpenedState == LOW)) {
bitSet(data, 2);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// If both gates are opened
if((btnLeftStopperOpenedState == HIGH) && (btnRightStopperOpenedState == HIGH)) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#23C48E");
indicatorLED.on();
}
// Left Gate Opening
if(btnLeftStopperOpenedState == LOW) {
bitSet(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Right Gate Opening
if(btnRightStopperOpenedState == LOW) {
bitSet(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Emergency Stop button
if(emergencyStopBool == true) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
delay(900);
indicatorLED.off();
delay(900);
}
}
// Close gate function
if((openGateBool == false) && (closeGateBool == true)) {
// Initial Gate Check
if((btnLeftStopperClosedState == LOW) && (btnRightStopperClosedState == LOW)) {
bitSet(data, 2);
bitSet(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// If both gates are closed
if((btnLeftStopperClosedState == LOW) && (btnRightStopperClosedState == LOW)) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
}
// Left Gate Closing
if(btnLeftStopperClosedState == LOW) {
bitSet(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Right Gate Closing
if(btnRightStopperClosedState == LOW) {
bitSet(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Emergency Stop button
if(emergencyStopBool == true) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
delay(900);
indicatorLED.off();
delay(900);
}
}
// Checks gate status
if((btnLeftStopperClosedState == LOW) && (btnRightStopperClosedState == LOW) && (btnLeftStopperOpenedState == LOW) && (btnRightStopperOpenedState == LOW)) {
indicatorLED.off();
}
// Checks if both buttons are false
if((openGateBool == false) && (closeGateBool == false)) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Emergency Stop button
if(emergencyStopBool == true) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
delay(900);
indicatorLED.off();
delay(900);
}
} // END //
When the OPEN button on the Blynk app is pressed the code performs a check to see if the OPEN state buttons are set to HIGH - if not then it turns on the power supply, another check is performed which will control each gates power delivery until it reaches its destination, once it has reached the destination it will stop. The same is meant to happen for the CLOSE button on the Blynk app but with the inclusion of turning the switch on along with the power supply. There is also an emergency stop button which allows for the button to be pressed in the Blynk app to shutdown everything.
Instead what happens is one button works (I Have verified to insure the virtual pin is correct)
The emergency button doesn't stop
If one gate reaches its destination it stops both gates instead of just the one
The relays keep flickering on and off while the destination goal has been reached by either gate
NODE MCU sometimes locks itself up
arduino nodemcu blynk
add a comment |
The electric gates are simply not doing what the code is stating to do. Relay flickering issues, NODE MCU becoming unresponsive and not performing what is meant to happen.
This is for controlling electric gates from multiple phones using the Blynk app.
The setup of the board includes using relays which will be switched on and off to control power going to each of the two gates and changing the direction of the power which inverts the gates directional position, I'm also using a shift register to control signals being sent to the gates as there aren't enough pins on the NODE MCU (I have included at the top of the code in comments of which pin from the shift register does what).
I have tried this system on a much smaller scale which only included using one gate arm to test if the code would work and it did, I then expanded onto the code to include both of the gates - this included having to add additional logic to allow one gate to continue opening/closing if the other gate has already reached its destination (the destination/endpoint of each gate is determined by a button on either end of each of the motors which when the corresponding button is pressed it will then allow the logic to see the state change, this does work however, it does flick the relays on and off and will stop power going to both sides of the gates even if one hasn't reached its destination yet.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Shift Regsiter
// 2 - Power Supply
// 3 - Gate Left Power
// 4 - Gate Right Power
// 6 - Gate Switch
// 7 - LEDs
// Button stoppers
int btnLeftStopperOpened = D5;
int btnLeftStopperClosed = D6;
int btnRightStopperOpened = D7;
int btnRightStopperClosed = D3;
int btnLeftStopperOpenedState = LOW;
int btnLeftStopperClosedState = LOW;
int btnRightStopperOpenedState = LOW;
int btnRightStopperClosedState = LOW;
// Shift register pins
int latchPin = D0;
int clockPin = D1;
int dataPin = D2;
byte data = 0b00000000;
// WiFi details
char auth = "0a5a18c1a9f2457eb842013ec8f5fef3";
char ssid = "SKYCEDB2";
char pass = "LVDLBSBQSC";
// Blynk digital LED
WidgetLED indicatorLED(V3);
// Button booleans
bool openGateBool = false;
bool closeGateBool = false;
bool emergencyStopBool = false;
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Inputs
pinMode(btnLeftStopperOpened, INPUT);
pinMode(btnLeftStopperClosed, INPUT);
pinMode(btnRightStopperOpened, INPUT);
pinMode(btnRightStopperClosed, INPUT);
// Outputs
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
// Clear Shift Register
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
bitClear(data, 7);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Blynk virtual buttons
BLYNK_WRITE(V0) {
openGateBool = !openGateBool;
}
BLYNK_WRITE(V1) {
closeGateBool = !closeGateBool;
}
BLYNK_WRITE(V2) {
emergencyStopBool = !emergencyStopBool;
}
void loop() {
Blynk.run();
// Detect Button States
btnLeftStopperOpenedState = digitalRead(btnLeftStopperOpened);
btnRightStopperOpenedState = digitalRead(btnRightStopperOpened);
btnLeftStopperClosedState = digitalRead(btnLeftStopperClosed);
btnRightStopperClosedState = digitalRead(btnRightStopperClosed);
// Stability Delay
delay(10);
// Open gate function
if((openGateBool == true) && (closeGateBool == false)) {
// Initial Gate Check
if((btnLeftStopperOpenedState == LOW) && (btnRightStopperOpenedState == LOW)) {
bitSet(data, 2);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// If both gates are opened
if((btnLeftStopperOpenedState == HIGH) && (btnRightStopperOpenedState == HIGH)) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#23C48E");
indicatorLED.on();
}
// Left Gate Opening
if(btnLeftStopperOpenedState == LOW) {
bitSet(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Right Gate Opening
if(btnRightStopperOpenedState == LOW) {
bitSet(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Emergency Stop button
if(emergencyStopBool == true) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
delay(900);
indicatorLED.off();
delay(900);
}
}
// Close gate function
if((openGateBool == false) && (closeGateBool == true)) {
// Initial Gate Check
if((btnLeftStopperClosedState == LOW) && (btnRightStopperClosedState == LOW)) {
bitSet(data, 2);
bitSet(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// If both gates are closed
if((btnLeftStopperClosedState == LOW) && (btnRightStopperClosedState == LOW)) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
}
// Left Gate Closing
if(btnLeftStopperClosedState == LOW) {
bitSet(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Right Gate Closing
if(btnRightStopperClosedState == LOW) {
bitSet(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Emergency Stop button
if(emergencyStopBool == true) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
delay(900);
indicatorLED.off();
delay(900);
}
}
// Checks gate status
if((btnLeftStopperClosedState == LOW) && (btnRightStopperClosedState == LOW) && (btnLeftStopperOpenedState == LOW) && (btnRightStopperOpenedState == LOW)) {
indicatorLED.off();
}
// Checks if both buttons are false
if((openGateBool == false) && (closeGateBool == false)) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Emergency Stop button
if(emergencyStopBool == true) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
delay(900);
indicatorLED.off();
delay(900);
}
} // END //
When the OPEN button on the Blynk app is pressed the code performs a check to see if the OPEN state buttons are set to HIGH - if not then it turns on the power supply, another check is performed which will control each gates power delivery until it reaches its destination, once it has reached the destination it will stop. The same is meant to happen for the CLOSE button on the Blynk app but with the inclusion of turning the switch on along with the power supply. There is also an emergency stop button which allows for the button to be pressed in the Blynk app to shutdown everything.
Instead what happens is one button works (I Have verified to insure the virtual pin is correct)
The emergency button doesn't stop
If one gate reaches its destination it stops both gates instead of just the one
The relays keep flickering on and off while the destination goal has been reached by either gate
NODE MCU sometimes locks itself up
arduino nodemcu blynk
you can post this to the community.blynk.cc maybe someone there may help you
– Dmitriy Dumanskiy
Jan 11 at 9:08
add a comment |
The electric gates are simply not doing what the code is stating to do. Relay flickering issues, NODE MCU becoming unresponsive and not performing what is meant to happen.
This is for controlling electric gates from multiple phones using the Blynk app.
The setup of the board includes using relays which will be switched on and off to control power going to each of the two gates and changing the direction of the power which inverts the gates directional position, I'm also using a shift register to control signals being sent to the gates as there aren't enough pins on the NODE MCU (I have included at the top of the code in comments of which pin from the shift register does what).
I have tried this system on a much smaller scale which only included using one gate arm to test if the code would work and it did, I then expanded onto the code to include both of the gates - this included having to add additional logic to allow one gate to continue opening/closing if the other gate has already reached its destination (the destination/endpoint of each gate is determined by a button on either end of each of the motors which when the corresponding button is pressed it will then allow the logic to see the state change, this does work however, it does flick the relays on and off and will stop power going to both sides of the gates even if one hasn't reached its destination yet.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Shift Regsiter
// 2 - Power Supply
// 3 - Gate Left Power
// 4 - Gate Right Power
// 6 - Gate Switch
// 7 - LEDs
// Button stoppers
int btnLeftStopperOpened = D5;
int btnLeftStopperClosed = D6;
int btnRightStopperOpened = D7;
int btnRightStopperClosed = D3;
int btnLeftStopperOpenedState = LOW;
int btnLeftStopperClosedState = LOW;
int btnRightStopperOpenedState = LOW;
int btnRightStopperClosedState = LOW;
// Shift register pins
int latchPin = D0;
int clockPin = D1;
int dataPin = D2;
byte data = 0b00000000;
// WiFi details
char auth = "0a5a18c1a9f2457eb842013ec8f5fef3";
char ssid = "SKYCEDB2";
char pass = "LVDLBSBQSC";
// Blynk digital LED
WidgetLED indicatorLED(V3);
// Button booleans
bool openGateBool = false;
bool closeGateBool = false;
bool emergencyStopBool = false;
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Inputs
pinMode(btnLeftStopperOpened, INPUT);
pinMode(btnLeftStopperClosed, INPUT);
pinMode(btnRightStopperOpened, INPUT);
pinMode(btnRightStopperClosed, INPUT);
// Outputs
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
// Clear Shift Register
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
bitClear(data, 7);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Blynk virtual buttons
BLYNK_WRITE(V0) {
openGateBool = !openGateBool;
}
BLYNK_WRITE(V1) {
closeGateBool = !closeGateBool;
}
BLYNK_WRITE(V2) {
emergencyStopBool = !emergencyStopBool;
}
void loop() {
Blynk.run();
// Detect Button States
btnLeftStopperOpenedState = digitalRead(btnLeftStopperOpened);
btnRightStopperOpenedState = digitalRead(btnRightStopperOpened);
btnLeftStopperClosedState = digitalRead(btnLeftStopperClosed);
btnRightStopperClosedState = digitalRead(btnRightStopperClosed);
// Stability Delay
delay(10);
// Open gate function
if((openGateBool == true) && (closeGateBool == false)) {
// Initial Gate Check
if((btnLeftStopperOpenedState == LOW) && (btnRightStopperOpenedState == LOW)) {
bitSet(data, 2);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// If both gates are opened
if((btnLeftStopperOpenedState == HIGH) && (btnRightStopperOpenedState == HIGH)) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#23C48E");
indicatorLED.on();
}
// Left Gate Opening
if(btnLeftStopperOpenedState == LOW) {
bitSet(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Right Gate Opening
if(btnRightStopperOpenedState == LOW) {
bitSet(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Emergency Stop button
if(emergencyStopBool == true) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
delay(900);
indicatorLED.off();
delay(900);
}
}
// Close gate function
if((openGateBool == false) && (closeGateBool == true)) {
// Initial Gate Check
if((btnLeftStopperClosedState == LOW) && (btnRightStopperClosedState == LOW)) {
bitSet(data, 2);
bitSet(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// If both gates are closed
if((btnLeftStopperClosedState == LOW) && (btnRightStopperClosedState == LOW)) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
}
// Left Gate Closing
if(btnLeftStopperClosedState == LOW) {
bitSet(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Right Gate Closing
if(btnRightStopperClosedState == LOW) {
bitSet(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Emergency Stop button
if(emergencyStopBool == true) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
delay(900);
indicatorLED.off();
delay(900);
}
}
// Checks gate status
if((btnLeftStopperClosedState == LOW) && (btnRightStopperClosedState == LOW) && (btnLeftStopperOpenedState == LOW) && (btnRightStopperOpenedState == LOW)) {
indicatorLED.off();
}
// Checks if both buttons are false
if((openGateBool == false) && (closeGateBool == false)) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Emergency Stop button
if(emergencyStopBool == true) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
delay(900);
indicatorLED.off();
delay(900);
}
} // END //
When the OPEN button on the Blynk app is pressed the code performs a check to see if the OPEN state buttons are set to HIGH - if not then it turns on the power supply, another check is performed which will control each gates power delivery until it reaches its destination, once it has reached the destination it will stop. The same is meant to happen for the CLOSE button on the Blynk app but with the inclusion of turning the switch on along with the power supply. There is also an emergency stop button which allows for the button to be pressed in the Blynk app to shutdown everything.
Instead what happens is one button works (I Have verified to insure the virtual pin is correct)
The emergency button doesn't stop
If one gate reaches its destination it stops both gates instead of just the one
The relays keep flickering on and off while the destination goal has been reached by either gate
NODE MCU sometimes locks itself up
arduino nodemcu blynk
The electric gates are simply not doing what the code is stating to do. Relay flickering issues, NODE MCU becoming unresponsive and not performing what is meant to happen.
This is for controlling electric gates from multiple phones using the Blynk app.
The setup of the board includes using relays which will be switched on and off to control power going to each of the two gates and changing the direction of the power which inverts the gates directional position, I'm also using a shift register to control signals being sent to the gates as there aren't enough pins on the NODE MCU (I have included at the top of the code in comments of which pin from the shift register does what).
I have tried this system on a much smaller scale which only included using one gate arm to test if the code would work and it did, I then expanded onto the code to include both of the gates - this included having to add additional logic to allow one gate to continue opening/closing if the other gate has already reached its destination (the destination/endpoint of each gate is determined by a button on either end of each of the motors which when the corresponding button is pressed it will then allow the logic to see the state change, this does work however, it does flick the relays on and off and will stop power going to both sides of the gates even if one hasn't reached its destination yet.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Shift Regsiter
// 2 - Power Supply
// 3 - Gate Left Power
// 4 - Gate Right Power
// 6 - Gate Switch
// 7 - LEDs
// Button stoppers
int btnLeftStopperOpened = D5;
int btnLeftStopperClosed = D6;
int btnRightStopperOpened = D7;
int btnRightStopperClosed = D3;
int btnLeftStopperOpenedState = LOW;
int btnLeftStopperClosedState = LOW;
int btnRightStopperOpenedState = LOW;
int btnRightStopperClosedState = LOW;
// Shift register pins
int latchPin = D0;
int clockPin = D1;
int dataPin = D2;
byte data = 0b00000000;
// WiFi details
char auth = "0a5a18c1a9f2457eb842013ec8f5fef3";
char ssid = "SKYCEDB2";
char pass = "LVDLBSBQSC";
// Blynk digital LED
WidgetLED indicatorLED(V3);
// Button booleans
bool openGateBool = false;
bool closeGateBool = false;
bool emergencyStopBool = false;
void setup() {
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Inputs
pinMode(btnLeftStopperOpened, INPUT);
pinMode(btnLeftStopperClosed, INPUT);
pinMode(btnRightStopperOpened, INPUT);
pinMode(btnRightStopperClosed, INPUT);
// Outputs
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
// Clear Shift Register
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
bitClear(data, 7);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Blynk virtual buttons
BLYNK_WRITE(V0) {
openGateBool = !openGateBool;
}
BLYNK_WRITE(V1) {
closeGateBool = !closeGateBool;
}
BLYNK_WRITE(V2) {
emergencyStopBool = !emergencyStopBool;
}
void loop() {
Blynk.run();
// Detect Button States
btnLeftStopperOpenedState = digitalRead(btnLeftStopperOpened);
btnRightStopperOpenedState = digitalRead(btnRightStopperOpened);
btnLeftStopperClosedState = digitalRead(btnLeftStopperClosed);
btnRightStopperClosedState = digitalRead(btnRightStopperClosed);
// Stability Delay
delay(10);
// Open gate function
if((openGateBool == true) && (closeGateBool == false)) {
// Initial Gate Check
if((btnLeftStopperOpenedState == LOW) && (btnRightStopperOpenedState == LOW)) {
bitSet(data, 2);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// If both gates are opened
if((btnLeftStopperOpenedState == HIGH) && (btnRightStopperOpenedState == HIGH)) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#23C48E");
indicatorLED.on();
}
// Left Gate Opening
if(btnLeftStopperOpenedState == LOW) {
bitSet(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Right Gate Opening
if(btnRightStopperOpenedState == LOW) {
bitSet(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Emergency Stop button
if(emergencyStopBool == true) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
delay(900);
indicatorLED.off();
delay(900);
}
}
// Close gate function
if((openGateBool == false) && (closeGateBool == true)) {
// Initial Gate Check
if((btnLeftStopperClosedState == LOW) && (btnRightStopperClosedState == LOW)) {
bitSet(data, 2);
bitSet(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// If both gates are closed
if((btnLeftStopperClosedState == LOW) && (btnRightStopperClosedState == LOW)) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
}
// Left Gate Closing
if(btnLeftStopperClosedState == LOW) {
bitSet(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 3);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Right Gate Closing
if(btnRightStopperClosedState == LOW) {
bitSet(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
} else {
bitClear(data, 4);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Emergency Stop button
if(emergencyStopBool == true) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
delay(900);
indicatorLED.off();
delay(900);
}
}
// Checks gate status
if((btnLeftStopperClosedState == LOW) && (btnRightStopperClosedState == LOW) && (btnLeftStopperOpenedState == LOW) && (btnRightStopperOpenedState == LOW)) {
indicatorLED.off();
}
// Checks if both buttons are false
if((openGateBool == false) && (closeGateBool == false)) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
}
// Emergency Stop button
if(emergencyStopBool == true) {
bitClear(data, 2);
bitClear(data, 3);
bitClear(data, 4);
bitClear(data, 6);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, data);
digitalWrite(latchPin, HIGH);
// Blynk LED indicator
Blynk.setProperty(V3, "color", "#D3435C");
indicatorLED.on();
delay(900);
indicatorLED.off();
delay(900);
}
} // END //
When the OPEN button on the Blynk app is pressed the code performs a check to see if the OPEN state buttons are set to HIGH - if not then it turns on the power supply, another check is performed which will control each gates power delivery until it reaches its destination, once it has reached the destination it will stop. The same is meant to happen for the CLOSE button on the Blynk app but with the inclusion of turning the switch on along with the power supply. There is also an emergency stop button which allows for the button to be pressed in the Blynk app to shutdown everything.
Instead what happens is one button works (I Have verified to insure the virtual pin is correct)
The emergency button doesn't stop
If one gate reaches its destination it stops both gates instead of just the one
The relays keep flickering on and off while the destination goal has been reached by either gate
NODE MCU sometimes locks itself up
arduino nodemcu blynk
arduino nodemcu blynk
asked Dec 28 '18 at 17:46
Jordan H.Jordan H.
204
204
you can post this to the community.blynk.cc maybe someone there may help you
– Dmitriy Dumanskiy
Jan 11 at 9:08
add a comment |
you can post this to the community.blynk.cc maybe someone there may help you
– Dmitriy Dumanskiy
Jan 11 at 9:08
you can post this to the community.blynk.cc maybe someone there may help you
– Dmitriy Dumanskiy
Jan 11 at 9:08
you can post this to the community.blynk.cc maybe someone there may help you
– Dmitriy Dumanskiy
Jan 11 at 9:08
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962378%2fcould-someone-verify-my-arduino-code-for-electric-gates%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962378%2fcould-someone-verify-my-arduino-code-for-electric-gates%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
you can post this to the community.blynk.cc maybe someone there may help you
– Dmitriy Dumanskiy
Jan 11 at 9:08