/*Analog InputDemonstrates analog input by reading an analog sensor on analog pin 0 andturning on and off a light emittingdiode(LED) connected to digital pin 13.The amount of time the LED will be on and off depends on the value obtainedby analogRead().The circuit:- potentiometercenter pin ...
Adafruit Arduino - Lesson 8. Analog Inputs */ int potPin = 0; void setup() { Serial.begin(9600); } void loop() { int reading = analogRead(potPin); Serial.println(reading); delay(500); } 现在打开串口监视器,您将看到出现打印的数字值。 转动可变电阻器上的旋钮,你会看到数字在0到1023之间...
void loop() { // read the input on analog pin 0: 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); } 火...
void loop() { // read the input on analog pin 0: 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); } [...
Demonstrates analog input by reading an analog sensor on analog pin 0 and turning on and off a light emitting diode(LED) connected to digital pin 13. The amount of time the LED will be on and off depends on the value obtained by analogRead(). ...
delay(2000);//wait 2s for next reading} 串行监视器上的输出如下所示: 我的测试环境是 100多一点时 表示有烟雾 ,正常是700多。(检测的是 A0 的输出) 我是用 打火机 打着火后 再吹灭。 放出的甲烷 气体 。直接 放到 检测器 边上。检测出 100多一点的 输出 ...
读取一个模拟引脚的值,把这个值设置为延时的时间长短。 if_noLED.png PhotoCellA0.png /* Analog Input Demonstrates analog input by reading an analog sensor on analog pin 0 and turning on and off a light emitting diode(LED) connected to digital pin 13. ...
// wait 2 milliseconds before the next loop for the analog-to-digital // converter to settle after the last reading: delay(2); } 模拟输入 在这个例子里我们用一个变化电阻(一个电位计或者光敏电阻),我们通过Arduino或者Genuino开发板的一个模拟输入引脚读取它的值,并且根据这个值改变内置LED灯闪烁的速...
voltage is 5V, and the analog input readings are returned as 10-bit integer values. The maximum numerical value for a (unsigned) 10-bit number is 1023. Therefore, when the maximum input of 5 V is applied to one of the input pins, the maximum numerical value for an analog reading is ...
sensorValue = analogRead(MQ2pin); // read analog input pin 0 Serial.print("Sensor Value: "); Serial.print(sensorValue); if(sensorValue < 300) //阈值 根据实际情况判断 大于300 还是小于300 ,300也是变量 { Serial.print(" | Smoke detected! 探测到烟雾 "); ...