9
Voltage Sensor
-
Voltage Sensor
No. 9 • Analog

Voltage Sensor

อ่านค่าแรงดันไฟฟ้าผ่านวงจรแบ่งแรงดัน

Component NameVoltage Sensor
Part No. / Model-
Interface TypeAnalog
PinsVCC, GND, S / Vin+, Vin-

Note: ตรวจช่วงแรงดันของโมดูลก่อนใช้งานจริง ห้ามเกินพิกัด

Wiring Example

ตัวอย่างการต่อวงจรกับ Arduino UNO

Circuit diagram
Sensor PinArduino Pin
VCC5V
GNDGND
SA0
Vin+แหล่งจ่าย +
Vin-แหล่งจ่าย -

Arduino IDE Code

Download .ino file

voltage-sensor.ino
// Voltage Sensor
// Board: Arduino UNO
// Typical module ratio is often 5:1. Verify your actual module before use.

const int VOLTAGE_PIN = A0;
const float ADC_REF = 5.0;
const float DIVIDER_RATIO = 5.0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int raw = analogRead(VOLTAGE_PIN);
  float vout = raw * (ADC_REF / 1023.0);
  float vin = vout * DIVIDER_RATIO;

  Serial.print("Raw: ");
  Serial.print(raw);
  Serial.print(" | Voltage: ");
  Serial.print(vin, 2);
  Serial.println(" V");

  delay(500);
}