hello, I want to add a limit switch to stop the code I wrote, but I couldn’t succeed, can you help me?
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Stepper.h> // Include the header file
#define BLYNK_PRINT Serial
// change this to the number of steps on your motor
#define STEPS 64
// create an instance of the stepper class using the steps and pins
Stepper stepper(STEPS, D0, D7, D6, D5);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "BXJHLmqGmwlUF8WZuTHBrdhpGYpvZAdG";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "AirTies_Air5650_7GD7";
char pass[] = "123onr456";
//Run the program only after opening the blinds
boolean closed = false;
boolean opened = true;
void disable_motor() //turn off the motor when done to avoid heating
{
digitalWrite(D1,LOW);
digitalWrite(D2,LOW);
digitalWrite(D3,LOW);
digitalWrite(D4,LOW);
}
void setup()
{
pinMode(D0, OUTPUT); //on-board LED as output
digitalWrite(D0,HIGH); //turn this light on
Serial.begin(9600);
stepper.setSpeed(500);
Blynk.begin(auth, ssid, pass);
//http://188.166.206.43/l_b47mF1hioCc_7FzdKMJJeFnJjxxxx_/update/V1?value=1 /
digitalWrite(D0,LOW); //turn it off after connecting to blynk
}
BLYNK_WRITE(V1) //CLOSE the BLINDS
{
Serial.println("Closing Blinds");
if (opened == true)
{
for (int c_val = 0; c_val <= 130; c_val++) //rotate in Counter-Clockwise for closing
{
stepper.step(c_val);
yield();
}
closed = true;
opened = false;
disable_motor(); // always desable stepper motors after use to reduce power consumption and heating
}
}
BLYNK_WRITE(V2) // OPEN the BLINDS
{
Serial.println("Opening Blinds");
if (closed == true)
{
for (int cc_val = 0; cc_val >= -130; cc_val--) //rotate in Clockwise for opening
{
stepper.step(cc_val);
yield();
}
opened = true;
closed = false;
}
disable_motor(); // always desable stepper motors after use to reduce power consumption and heating
}
void loop()
{
Blynk.run();
}