#define BLYNK_TEMPLATE_ID "TMPL3SWu6Blpi"
#define BLYNK_TEMPLATE_NAME "e vehicle"
#define BLYNK_AUTH_TOKEN "81t0rQC-Fj3ZYM3ZWvzfcZ0U8tAWpAHQ"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
// Blynk Auth Token
char auth[] = "81t0rQC-Fj3ZYM3ZWvzfcZ0U8tAWpAHQ";
// WiFi credentials
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// Motor control pins
#define DIR_PIN 19
#define STEP_PIN 18
#define ENABLE_PIN 21
// Thermistor pin
#define THERMISTOR_PIN 34
BlynkTimer timer;
// Function to read the thermistor and send the value to Blynk
void readThermistor() {
int thermistorValue = analogRead(THERMISTOR_PIN);
Serial.print("Thermistor Value: ");
Serial.println(thermistorValue);
Blynk.virtualWrite(V1, thermistorValue); // Send thermistor value to Virtual Pin V1
}
// Function to control the motor
void stepMotor(int steps, bool direction) {
digitalWrite(DIR_PIN, direction);
for (int i = 0; i < steps; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(500); // Adjust delay for speed control
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(500); // Adjust delay for speed control
}
}
void setup() {
// Initialize serial communication for debugging
Serial.begin(115200);
// Initialize motor control pins
pinMode(DIR_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
pinMode(ENABLE_PIN, OUTPUT);
// Enable the motor driver
digitalWrite(ENABLE_PIN, LOW);
// Connect to WiFi and Blynk
Blynk.begin(auth, ssid, pass);
// Setup a function to be called every second
timer.setInterval(1000L, readThermistor);
}
void loop() {
Blynk.run();
timer.run();
// Example movement: Rotate in one direction for 200 steps, then reverse
stepMotor(200, HIGH); // 200 steps forward
delay(1000); // Wait 1 second
stepMotor(200, LOW); // 200 steps backward
delay(1000); // Wait 1 second
}