搜索代码

Lesson 10-1: Reading Potentiometer Voltage with an Arduino

Lesson 10-1: Reading Potentiometer Voltage with an Arduino

We first learn the difference between analog and digital. Then we learn what a potentiometer is and how to measure DC voltage with Arduino, and how to find the value of a resistor.

543-Lesson 10: Using a Potentiometer to Read Voltage, Analog, and Digital
语言: C++
++
/*
 * S01-10 Potentiometer
  Please watch video instruction here https://youtu.be/wuNrzQ8rpYw
 This code is available at http://robojax.com/course1/?vid=lecture10

with over 100 lectures free on YouTube. Watch it here http://robojax.com/L/?id=338
Get the code for the course: http://robojax.com/L/?id=339 
 * Written by Ahmad Shamshiri for Robojax, robojax.com http://youtube.com/robojaxTV
 * Feb 23, 2019
 * 
 */
const int potPin = A0;// pin name for reading voltage

void setup() {
  Serial.begin(9600);// initialize the serial monitor
  Serial.println("Reading Analog value");

}

void loop() {
//Robojax Step-by-Step Arduino Course http://robojax.com/L/?id=338
	
  int potValue = analogRead(potPin);// read the input value 
  Serial.print("potValue:");
  Serial.print(potValue);
  Serial.print(" Voltage:");
  float voltage = potValue * (5.0 / 1023.0);
  Serial.print(voltage);
  Serial.println("V");
  if(voltage >= 2.8 && voltage <= 4.1) 
  {
    Serial.println("Voltage between 2.8 and 4.1");
  }
  delay(200);

}

资源与参考

尚无可用资源。

文件📁

没有可用的文件。