Remote Control

ICT 361: Introduction to Robotics

Mr. Seng Theara

Learning Objective

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

Learning Objective

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

Remote

4 Buttons

Joystick

Remote

4 Push Buttons

Joystick

Function of Push Button

Function of Push Button

Function of Push Button

  • From this connection, we see that when the button is not pressed, the esp32 pin is connect to Vcc(3.3V). So, it means that it is HIGH
  • But when the Button is pressed, the esp32 pin flow into the GND. So, it means that it is LOW

Function of Push Button

  • From this connection, we see that when the button is not pressed, the esp32 pin is connect to Vcc(3.3V). So, it means that it is HIGH
  • But when the Button is pressed, the esp32 pin flow into the GND. So, it means that it is LOW

Pins of Push 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);
}

Pins of Push 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

Pins of Push 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

Pins of Push 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

We declare a button_up variable to read the state of the button to check whether it is pressed or not pressed 

Pins of Push 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

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

Code of Push 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

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

Function of Joystick

Function of Joystick

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

Function of Joystick

Y

X

0

0

4095

4095

2048

The ESP32 uses a 12-bit ADC (Analog-to-Digital Converter).

12-bit ADC represent:

2^{12} = 4096 \quad \text{These levels are numbered from }\quad 0 \rightarrow 4095

Function of Joystick


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);
}