//#include <Servo.h>
#include <ESP32Servo.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define BLYNK_TEMPLATE_ID "TMPL4m_KpjBRZ"
#define BLYNK_TEMPLATE_NAME "RS Car"
#define BLYNK_AUTH_TOKEN "KgGdpgbKxGpMnY81SM1ko7Y84t4yr5Ei"
#define BLYNK_PRINT Serial
char ssid[] = "Konstantin's IPhone";
char pass[] = "Koko021203";
const int potPin = 27; // Potentiometer
const int servoPin = 15; // Servo
const int buttonPin = 14; // Button
const int relayPin = 12; // Relay
const int ledPin = 13; // LED (DC motor)
Servo servoMotor;
void setup() {
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
servoMotor.attach(servoPin);// Attach the servo to its pin
pinMode(buttonPin, INPUT); // Set Button pin as input
pinMode(relayPin, OUTPUT); // Set Relay pin as output
pinMode(ledPin, OUTPUT); // Set LED pin as output
}
void loop() {
Blynk.run();
// Servo Block
int potValue = analogRead(potPin); // Read the potentiometer value
int servoPosition = map(potValue, 0, 4096, 0, 180); // Map the potentiometer value to servo position
servoMotor.write(servoPosition); // Move the servo to the mapped position
// LED Block (DC Block)
if (digitalRead(buttonPin) == LOW) { // Check if the button is pressed
digitalWrite(ledPin, LOW); // Turn on the LED
digitalWrite(relayPin, HIGH); // Activate the relay
Serial.print("DC Motor ON | ");
} else {
digitalWrite(ledPin, HIGH); // Turn off the LED
digitalWrite(relayPin, LOW); // Deactivate the relay
Serial.print("DC Motor OFF | ");
}
Serial.print("Potentiometer: ");
Serial.print(potValue);
Serial.print(" | Servo Position: ");
Serial.println(servoPosition);
delay(15);
}