HS-KEY4B Independent push-button switch module 4P

HS-KEY4B  Independent push-button switch module 4P

1. Introduction

2. Schematic

4P push button module HS-KEY4B schematicClick to view

Module Parameters

Pin Name

description

G

GND (Negative Power Input)

V

VCC (Positive Power Input)

1

Digital Signal Pin

2

Digital Signal Pin

3

Digital Signal Pin

4

Digital Signal Pin

  • Power Supply Voltage: 3.3V / 5V

  • Connection Type: 2.54mm Header

  • Installation Method: Double Screw Fixed

4, Circuit Board Size

5 of Arduino IDE example program

Attention: If prompted with an error message about the library file during program upload, please import the library file first!
Arduino IDE Library Download and Import Tutorial:
Click to view

Example program (UNO development board):

volatile int light;

void setup(){
  light = 0;
  pinMode(9, OUTPUT);
  analogWrite(9, 0);
  pinMode(6, INPUT);
  pinMode(5, INPUT);
  pinMode(4, INPUT);
  pinMode(3, INPUT);
}

void loop(){
  //led็ฏๆŽฅD9ๅผ•่„š๏ผšๅ››ไฝๆŒ‰้”ฎๆจกๅ—1~4ๅˆ†ๅˆซๆŽฅๅผ€ๅ‘ๆฟ3๏ผŒ4๏ผŒ5๏ผŒ6

  if (digitalRead(6) == 0) {
    light = 0;

  } else if (digitalRead(5) == 0) {
    light = 30;
  } else if (digitalRead(4) == 0) {
    light = 125;
  } else if (digitalRead(3) == 0) {
    light = 255;
  }
  delay(10);
  analogWrite(9, light);

}

6, ESP32 Python Example (for Mixly IDE/Misashi)

Choose the development board Python ESP32 [ESP32 Generic(4MB)] and upload in code mode

Attention: If prompted with an error message about the library file during program upload, please import the library file first!
Download and import tutorial for Mixly IDE ESP32 library:
Click to view

Example program (ESP32-Python):

import machine


pin39 = machine.Pin(39, machine.Pin.IN)
pin36 = machine.Pin(36, machine.Pin.IN)
pin35 = machine.Pin(35, machine.Pin.IN)
pin34 = machine.Pin(34, machine.Pin.IN)
pwm2 = machine.PWM(machine.Pin(2))
light = 0
while True:
    if pin39.value() == 0:
        light = 0
    elif pin36.value() == 0:
        light = 15000
    elif pin35.value() == 0:
        light = 30000
    elif pin34.value() == 0:
        light = 60000
    pwm2.duty_u16(light)

7, Mixly example program (graphical language)

Example program (UNO development board):Click to download
Attention: If prompted with an error message about the library file during program upload, please import the library file first!
Download and import tutorial of Mixly IDE Arduino library:Click to view

Example Program (ESP32 Development Board):Click to download
Attention: If prompted with an error message about the library file during program upload, please import the library file first!
Download and import tutorial for Mixly IDE ESP32 library:
Click to view

8. Setting up the Test Environment

Arduino UNO Test Environment Setup

Prepare Components:

  • HELLO STEM UNO R3 PRO DEVELOPMENT BOARD *1

  • USB TYPE-C DATA CABLE *1

  • LED light module (HS-F08A) *1

  • Independent key switch module (HS-KEY4B) *1

  • 1P female-to-female Dupont wire *9 or 3P female-to-female Dupont wire *3

Circuit wiring diagram:

ESP32 Test Environment Setup

Prepare Components:Pending update...

Circuit wiring diagram:Pending update...

9, Video tutorial

Video tutorial:Click to view

10, Test results

Arduino UNO test results: