Product Introduction #
The 4-button module contains four presses, and the circuit is on when a button is pressed and disconnected when it is released. Because the four key switches share one analog output, they can only be connected to the analog port. Each key corresponds to an analog value, so as to realize the discrimination of different keys.
Application reference: remote control, keyboard, game controller, etc.
Parameter Specification #
Parameter | Value/Description |
Operating voltage | 3.3V~5V |
Operating temperature | -40°C~+80°C |
Output signal | Analog signal |
Size | 4.7cm*2.4cm |
Wiring Diagram #
Note: Expansion board is attached to esp32 controller board.
4-Button Module | ESP32 |
S | 32 |
VCC | 5V |
GND | GND |
Sample Code #
int n = 0;
void setup(){
Serial.begin(115200);//Set baud rate
}
void loop(){
n = analogRead(32);//Define the analog pin for the 4-Button
//Print different button values
if(n<10){ Serial.println("Right: "+String(n)); } else if(n>10 && n<=1000){ Serial.println("Down: "+String(n)); } else if(n>1000 && n<=3000){ Serial.println("Left: "+String(n)); } else if(n>3000 && n<=4000){
Serial.println("Up: "+String(n));
}
delay(300);
}
Note: If you are using an Arduino board, then change the pin in the program to PIN A0, set the baud rate to 9600, and then connect the hardware pin to PIN A0 and upload the program.
You also need to change the value range of Button in the program.
Right:<10
Down:10~200
Left:300~600
Up:600~1000
Test Result #
When you successfully connect the line according to the wiring diagram and successfully upload the correct program, when a certain button is pressed, the serial port monitor will print the corresponding button value.