Skip to main content

voltage-monitor

Monitor voltage levels using ADC with configurable voltage divider ratio and alert thresholds.

Overview

The voltage-monitor node reads voltage levels through an ADC with configurable voltage divider support and alert thresholds. It translates raw ADC values into calibrated voltage readings, accounting for external resistor divider networks. Ideal for battery monitoring, solar panel voltage tracking, and power supply supervision.

16-bit
ADC Resolution
±0.1%
Accuracy
Divider
Built-in Scaling
I2C
Interface

Properties

Property Type Default Description
i2cBus select /dev/i2c-1 I2C bus device (/dev/i2c-0, /dev/i2c-1)
address string 0x48 I2C address of the ADC
channel number 0 ADC channel to read (0-3)
gain number 1 PGA gain setting (2/3, 1, 2, 4, 8, 16)
voltageDivider number 1 Voltage divider ratio R1/(R1+R2). Set to 1 for no divider.
threshold number 0 Alert threshold voltage. Set to 0 to disable alerts.

Output

{
  "voltage": 12.45,
  "rawAdc": 24315,
  "dividerRatio": 0.25,
  "thresholdExceeded": false,
  "channel": 0,
  "timestamp": 1640000000000
}

Note: When threshold is set to 0, the thresholdExceeded field is always false. The actual voltage is computed as rawAdc voltage / dividerRatio.

Wiring

Connection (with Voltage Divider)

VDD → 3.3V

GND → GND

SDA → GPIO 2 (Pin 3)

SCL → GPIO 3 (Pin 5)

AIN0 → Voltage divider output

Never exceed 3.3V on the ADC input. Use a voltage divider for higher voltages.

Voltage Divider Circuit

  V_in (e.g. 12V)
    |
   [R1]  30kΩ
    |
    +-------→ AIN0 (to ADC)
    |
   [R2]  10kΩ
    |
   GND

  Ratio = R2/(R1+R2) = 10k/40k = 0.25
  V_adc = 12V * 0.25 = 3.0V

Example: Battery Voltage Monitor

Monitor a 12V lead-acid battery and alert when voltage drops below safe level.

voltage-monitor function dashboard
// Function node: Battery health analysis
var voltage = msg.voltage;
var history = flow.get('batteryHistory') || [];

history.push({ v: voltage, t: Date.now() });

// Keep last hour of readings
var oneHourAgo = Date.now() - (60 * 60 * 1000);
history = history.filter(r => r.t > oneHourAgo);
flow.set('batteryHistory', history);

var status = "healthy";
if (voltage < 11.8) status = "critical";
else if (voltage < 12.2) status = "low";
else if (voltage > 14.4) status = "overcharge";

// Calculate discharge rate
var rate = 0;
if (history.length > 1) {
    var oldest = history[0];
    var hours = (Date.now() - oldest.t) / 3600000;
    rate = (oldest.v - voltage) / hours;
}

msg.payload = {
    voltage: voltage.toFixed(2),
    status: status,
    dischargeRate: rate.toFixed(3),
    hoursRemaining: rate > 0 ? ((voltage - 10.5) / rate).toFixed(1) : "N/A"
};

return msg;

Example: Solar Panel Voltage Logger

Track solar panel output voltage over time and log to database.

// Function node: Solar voltage classification
var voltage = msg.voltage;
var hour = new Date().getHours();

var panel = {
    voltage: voltage.toFixed(2),
    timestamp: msg.timestamp,
    hour: hour,
    generating: voltage > 1.0,
    peakHours: (hour >= 10 && hour <= 15)
};

// Efficiency estimate based on expected peak
var expectedPeak = 18.5; // Voc of panel
panel.efficiency = ((voltage / expectedPeak) * 100).toFixed(1);

if (msg.thresholdExceeded) {
    panel.alert = "Voltage threshold exceeded";
}

msg.payload = panel;
return msg;

Common Use Cases

Battery Monitoring

Track battery charge state and predict remaining runtime with discharge rate analysis.

Solar Panel Tracking

Monitor open-circuit and load voltage from solar panels to optimize charge controllers.

Power Supply Supervision

Detect supply rail brownouts and trigger alerts before system instability occurs.

Automotive Diagnostics

Read alternator and battery voltages in vehicles for predictive maintenance systems.

Related Nodes