HS-S28P Rotary Potentiometer

HS-S28P Rotary Potentiometer

1. Introduction

2. Schematic

Tilt Potentiometer-HS-S28P SchematicClick to view

Module Parameters

Pin Name

description

G

GND (Negative Power Input)

V

VCC (Positive Power Input)

S

Analog Signal Pin

  • Power Supply Voltage: 3.3V / 5V

  • Connection method: PH2.0 terminal wire

  • 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):

float Voltage;//定义电压变量
float data;//定义电位器模拟值变量
int light;//定义LED灯亮度变量

void setup() {
  Serial.begin(9600);//设置串口波特率
  pinMode(A0, INPUT);//电位器电压输出接口
  pinMode(6, OUTPUT);
}

void loop() {
  data = analogRead(A0);//获取电位器电压模拟值
  Voltage = (data / 978) * 5;//模拟值和数字值转换 * 电压得到当前电压,模拟正常最大为1023,978为实际电位器模拟值最大值
  light = (map(constrain(analogRead(A0), 0, 978), 0, 978, 0, 255));//将电位器电压模拟值缩放至light变量以符合模拟输出取值范围,正常模拟输出PWM波取值为0-255
  Serial.print("Voltage is:");
  Serial.print(Voltage);//打印获取到的电压
  Serial.print("V");
  Serial.print("    light is:");//打印LED的亮度值
  Serial.println(light);
  analogWrite(6, light);//将light值转变为PWM波占空比从6号口输出。
  delay(100); //延时0.1秒

}

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
from mixpy import math_map


value = 0
light = 0
adc32 = machine.ADC(machine.Pin(32))
pwm2 = machine.PWM(machine.Pin(2))
while True:
    value = adc32.read_u16()
    light = (math_map(value, 0, 65535, 65535, 0))
    pwm2.duty_u16(int(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 DEVELOPMENT BOARD *1

  • HELLO STEM UNO R3 P EXPANSION BOARD *1

  • USB TYPE-C DATA CABLE *1

  • LED light module (HS-F08A) *1

  • rotary potentiometer module (HS-S28P) *1

  • PH2.0 3P terminal to DuPont wire *2 or PH2.0 3P dual-head terminal wire *2

Circuit wiring diagram:Pending update...

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:

ESP32 Test Results:

Pending update...