“风扇模块”的版本间的差异
来自YFRobotwiki
第2行: | 第2行: | ||
[[Image:风扇模块.jpg|400px|thumb|风扇模块]] | [[Image:风扇模块.jpg|400px|thumb|风扇模块]] | ||
[[Image:风扇模块1.jpg|400px|thumb|风扇模块]] | [[Image:风扇模块1.jpg|400px|thumb|风扇模块]] | ||
+ | |||
+ | |||
+ | === 产品简介 === | ||
+ | <br> | ||
+ | <strike>10K电位器采用WH148 10K电位器,3引脚直接焊接杜邦线,连接更方便!</strike> | ||
+ | |||
+ | 旋钮电位器模块采用立式旋钮10K电位器制作,采用PH2.0-3P统一接口,配合专用传感器线使用非常方便。 | ||
+ | |||
+ | 电位器的电阻体有两个固定端,通过手动调节旋钮,改变动触点在电阻体上的位置,则改变林动触点与任一固定端之间的电阻值,从而改变电压与电流大小。 | ||
+ | |||
+ | 将旋钮电位器模块加入项目中,可用来控制LED灯亮度、喇叭声音大小等。 | ||
+ | |||
+ | |||
+ | |||
+ | === 规格参数 === | ||
+ | <br> | ||
+ | *供电电压:DC3.3V~5V | ||
+ | *输出信号:模拟 | ||
+ | *阻值:10KΩ | ||
+ | *绝缘阻抗:100MΩ Min DC250V | ||
+ | *开关接触阻抗:< 50mΩ | ||
+ | *开关额定功率:1.0A at AC/DC 12V | ||
+ | *全回转角度:170°±5° | ||
+ | *旋转力距:20~200 gf.cm | ||
+ | *旋转止动强度:3.0Kgf.cm Min | ||
+ | *旋转寿命:10000 | ||
+ | *模块尺寸:28*21*24MM(长*宽*高) | ||
+ | *安装孔:3mm | ||
+ | *安装孔间距:15mm | ||
+ | *模块重量:3.8g | ||
+ | |||
+ | |||
+ | |||
+ | === 引脚说明 === | ||
+ | <br> | ||
+ | *1. G 黑线 -- Gnd(地) | ||
+ | *2. V 红线 -- Vcc(电源+5V) | ||
+ | *3. S 白线 -- 信号 | ||
+ | |||
+ | |||
+ | === 应用示例 === | ||
+ | <br> | ||
+ | |||
+ | '''电路连接示意图''' | ||
+ | <br> | ||
+ | :'''电位器模块'''的 G、V、S分别连接 '''Arduino UNO'''的GND、VCC(+5V)、A0引脚。 | ||
+ | <img src="http://wiki.yfrobot.com/image/sensor_circuit/potentiometer1.png-yf" alt="potentiometer1" /> | ||
+ | |||
+ | |||
+ | |||
+ | '''示例代码''' | ||
+ | <br><br> | ||
+ | <font color="darkcyan">'''示例一'''</font>:电位器值串口打印 | ||
+ | <br> | ||
+ | <pre > | ||
+ | /* | ||
+ | Potentiometer Test | ||
+ | */ | ||
+ | int pPin = A0; | ||
+ | int pVal = 0; | ||
+ | int pVal_old = 0; | ||
+ | void setup() | ||
+ | { | ||
+ | pinMode(pPin,INPUT); | ||
+ | Serial.begin(9600); | ||
+ | } | ||
+ | void loop() | ||
+ | { | ||
+ | //读取A0模拟口的数值(0-5V 对应 0-1204取值) | ||
+ | pVal = analogRead(pPin); | ||
+ | if(abs(pVal - pVal_old) >= 2 ){ | ||
+ | Serial.println(pVal); | ||
+ | pVal_old = pVal; | ||
+ | } | ||
+ | } | ||
+ | </pre> | ||
+ | 程序下载地址:[https://eyun.baidu.com/s/3miecpcc PotentiometerTest] | ||
+ | |||
+ | 程序运行结果:电位器值串口打印,结果如下图: | ||
+ | |||
+ | [[File:电位器串口输出.png|450px|center]] | ||
+ | |||
+ | |||
+ | <br><br> | ||
+ | <font color="darkcyan">'''示例二'''</font>:电位器控制[http://www.yfrobot.com/wiki/index.php?title=%E5%BD%A9%E8%89%B2LED%E6%A8%A1%E5%9D%97 彩色LED模块]变色 | ||
+ | <br> | ||
+ | '''电路连接示意图''' | ||
+ | |||
+ | <img src="http://wiki.yfrobot.com/image/sensor_circuit/potentiometer2.png-yf" alt="potentiometer2" /> | ||
+ | <br> | ||
+ | |||
+ | <pre> | ||
+ | |||
+ | /* | ||
+ | Potentiometer control RGB LED change color | ||
+ | */ | ||
+ | |||
+ | #include <Adafruit_NeoPixel.h> | ||
+ | |||
+ | #define RGBLEDPin 5 | ||
+ | #define NUMPIXELS 4 | ||
+ | #define pPin A0 | ||
+ | |||
+ | // Parameter 1 = number of pixels in strip | ||
+ | // Parameter 2 = pin number (most are valid) | ||
+ | // Parameter 3 = pixel type flags, add together as needed: | ||
+ | // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) | ||
+ | // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) | ||
+ | // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) | ||
+ | // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) | ||
+ | Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, RGBLEDPin, NEO_GRB + NEO_KHZ800); | ||
+ | |||
+ | int pVal = 0; | ||
+ | int RVal = 0; | ||
+ | int GVal = 0; | ||
+ | int BVal = 0; | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | pinMode(RGBLEDPin, OUTPUT); | ||
+ | pixels.begin(); // This initializes the NeoPixel library. | ||
+ | pixels.show(); | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | pVal = analogRead(pPin); //读取A0模拟口的数值(0-5V 对应 0-1203取值) | ||
+ | if (pVal >= 0 && pVal <= 170) { | ||
+ | RVal = 255; | ||
+ | GVal = 0; | ||
+ | BVal = map(pVal, 0, 170, 0, 255); | ||
+ | } else if (pVal > 170 && pVal <= 340) { | ||
+ | RVal = map(pVal, 170, 340, 255, 0); | ||
+ | GVal = 0; | ||
+ | BVal = 255; | ||
+ | } else if (pVal > 340 && pVal <= 510) { | ||
+ | RVal = 0; | ||
+ | GVal = map(pVal, 340, 510, 0, 255); | ||
+ | BVal = 255; | ||
+ | } else if (pVal > 510 && pVal <= 680) { | ||
+ | RVal = 0; | ||
+ | GVal = 255; | ||
+ | BVal = map(pVal, 510, 680, 255, 0); | ||
+ | } else if (pVal > 680 && pVal <= 850) { | ||
+ | RVal = map(pVal, 680, 850, 0, 255); | ||
+ | GVal = 255; | ||
+ | BVal = 0; | ||
+ | } else { | ||
+ | RVal = 255; | ||
+ | GVal = map(pVal, 850, 1023, 255, 0); | ||
+ | BVal = 0; | ||
+ | } | ||
+ | lightLED(RVal, GVal, BVal); | ||
+ | } | ||
+ | |||
+ | void lightLED(int r, int g , int b) { | ||
+ | // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one. | ||
+ | for (int i = 0; i < NUMPIXELS; i++) { | ||
+ | // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 | ||
+ | pixels.setPixelColor(i, r, g, b); // Moderately bright green color. | ||
+ | pixels.show(); // This sends the updated pixel color to the hardware. | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | 程序下载地址:[https://eyun.baidu.com/s/3dFaSHgP ChangeColor] | ||
+ | |||
+ | 程序运行结果:转动电位器,彩色led变色。 | ||
+ | |||
+ | |||
+ | |||
+ | <!-- | ||
+ | ===参考资料=== | ||
+ | <br> | ||
+ | --> | ||
+ | |||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | |||
+ | [[首页 | 返回首页]] | ||
+ | |||
+ | 更多建议和问题欢迎反馈至 [http://www.yfrobot.com YFRobot论坛] | ||
+ | |||
+ | 购买方式:[http://yfrobot.taobao.com/ YFRobot 电子工作室] |
2019年12月2日 (一) 16:21的版本
产品简介
10K电位器采用WH148 10K电位器,3引脚直接焊接杜邦线,连接更方便!
旋钮电位器模块采用立式旋钮10K电位器制作,采用PH2.0-3P统一接口,配合专用传感器线使用非常方便。
电位器的电阻体有两个固定端,通过手动调节旋钮,改变动触点在电阻体上的位置,则改变林动触点与任一固定端之间的电阻值,从而改变电压与电流大小。
将旋钮电位器模块加入项目中,可用来控制LED灯亮度、喇叭声音大小等。
规格参数
- 供电电压:DC3.3V~5V
- 输出信号:模拟
- 阻值:10KΩ
- 绝缘阻抗:100MΩ Min DC250V
- 开关接触阻抗:< 50mΩ
- 开关额定功率:1.0A at AC/DC 12V
- 全回转角度:170°±5°
- 旋转力距:20~200 gf.cm
- 旋转止动强度:3.0Kgf.cm Min
- 旋转寿命:10000
- 模块尺寸:28*21*24MM(长*宽*高)
- 安装孔:3mm
- 安装孔间距:15mm
- 模块重量:3.8g
引脚说明
- 1. G 黑线 -- Gnd(地)
- 2. V 红线 -- Vcc(电源+5V)
- 3. S 白线 -- 信号
应用示例
电路连接示意图
- 电位器模块的 G、V、S分别连接 Arduino UNO的GND、VCC(+5V)、A0引脚。
示例代码
示例一:电位器值串口打印
/* Potentiometer Test */ int pPin = A0; int pVal = 0; int pVal_old = 0; void setup() { pinMode(pPin,INPUT); Serial.begin(9600); } void loop() { //读取A0模拟口的数值(0-5V 对应 0-1204取值) pVal = analogRead(pPin); if(abs(pVal - pVal_old) >= 2 ){ Serial.println(pVal); pVal_old = pVal; } }
程序下载地址:PotentiometerTest
程序运行结果:电位器值串口打印,结果如下图:
生成缩略图出错:文件可能丢失:
示例二:电位器控制彩色LED模块变色
电路连接示意图
/* Potentiometer control RGB LED change color */ #include <Adafruit_NeoPixel.h> #define RGBLEDPin 5 #define NUMPIXELS 4 #define pPin A0 // Parameter 1 = number of pixels in strip // Parameter 2 = pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, RGBLEDPin, NEO_GRB + NEO_KHZ800); int pVal = 0; int RVal = 0; int GVal = 0; int BVal = 0; void setup() { pinMode(RGBLEDPin, OUTPUT); pixels.begin(); // This initializes the NeoPixel library. pixels.show(); } void loop() { pVal = analogRead(pPin); //读取A0模拟口的数值(0-5V 对应 0-1203取值) if (pVal >= 0 && pVal <= 170) { RVal = 255; GVal = 0; BVal = map(pVal, 0, 170, 0, 255); } else if (pVal > 170 && pVal <= 340) { RVal = map(pVal, 170, 340, 255, 0); GVal = 0; BVal = 255; } else if (pVal > 340 && pVal <= 510) { RVal = 0; GVal = map(pVal, 340, 510, 0, 255); BVal = 255; } else if (pVal > 510 && pVal <= 680) { RVal = 0; GVal = 255; BVal = map(pVal, 510, 680, 255, 0); } else if (pVal > 680 && pVal <= 850) { RVal = map(pVal, 680, 850, 0, 255); GVal = 255; BVal = 0; } else { RVal = 255; GVal = map(pVal, 850, 1023, 255, 0); BVal = 0; } lightLED(RVal, GVal, BVal); } void lightLED(int r, int g , int b) { // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one. for (int i = 0; i < NUMPIXELS; i++) { // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 pixels.setPixelColor(i, r, g, b); // Moderately bright green color. pixels.show(); // This sends the updated pixel color to the hardware. } }
程序下载地址:ChangeColor
程序运行结果:转动电位器,彩色led变色。
更多建议和问题欢迎反馈至 YFRobot论坛
购买方式:YFRobot 电子工作室