Arduino UNO based controller using BME280 environmental sensor to output a relay signal for warm and dry ambient state.
- Initialization
- [X] Read configuration parameters from EEPROM
- [X] Print configuration parameters to serial
- [X] LCD output rainmaker + version number
- Hardware
- [X] Temperature and humidity sensor AM2320
- [X] 2x16 LCD display shield
- [X] select button
NEXT
- [X] left button
SELECT
- [X] select button
- Normal operation
- [X] Read and show temperature and humidity
- [X] Rain operation active
- [X] Blank display after idle timeout
- Configuration operation
- [X] Rain operation inactive
- Configuration values
- [X] Configure temperature threshold (TH)
- [X] Configure humidity threshold (RH)
- [X] Configure blank LCK idel timeout (IDLE)
- [X] Configure rain delay (DEL)
- [X] Configure rain duration (DUR)
- [X] Change rain delay timer for debug purposes (TMR)
- Configuration functions
- [X] Menu choice to show configuration value
- [X] Menu choice to choose configuration value
- [X] Menu choice to change configuration value
- [X] Menu choice to persist changes in EEPROM
- Rain operation
- [X] Rain if temp exceed limit and RH less than limit
- [X] Time interval between rainy periods (DLY)
- [X] Rain lasts for a duration (DUR)
- [X] Output signal (RAIN) when should rain
- Keyboard
- [X] Debounce timeout
- [X] Two key operation (select and set)
At a high level, rainmaker
is a state machine Main
with two states
MainStarting
and MainOperating
.
MainStarting
transitions to MainOperating
after reading parameters
from EEPROM, and configuring controller pins and peripherals.
MainOperating
runs three state machines in parallel:
SelectButton
to check pressing ofselect
button,SetButton
to check pressing ofset
button, andDisplay
to read inputs from sensor and buttons, and to control output to LCD and to output pins.
State machine Display
implements modes ConfiguringMode
and
OperatingMode
.
OperatingMode
-mode includes states DisplayMain
and DisplayIdle
.
Both of these states read environment sensor and execute state machine
Rain
. DisplayMain
reads and updates ambient state to LCD display
using state machine UpdateMeasurement
. The corresponding state
machine, IdleMeasurement
, in DisplayMain
reads ambient state and
blanks LCD. DisplayMain
runs state machine IdleChecker
to trigger
timeout
transition from DisplayMain
to DisplayIdle
. Pressing
either select
or set
-button, when in DisplayIdle
, resumes
control back to DisplayMain
state.
States of state machine Rain
use ambient state and two timers:
- state
NoRain
: Entered, when ambient temperature is below parameterTH
limit OR relative humidity greater than parameterRH
limit. - state
WaitToRain
: Entered, when temperature above parameterTH
limit and relative humidity less than parameterRH
limit and RAIN_DELAY timer has not elapsed. Output signalRAIN
isoff
. - state
Raining
: Entered, when temperature above parameterTH
limit and relative humidity less than parameterRH
limit andRAIN_DELAY
timer has elapsed andRAIN_DURATION
has not elapsed. Output signalRAIN
ison
.
Configuration
-mode is invoked by pressing select
button in
DisplayMain
-state. In Configuring
state button select
chooses
next parameter to configure. set
button transitions to state
ConcigureSet
, which allows choosing parameter value with select
button and resuming back to Configuring
state with set
button. After all configuration parameters have been processed,
pressing select
transitions to ConfigurePersist
, where set
button persists parameter values to EEPROM and resumes back to
DisplayMain
. Button select
resumes back to DisplayMain
without
making changes permanent.
ConfigSlot slots[CONFIG_SLOTS] = { { "TH" // warm temperature threshold ,&temp_too_treshold ,5 // increment by 5 degrees ,50 // max 50 deg ,20 // min 20 deg ,1 // save to eeprom 0 address }, { "RH" // dry/humid threshold ,&relative_humidity_treshold ,5 // increment ,100 // max ,30 // min ,2 // save to EEPROM address slot }, { "IDLE" // Timeout before blanking LCD ,&idle_timeout // idle timeout (seconds) ,30 // increment ,600 // max 10 min ,30 // min ,3 // save to EEPROM address slot }, { "DLY" // Rain delay, number of ticks between showers ,&rain_delay // delay * 15 mins between rain showever ,1 // increment by slot count ,RAIN_DELAY_MAX // max 8*15 mins = 2 hours ,1 // min 1 slot = 15 mins ,4 // save to EEPROM address slot }, { "DUR" // Rain duration = length of shower ,&rain_duration // delay * 15 mins between rain showever ,10 // increment 10 sec slots ,120 // max 120 secs = 2 minutes ,10 // min 10 secs ,5 // save to EEPROM address slot }, { "TMR" // Current counter value, allow change but NOT persist ,&rainTimer // delay * 15 mins between rain showever ,RAIN_DELAY_TICK // increment counter by tick size ,RAIN_DELAY_TICK * RAIN_DELAY_MAX // max to rain delay = number of ticks between showers ,0 // min = start counter from 0 ,0 // NOT saved to EEPROM } };
// Hardware settings: // Lcd-shield pins const int lcd_pin1=8; const int lcd_pin2=9; const int lcd_pin3=4; const int lcd_pin4=5; const int lcd_pin5=6; const int lcd_pin6=7; // Analog inputs const int lcd_button_port=0; const int lcd_backligh_port=10; // Hardware settings.