← Back to notes

Renewable source with battery backup

The finished project: a voltage divider scales the renewable energy source (RES) voltage into A0; the Arduino compares it with a threshold and uses two relays to feed the load from the RES or, when the RES voltage drops, from the battery.

Renewable source

Monitoring divider → A0

What the Arduino sees

RESrelay on pin 12
Batteryrelay on pin 13
RES voltage
A0 voltage (RES_volt)
pin 12 (RES_relay) / pin 13 (BAT_relay)

Sketch for these settings


  

The relay module is active-LOW: writing LOW energises a relay and connects that source. The slide version compares at 2.5 V; adjust the threshold above to see the generated code change.