Esp8266 Blynk joystick controlled car iot
https://www.youtube.com/watch?v=j9WElxmOn9Y
code google drive:
https://drive.google.com/drive/folders/1Dzggg0uWqo-vX_NLhRMcb-rjQFAHM1aX?usp=sharing
code ESP8266
#define BLYNK_TEMPLATE_ID "TMPLFE9ZetHp" #define BLYNK_DEVICE_NAME "Quickstart Template" #define BLYNK_AUTH_TOKEN "xFve4e_c4es_fWjAfHO4SxYssp7yV7bf" #define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> #include<Servo.h> #define PWMA D1 #define DIRA D3 #define PWMB D2 #define DIRB D4 Servo servo; int x,y,z; int minRange=312; int maxRange=712; char auth[] = BLYNK_AUTH_TOKEN; // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "Ghost Rider";//"Ghost Rider"; Your Wifi's name char pass[] = "1984Nvdt";//"1984Nvdt";Your password Wifi BlynkTimer timer; void moveControl(int x, int y) { //No Move if(y < maxRange && y > minRange && x < maxRange && x > minRange) { analogWrite(PWMA, 0); analogWrite(PWMB, 0); } //Move Forward else if(y >= maxRange && x >= minRange && x<= maxRange) { //Serial.println("Tiến"); analogWrite(PWMA, y); analogWrite(PWMB, y); digitalWrite(DIRA, HIGH); digitalWrite(DIRB, HIGH);
} //Move Forward Right else if(x >= maxRange && y >= maxRange) { analogWrite(PWMA,y); analogWrite(PWMB,y); digitalWrite(DIRA, HIGH); digitalWrite(DIRB, LOW);
} //Move Forward Left else if(x <= minRange && y >= maxRange) { analogWrite(PWMA,y); analogWrite(PWMB,y); digitalWrite(DIRA, LOW); digitalWrite(DIRB, HIGH);
} //Move Backward else if(y <= minRange && x >= minRange && x <= maxRange) { analogWrite(PWMA, y); analogWrite(PWMB, y); digitalWrite(DIRA, LOW); digitalWrite(DIRB, LOW);
} } void setup() { // Debug console Serial.begin(9600); Blynk.begin(auth, ssid, pass); // timer.setInterval(1000L, myTimerEvent); //khai báo các chân analog điều khiển tốc độ
pinMode(PWMA, OUTPUT); pinMode(DIRA, OUTPUT); pinMode(PWMB, OUTPUT); pinMode(DIRB, OUTPUT);
analogWrite(PWMA, 0); analogWrite(PWMB, 0); servo.attach(13); // NodeMCU D7 pin } void loop() { Blynk.run(); timer.run(); } BLYNK_WRITE(V6) { servo.write(param.asInt()); } BLYNK_WRITE(V4) { x = param[0].asInt(); moveControl(x,y); } BLYNK_WRITE(V5) { y = param[0].asInt(); moveControl(x,y); } |
Powered by Froala Editor
;