Overview
The current-monitor node measures electrical current by reading the voltage
drop across a shunt resistor via an ADC. It supports configurable sample averaging for stable readings and
computes current in milliamps and power in milliwatts. Essential for energy monitoring, load profiling, and
overcurrent detection in IoT deployments.
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) |
| shuntResistor | number (required) | 0.1 | Shunt resistor value in ohms |
| maxCurrent | number | 10 | Maximum expected current in amps |
| averaging | number | 4 | Number of samples to average per reading |
Output
{
"current_mA": 523.4,
"voltage_mV": 52.34,
"power_mW": 6280.8,
"shuntResistor": 0.1,
"samples": 4,
"timestamp": 1640000000000
} Note: Current is derived using Ohm's law: I = V_shunt / R_shunt.
Power is calculated as P = V_supply * I. The samples field indicates how many
ADC readings were averaged.
Wiring
Connection (High-Side Shunt)
VDD → 3.3V
GND → GND
SDA → GPIO 2 (Pin 3)
SCL → GPIO 3 (Pin 5)
AIN0 → Shunt resistor high side
AIN1 → Shunt resistor low side
Use differential mode (AIN0-AIN1) for best accuracy. Ensure shunt voltage stays within ADC range.
Shunt Resistor Circuit
V_supply (+)
|
+---→ AIN0 (high side)
|
[R_shunt] 0.1Ω
|
+---→ AIN1 (low side)
|
[LOAD]
|
GND
V_shunt = I_load * R_shunt
Example: 1A * 0.1Ω = 100mV Example: Energy Consumption Tracker
Accumulate energy usage over time and compute cost estimates.
// Function node: Energy accumulator
var current_mA = msg.current_mA;
var power_mW = msg.power_mW;
var now = Date.now();
var state = flow.get('energyState') || {
totalEnergy_Wh: 0,
lastTimestamp: now,
peakCurrent_mA: 0
};
// Calculate energy consumed since last reading
var elapsed_h = (now - state.lastTimestamp) / 3600000;
var energy_Wh = (power_mW / 1000) * elapsed_h;
state.totalEnergy_Wh += energy_Wh;
// Track peak current
if (current_mA > state.peakCurrent_mA) {
state.peakCurrent_mA = current_mA;
}
state.lastTimestamp = now;
flow.set('energyState', state);
// Cost estimate (configurable rate)
var rate_per_kWh = 0.12;
var cost = (state.totalEnergy_Wh / 1000) * rate_per_kWh;
msg.payload = {
current_mA: current_mA.toFixed(1),
power_mW: power_mW.toFixed(1),
totalEnergy_Wh: state.totalEnergy_Wh.toFixed(3),
peakCurrent_mA: state.peakCurrent_mA.toFixed(1),
estimatedCost: cost.toFixed(4)
};
return msg; Example: Overcurrent Protection Alert
Detect overcurrent conditions and send immediate alerts.
// Function node: Overcurrent detector
var current_mA = msg.current_mA;
var maxCurrent_mA = 5000; // 5A threshold
var alerts = flow.get('currentAlerts') || [];
if (current_mA > maxCurrent_mA) {
var alert = {
type: "overcurrent",
current_mA: current_mA,
threshold_mA: maxCurrent_mA,
timestamp: msg.timestamp,
message: "Current exceeded " + maxCurrent_mA + "mA: " + current_mA.toFixed(0) + "mA"
};
alerts.push(alert);
flow.set('currentAlerts', alerts);
msg.payload = alert;
msg.topic = "alerts/overcurrent";
return msg;
}
return null; // No alert needed Common Use Cases
Energy Metering
Track real-time power consumption and accumulate energy usage for billing or monitoring.
Overcurrent Detection
Alert when load current exceeds safe limits to prevent damage or fire hazards.
Load Profiling
Analyze current draw patterns over time to identify equipment behavior and anomalies.
Solar Charge Monitoring
Measure charge and discharge currents in battery-backed solar energy systems.