Board simulator: Example 6.1
The RenewableSwitchOver board running Example 6.1. The simulator runs the sketch's own logic, with the same whole-number sums, against a model of the RES, the battery, the MOSFET switches, the L298N and the pump. Change the RES and watch what the Arduino reads, how it switches the supply, and how the ramp keeps the pump current down.
Renewable source
A solar panel or small turbine sags when it supplies current: this is how much.
Changes the sketch so startRamp() jumps straight to full drive: a direct start through the L298N.
Example 6.1: the sketch, as it runs
running now · ran in the last 2 s, fading · setup() or changeSupply(): a decision that just happened. loop() runs once every millisecond; it reads the RES on one pass in 100. Press a Step button to pause and step through one pass at a time (▶ Run carries on), or use slow motion.
Graphs
Graphs ▾
Analogue input: A0 reading
RES voltage at J3
Pump drive: PWM duty and pump voltage
level as a duty cycle (%)average pump voltage (V)Pump current through the L298N
Scope: the PWM now (3 periods, about 6 ms)
No graphs selected: choose some from the Graphs menu.
The board
| Pin | Net | Now |
|---|---|---|
| A0 | AnalogIn | |
| D13 | renewableOn | |
| D12 | batteryOn | |
| D3 | InC (IN3) | |
| D2 | InD (IN4) | |
| D4 | Enable |
Variables
onBatterylevelrampFromrampStartMsreadingkToBattery / kToResWhat happened
The sketch prints nothing: this log is the simulator's commentary on what each decision did.
The model
Battery 12 V; diodes D1/D2 drop 0.8 V; the L298N drops 1.8 V; pump winding 2 Ω, 0.8 A running at full speed, load rising with the square of its speed. The divider is set so A0 sees 0.300 of the RES voltage, as kRatioPermil = 300 assumes. Readings jitter by ±1 count.