Grayscale Sensor
Module Source
Purchase Link:
https://detail.tmall.com/item.htm?abbucket=0&id=676917570259&ns=1&spm=a21n57.1.0.0.6a6b523c8GDuHU
Baidu Netdisk Download Link:
Specifications
Operating Voltage: 3.3V-5V
Operating Current: <20mA
Output Format: Analog signal output
Control Interface: ADC (Analog-to-Digital Converter)
Pin Count: 3 Pins (2.54mm pitch header)
Hardware Connection
The grayscale sensor typically has three pins: VCC, GND, and OUT. VCC should be connected to the 5V output of the development board, GND to the GND pin of the development board, and the OUT pin to the A0 analog input port of the development board.
Usage Method
/******************************************************************************
* Test Hardware: LCSC ColorEasyDuino Development Board
* Version Number: V1.0
* Modified By: www.lckfb.com
* Modification Date: April 11, 2024
* Function Overview:
*****************************************************************************
* Open-source development board hardware and software information and related projects hardware and software information on official website
* Development board official website: www.lckfb.com
* Technical support resident forum, any technical problems are welcome at any time to exchange learning
* LCSC Forum: club.szlcsc.com
* Follow our Bilibili account: [立创开发板], stay toned to our latest news!
* We focus on cultivating Chinese engineers rather than profiting from board sales.
******************************************************************************/
// 定义灰度传感器连接的模拟输入引脚
int graySensorPin = A0;
void setup() {
// 初始化串行通讯,设置波特率为9600
Serial.begin(9600);
}
void loop() {
// 读取灰度传感器的模拟值
int sensorValue = analogRead(graySensorPin);
// 将读取的模拟值输出到串口监视器
Serial.print("灰度值: ");
Serial.println(sensorValue);
// 稍作延迟,方便观察
delay(500);
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Usage Testing
The grayscale sensor outputs an analog value, typically ranging from 0 to 1023 (with the development board's ADC being 10-bit). This value represents the variation in light intensity detected by the sensor, reflecting the grayscale level of the surface. In practical applications, you may need to conduct experiments and record the analog values of black and white surfaces under specific lighting conditions for comparison and judgment.