Need to replace timer for limit switch

Hello im new to blynk i was hoping some one could give me some advice. i have a wemos d1 mini and managed to incorporate simple timer control a relay that is connected to dc motor . what i would like to do is use a limit switch to deactivate the relay and shut to motor off instead. can any one steer me in the right direction on how to achieve this. here is the sketch i would like to change.

> #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
> #include <ESP8266WiFi.h>
> #include <BlynkSimpleEsp8266.h>
> #include <SimpleTimer.h>
> SimpleTimer timer;
> // You should get Auth Token in the Blynk App.
> // Go to the Project Settings (nut icon).
> char auth[] = "**********************";
> // Your WiFi credentials.
> // Set password to "" for open networks.
> char ssid[] = "******";
> char pass[] = "******";
> void setup()
> {
>   Serial.begin(9600);
>   Blynk.begin(auth, ssid, pass);
>   pinMode (5, OUTPUT);
>  }
> //pasted code starts here
>    if (param.asInt()==1){  // act only on the HIGH and not the LOW of the momentary
>     digitalWrite(5, !digitalRead(5));  // invert pin state just once
>     timer.setTimeout(100L, [](){
>     digitalWrite(5, !digitalRead(5));  // then invert it back after 100ms
>   Blynk.virtualWrite(V1, LOW);
>     });
>     }
> }
> //pasted code ends here
> void loop()
> {
> }


pls edit your post and put your code inside a code block.

and what is a ‘limit switch’?

I’d attach an interrupt to the pin tha the limit switch is connected to, and use that to trigger a stop to the mother rotation.


A common reference to physical switches that prevent the linear or rotational movement of a mechanical part past it’s allowable limits, even if physically possible.

It is up to you to figure out the mechanics of the limit switches… well… and the programming :stuck_out_tongue: but basically you just wire up your switches to digital inputs and have some form of monitoring, either before the next ‘move’ or via hardware interrupts that will force a stop to the motor.

This is NOT a Blynk relevant issue… it will usually be done in the device code, so you can find lots of code references with 3D printer code, robotic arm movement, etc.

EDIT - it can also be done in electrical/mechanical ways that physically cut the power, usually used as more of a fail safe in addition to MCU control, but can be a bit confusing to wire up a switch that breaks the circuit for movement in only one direction. Google for that option as well.