int sensorValue = analogRead(A0);:读取模拟引脚A0的值。analogRead()函数返回一个0到1023之间的整数,表示输入电压的相对值。 例如,当A0引脚的电压为0V时,返回0;当电压为5V时,返回1023。 float voltage = sensorValue * (5.0 / 1023.0);:将读取到的模拟值转换为实际的
在模拟输入引脚没有任何连接的情况下,用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...
int sensorValue = analogRead(A0); To change the values from 0-1023 to a range that corresponds to the voltage the pin is reading, you'll need to create another variable, afloat, and do a little math. To scale the numbers between 0.0 and 5.0, divide 5.0 by 1023.0 and multiply that by...
}//the loop routine runs 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 r...
int sensorValue = analogRead(A0); 为了使从0-1023的值对应到读取到的电压值,你需要创建另外一个浮数的变量,然后做一些运算: float voltage= sensorValue * (5.0 / 1023.0); 最后,你需要打印这个电压值到你的串口窗口里。你可以用Serial.println()命令来完成这个步骤: ...
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上...
int voltage_value1 = analogRead(A1); 声明一个临时浮点变量用于保持浮temp_val等电压值。将该值乘以 0.00488 得到实际电压差,然后除以电阻值以求出电流。0.00488v是Arduino的ADC可以检测到的最小电压。 intsubraction_value =(voltage_value0 - voltage_value1) ; ...
In this example, we use the value of the sensor connected to the A0 pin with the `Analogread ()` function. `ANALOGREAD ()` function returns an integer value between 0 and 1023, indicating the voltage on the simulation pin. Then, we use the `map ()` function to convert this value ...
// 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: float sensorValue = analogRead(A0); // convert ADC value to voltage ...
AnalogReadSerial- 读取电位器, 并把它的状态输出到 Arduino 串口窗口 BareMinimum- 编写一个 Arduino 代码的必要代码块 DigitalReadSerial- 读取一个按键, 并把它的状态输出到 Arduino 串口窗口 Fade- 示范使用模拟输出使 LED 变暗. ReadAnalogVoltage- 读取模拟输入,并把电压输出到 Arduino 串口窗口 ...