This example shows you how to read an analog input on analog pin 0, convert the values from analogRead() into voltage, and print it out to the serial monitor of the Arduino Software (IDE). 本例展示了怎样从模拟输入针脚 0 读取,转换从 analogRead 读取值为电压,并打印结果到 Arduino 软件(IDE)...
读取模拟电压(Read Analog Voltage)本示例展示了如何读取模拟输入0脚的模拟信号,将来自analogRead()的值...
int sensorValue = analogRead(A0); 为了使从0-1023的值对应到读取到的电压值,你需要创建另外一个浮数的变量,然后做一些运算: float voltage= sensorValue * (5.0 / 1023.0); 最后,你需要打印这个电压值到你的串口窗口里。你可以用Serial.println()命令来完成这个步骤: Serial.println(voltage) 现在,当你打开...
在模拟输入引脚没有任何连接的情况下,用analogRead()指令读取该引脚,这时获得的返回值为不固定的数值(用于生成随机数)。 代码(在示例里): /* ReadAnalogVoltage Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor. Graphical representation is available us...
over and over again forever:voidloop() {//read the input on analog pin 0:intsensorValue =analogRead(A0);//Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):floatvoltage = sensorValue * (5.0/1023.0);//print out the value you read:Serial.println(voltage)...
int sensorValue = analogRead(A0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float voltage = sensorValue * (5.0 / 1023.0); // print out the value you read: Serial.println(voltage); } 代码说明 在下面给出的程序或草图中,你在设置功能中做的第...
AnalogReadSerial- 读取电位器, 并把它的状态输出到 Arduino 串口窗口 BareMinimum- 编写一个 Arduino 代码的必要代码块 DigitalReadSerial- 读取一个按键, 并把它的状态输出到 Arduino 串口窗口 Fade- 示范使用模拟输出使 LED 变暗. ReadAnalogVoltage- 读取模拟输入,并把电压输出到 Arduino 串口窗口 ...
int analogvalue = analogRead(A0); temp = (analogvalue * 5.0) / 1024.0; // FORMULA USED TO CONVERT THE VOLTAGE input_volt = temp / (r2/(r1+r2)); 在这里,我们在Arduino的LCD和串行监视器上显示了测量的电压值。因此,在代码中,Serial.println用于在串行监视器上打印值,lcd.print用于在16x2 LCD上...
Arduino example. Demonstration of how to use analog pins to read the input from a sensor:```cpp// 定义一个变量来存储读取的值int sensorValue = 0;void setup() { // 初始化串口,设置波特率为9600 Serial.begin(9600);}void loop() { // 读取模拟引脚A0的值 sensorValue = analogRead(A0...
//initialize serial communication at 9600 bits per second: Serial.begin(9600); // the loop routine runs over and over again forever: void loop() { //read the input on analog pin 0: floatsensorValue = analogRead(A0); //convert ADC value to voltage ...