Lesson 10-2: Finding the Voltage of an Unknown Resistor Using 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. Using this code, you can find an unknown R value.
544-Lesson 10: Using a potentiometer to read voltage, analog, and digital.
Язык: C++
++
/*
* S01-10 Potentiometer R value
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 https://www.youtube.com/robojaxTV
* Feb 23, 2019
*
*/
const int potPin = A0;// pin name for reading voltage
float RT = 10000;// the potentiometer value 10k
float R;// the unknown R value
void setup() {
Serial.begin(9600);// initialize the serial monitor
Serial.println("Reading Analog value");
}
void loop() {
int potValue = analogRead(potPin);// read the input value
float voltage = potValue * (5.0 / 1023.0);// calculate voltage
R = ( voltage * RT)/5.0;// calculate R
Serial.print("R :");
Serial.print(R);
Serial.print(" Ohms V:");
Serial.print(voltage);
Serial.println("V");
delay(200);
}
Ресурсы и ссылки
Ресурсов пока нет.
Файлы📁
Нет доступных файлов.