arduino 读取输入电压 & arduino模拟器

  • 内容
  • 评论
  • 相关

arduino 模拟器

https://circuits.io

 

 

读取模拟信号代码


// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = A0;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
Serial.begin(9600);//打开串口并设置波特率为9600
pinMode(led, OUTPUT);
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)

}

// the loop routine runs over and over again forever:
void loop() {

int sensorValue = analogRead(led);
// 将模拟信号转化为0-5V的电压
float voltage = sensorValue * (5.0 / 1023.0);
//打印数字信号
Serial.println(sensorValue);

//打印电压

Serial.println(voltage);

delay(2000);
}

 

丑陋的电路图

QQ20160813-0

 

 

 

评论

1条评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注