Cart 0

Blynk Joystick Access

Once you have the basic robot working, you can scale up your projects.

The Blynk Joystick is a UI widget in the Blynk IoT platform (Legacy app) that allows users to control 2-axis movement (X and Y) from a smartphone. It is commonly used to remotely control robots, camera gimbals, pan-tilt servos, or any device requiring directional input.

Platform Note: This report primarily covers Blynk Legacy (Blynk v0.6.1) , as the new Blynk 2.0 (IoT platform) has a different widget set. A modern alternative in Blynk 2.0 is the "Analog Joystick" or "Control Pad".

Here is the complete code to map the Blynk joystick to a differential drive robot (tank steering).

#define BLYNK_TEMPLATE_ID "YourTemplateID"
#define BLYNK_DEVICE_NAME "YourDeviceName"
#define BLYNK_AUTH_TOKEN "YourAuthToken"

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

// WiFi Credentials char ssid[] = "YourWiFiSSID"; char pass[] = "YourWiFiPassword"; blynk joystick

// Motor A (Left Side) int motorA_en = D1; // Enable pin (PWM Speed) int motorA_in1 = D2; int motorA_in2 = D3;

// Motor B (Right Side) int motorB_en = D4; // Enable pin (PWM Speed) int motorB_in1 = D5; int motorB_in2 = D6;

int xValue = 512; // Center default int yValue = 512;

// This function runs whenever the app sends new joystick data BLYNK_WRITE(V0) // X Axis xValue = param.asInt();

BLYNK_WRITE(V1) // Y Axis yValue = param.asInt(); Once you have the basic robot working, you

void setup() Serial.begin(115200);

// Set motor pins as outputs pinMode(motorA_en, OUTPUT); pinMode(motorA_in1, OUTPUT); pinMode(motorA_in2, OUTPUT); pinMode(motorB_en, OUTPUT); pinMode(motorB_in1, OUTPUT); pinMode(motorB_in2, OUTPUT);

Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

void loop() Blynk.run(); controlRobot();

void controlRobot() // Map joystick (0-1023) to motor speed (-255 to 255) // Center (512) = Stop int mappedX = map(xValue, 0, 1023, -255, 255); int mappedY = map(yValue, 0, 1023, -255, 255); BLYNK_WRITE(V1) // Y Axis yValue = param

int leftSpeed, rightSpeed;

// Differential Drive Logic leftSpeed = mappedY + mappedX; rightSpeed = mappedY - mappedX;

// Constrain values to PWM range leftSpeed = constrain(leftSpeed, -255, 255); rightSpeed = constrain(rightSpeed, -255, 255);

// Apply to Left Motor setMotor(motorA_in1, motorA_in2, motorA_en, leftSpeed);

// Apply to Right Motor setMotor(motorB_in1, motorB_in2, motorB_en, rightSpeed);

void setMotor(int in1, int in2, int en, int speed) if (speed >= 0) // Forward digitalWrite(in1, HIGH); digitalWrite(in2, LOW); analogWrite(en, speed); else // Backward digitalWrite(in1, LOW); digitalWrite(in2, HIGH); analogWrite(en, -speed);