Creative Code

07_Analog_Read 본문

Arduino(C,C++)

07_Analog_Read

빛하루 2023. 8. 11. 15:01
#define V0 5.0
#define unit V0/1024
#define R1 10000.0
const int analogPin = A0; 



void setup() {
  // put your setup code here, to run once: 
  Serial.begin(115200);

}

void loop() {
  // put your main code here, to run repeatedly:
  int analogValue = analogRead(analogPin);  // analogpin에 연결했을때
  float V2 = analogValue * unit;
  float R2 = V2 * R1 / (V0 - V2);
  Serial.print(analogValue);
  Serial.print(", ");
  Serial.print(analogValue * unit);
  Serial.print("V,");
  Serial.println(R2);
  delay(300);
  
}