Sunday, November 26, 2023

किसी भी पुरानी कार को बनाओ wifi कार | using Node Mcu


(9v battery is used. you may use upload 12v battery)









esp8266 Code
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "template id"
#define BLYNK_TEMPLATE_NAME "Template name"
#define BLYNK_AUTH_TOKEN "pasteHere"
#define BLYNK_FIRMWARE_VERSION "0.0.1"

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

/* WIFI INFO*******************************************/

const char ssid[] = "wifi name" ;
const char pass[] = "password" ;

const int PIN_IN1 = 5; //D1
const int PIN_IN2 = 4; //D2
const int PIN_IN3 = 14; //D5
const int PIN_IN4 = 12; //D6
/*
D1 5
D2 4
D3 0
D4 2
D5 14
D6 12
D7 13
D8 15
*/

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

BLYNK_WRITE(V1){
Serial.println("move front");
int value = param.asInt();

if(param.asInt() == 1){ digitalWrite(PIN_IN1, HIGH); digitalWrite(PIN_IN3, HIGH);
}else{ digitalWrite(PIN_IN1, LOW); digitalWrite(PIN_IN3, LOW); }
Blynk.virtualWrite(V1, value);}

BLYNK_WRITE(V2){
Serial.println("move back");
int value = param.asInt();

if(param.asInt() == 1) {digitalWrite(PIN_IN2, HIGH); digitalWrite(PIN_IN4, HIGH);
} else { digitalWrite(PIN_IN2, LOW); digitalWrite(PIN_IN4, LOW); }
Blynk.virtualWrite(V2, value);
}

BLYNK_WRITE(V3){
Serial.println("move right");
int value = param.asInt();

if(param.asInt() == 1) { digitalWrite(PIN_IN2, HIGH);
}else { digitalWrite(PIN_IN2, LOW); }
Blynk.virtualWrite(V3, value);}

BLYNK_WRITE(V4){
Serial.println("move left");
int value = param.asInt();
if(param.asInt() == 1) { digitalWrite(PIN_IN4, HIGH);
} else { digitalWrite(PIN_IN4, LOW); }
Blynk.virtualWrite(V4, value);
}

// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED(){
Blynk.syncVirtual(V1); // will cause BLYNK_WRITE(V0) to be executed
Blynk.syncVirtual(V2); // will cause BLYNK_WRITE(V0) to be executed
Blynk.syncVirtual(V3); // will cause BLYNK_WRITE(V0) to be executed
Blynk.syncVirtual(V4); // will cause BLYNK_WRITE(V0) to be executed
}

void setup()
{
Serial.begin(115200);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

pinMode(PIN_IN1, OUTPUT);
pinMode(PIN_IN2, OUTPUT);
pinMode(PIN_IN3, OUTPUT);
pinMode(PIN_IN4, OUTPUT);

/*off by default*/
digitalWrite(PIN_IN1, LOW);
digitalWrite(PIN_IN2, LOW);
digitalWrite(PIN_IN3, LOW);
digitalWrite(PIN_IN4, LOW);

//lastMilliSec = millis();
}

void loop()
{
Blynk.run();
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.