Mr. Seng Theara
By the end of the lesson, student will be able to:
Understand how a joystick works electrically
Explain pull-up button logic
Read analog and digital signals
Map controller inputs to robot movements
Design basic control logic for robots
By the end of the lesson, student will be able to:
Understand how a joystick works electrically
Explain pull-up button logic
Read analog and digital signals
Map controller inputs to robot movements
Design basic control logic for robots
4 Buttons
Joystick
4 Push Buttons
Joystick
Pin 16
Pin 4
Pin 15
Pin 2
void setup() {
pinMode(16, INPUT);
Serial.begin(115200);
}
void loop() {
int button_up = digitalRead(16);
if (button_up == LOW){
Serial.println("Button Up is pressed");
}else{
Serial.println("Button Up isn't pressed");
}
delay(200);
}
Pin 16
Pin 4
Pin 15
Pin 2
void setup() {
pinMode(16, INPUT);
Serial.begin(115200);
}
void loop() {
int button_up = digitalRead(16);
if (button_up == LOW){
Serial.println("Button Up is pressed");
}else{
Serial.println("Button Up isn't pressed");
}
delay(200);
}
Declare pin 16 as INPUT because the esp32 read from the button
Pin 16
Pin 4
Pin 15
Pin 2
void setup() {
pinMode(16, INPUT);
Serial.begin(115200);
}
void loop() {
int button_up = digitalRead(16);
if (button_up == LOW){
Serial.println("Button Up is pressed");
}else{
Serial.println("Button Up isn't pressed");
}
delay(200);
}
Declare pin 16 as INPUT because the esp32 read from the button
Using baudrate of 115200
Pin 16
Pin 4
Pin 15
Pin 2
void setup() {
pinMode(16, INPUT);
Serial.begin(115200);
}
void loop() {
int button_up = digitalRead(16);
if (button_up == LOW){
Serial.println("Button Up is pressed");
}else{
Serial.println("Button Up isn't pressed");
}
delay(200);
}
Declare pin 16 as INPUT because the esp32 read from the button
Using baudrate of 115200
We declare a button_up variable to read the state of the button to check whether it is pressed or not pressed
Pin 16
Pin 4
Pin 15
Pin 2
void setup() {
pinMode(16, INPUT);
Serial.begin(115200);
}
void loop() {
int button_up = digitalRead(16);
if (button_up == LOW){
Serial.println("Button Up is pressed");
}else{
Serial.println("Button Up isn't pressed");
}
delay(200);
}
Declare pin 16 as INPUT because the esp32 read from the button
Using baudrate of 115200
We declare a button_up variable to read the state of the button to check whether it is pressed or not pressed
Finally, we have a condition to verify if the button_up is LOW, we print the button up is press. If not, print the button up isn't pressed
Pin 16
Pin 4
Pin 15
Pin 2
void setup() {
pinMode(16, INPUT);
Serial.begin(115200);
}
void loop() {
int button_up = digitalRead(16);
if (button_up == LOW){
Serial.println("Button Up is pressed");
}else{
Serial.println("Button Up isn't pressed");
}
delay(200);
}
Declare pin 16 as INPUT because the esp32 read from the button
Using baudrate of 115200
We declare a button_up variable to read the state of the button to check whether it is pressed or not pressed
Finally, we have a condition to verify if the button_up is LOW, we print the button up is pressed. If not, print the button up isn't pressed
A joystick is an input device that allows a user to control movement or direction by pushing a stick in different directions. It is widely used in robotics, gaming controllers, drones, and control panels.
| Movement | Axis | Typical Use |
|---|---|---|
| Left / Right | X-axis | Turning, steering |
| Up / Down | Y-axis | Forward / backward |
| Center | Neutral | Stop / idle |
Y
X
0
0
4095
4095
2048
The ESP32 uses a 12-bit ADC (Analog-to-Digital Converter).
12-bit ADC represent:
const int joyX = 34;
const int joyY = 35;
int xValue = 0;
int yValue = 0;
void setup() {
Serial.begin(115200);
// ADC pins do not need pinMode
Serial.println("ESP32 Joystick Reading Started");
}
void loop() {
xValue = analogRead(joyX); // 0 - 4095
yValue = analogRead(joyY); // 0 - 4095
Serial.print("X: ");
Serial.print(xValue);
Serial.print(" | Y: ");
Serial.println(yValue);
delay(200);
}