Good day everyone, please i need help with my project. I’m trying to use my ESP32 and the blynk app as a transmitter and a receiver in my drone project and i don’t know what I’m doing wrong cause it’s not working but i only get an output reading in the serial monitor. Here’s the code i used
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "****"
#define BLYNK_TEMPLATE_NAME "****"
#define BLYNK_AUTH_TOKEN "***"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*****";
char pass[] = "****";
//Change the pin numbers as per your connections and board used
#define channel_pin_1 16 //Throttle
#define channel_pin_2 17 //Roll
#define channel_pin_3 18 //Pitch
#define channel_pin_4 19 //Yaw
#define channel_pin_5 21 //Flight Mode
#define status_led 13 //LED for WiFi status indication
int input_YAW, input_PITCH, input_ROLL, throttle, flight_mode, dummy;
Servo channel_1, channel_2, channel_3, channel_4, channel_5;
BLYNK_WRITE(0)
{
throttle = param.asInt();
}
BLYNK_WRITE(1)
{
input_YAW = param.asInt();
}
BLYNK_WRITE(2){
input_PITCH = param.asInt();
}
BLYNK_WRITE(3){
input_ROLL = param.asInt();
}
BLYNK_WRITE(4){
flight_mode = param.asInt();
}
BLYNK_WRITE(5){
dummy = param.asInt();
}
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(status_led,OUTPUT);
digitalWrite(status_led,HIGH); // LED on when not connected to cloud
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
if(Blynk.connected()){
digitalWrite(status_led, LOW); // LED off when connected to cloud
}
channel_1.attach(channel_pin_1); // Throttle output to Flight Controller
channel_2.attach(channel_pin_2); // Roll output to Flight Controller
channel_3.attach(channel_pin_3); // Pitch output to Flight Controller
channel_4.attach(channel_pin_4); // Yaw output to Flight Controller
channel_5.attach(channel_pin_5); // Flight Mode output to Flight Controller
}
void loop()
{
if(!Blynk.connected()){ //On disconnection with the cloud
digitalWrite(status_led, HIGH);
}
channel_1.writeMicroseconds(throttle); // Sending throttle data to flight controller
channel_2.writeMicroseconds(input_ROLL); // Sending roll data to flight controller
channel_3.writeMicroseconds(input_PITCH); // Sending pitch data to flight controller
channel_4.writeMicroseconds(input_YAW); // Sending yaw data to flight controller
channel_5.writeMicroseconds(flight_mode); // Sending flight mode data to flight controller
//Printing data in serial monitor
Serial.print(throttle);
Serial.print('\t');
Serial.print(input_ROLL);
Serial.print('\t');
Serial.print(input_PITCH);
Serial.print('\t');
Serial.print(input_YAW);
Serial.print('\t');
Serial.println(flight_mode);
Blynk.run();
}