Last active
May 4, 2022 05:52
-
-
Save hlog2e/9b54de19b340d43ca724e9662bb17f1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float Vout = 0.0; // 아두이노에 들어오는 전압 | |
float Vin = 0.0; // 실제 전압 | |
float R1 = 30000.0; // 1번 저항의 값 선언 | |
float R2 = 7500.0; // 2번 저항의 값 선언 | |
int sensorValue = 0; // 전압 측정 센서 변수 선언 | |
void setup() { | |
Serial.begin(9600); // 컴퓨터랑 통신하기 위한 시리얼 모니터 사용 설정 | |
pinMode(A0, INPUT); | |
} | |
void loop() { | |
sensorValue = analogRead(A0); // 아날로그 핀에 들어오는 센서 값을 변수에 넣어줌. | |
Vout = (sensorValue * 5.0) / 1024.0; // 전압측정 센서->아두이노로 오는 전압 계산 공식 | |
Vin = Vout / ( R2 / ( R1 + R2) ); // 전압측정 센서에 연결된 전압의 값 | |
Serial.print("Voltage: "); | |
Serial.println(Vin); // 전압측정 센서에 연결된 전압을 컴퓨터로 출력해줌 | |
delay(300); // 0.3초(300밀리초) 딜레이 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment