0% found this document useful (0 votes)
4 views2 pages

Blynk Stepper Code

This document contains code for controlling a stepper motor using an ESP8266 microcontroller and Blynk application. It connects to WiFi and allows for clockwise and counterclockwise rotation of the motor via virtual buttons. The code utilizes the AccelStepper library for motor control and includes setup and loop functions for operation.

Uploaded by

aadiwsn123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Blynk Stepper Code

This document contains code for controlling a stepper motor using an ESP8266 microcontroller and Blynk application. It connects to WiFi and allows for clockwise and counterclockwise rotation of the motor via virtual buttons. The code utilizes the AccelStepper library for motor control and includes setup and loop functions for operation.

Uploaded by

aadiwsn123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#define BLYNK_TEMPLATE_ID "TMPL3V_hfySQx"

#define BLYNK_TEMPLATE_NAME "stepper"


#define BLYNK_AUTH_TOKEN "F-mPg7_lrEyB03DbayVIMwuZEQCKgQox"

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <AccelStepper.h>

// WiFi credentials
const char ssid[] = "Moto";
const char pass[] = "anas@1234";

// Stepper motor pins (ULN2003)


#define IN1 D5 // GPIO14
#define IN2 D6 // GPIO12
#define IN3 D7 // GPIO13
#define IN4 D8 // GPIO15

// Virtual pins
#define buttonClockwisePin V1
#define buttonCounterclockwisePin V2

// Initialize AccelStepper
AccelStepper stepper(AccelStepper::HALF4WIRE, IN1, IN3, IN2, IN4);

void setup() {
Serial.begin(115200);

// Start WiFi and Blynk


WiFi.begin(ssid, pass);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi connected");

Blynk.config(BLYNK_AUTH_TOKEN);
while (!Blynk.connect()) {
Serial.println("Connecting to Blynk...");
delay(1000);
}
Serial.println("Blynk connected");

// Motor setup
stepper.setMaxSpeed(500);
stepper.setAcceleration(100);
}

void loop() {
Blynk.run();
stepper.runSpeed(); // Non-blocking
}
// Clockwise rotation
BLYNK_WRITE(buttonClockwisePin) {
int state = param.asInt();
if (state == 1) {
stepper.setSpeed(500);
stepper.enableOutputs();
Serial.println("Clockwise");
} else {
stepper.setSpeed(0);
stepper.disableOutputs();
Serial.println("Motor Stopped");
}
}

// Counterclockwise rotation
BLYNK_WRITE(buttonCounterclockwisePin) {
int state = param.asInt();
if (state == 1) {
stepper.setSpeed(-500);
stepper.enableOutputs();
Serial.println("Counterclockwise");
} else {
stepper.setSpeed(0);
stepper.disableOutputs();
Serial.println("Motor Stopped");
}
}

You might also like