1. Hardware Connection
Water level sensor from Anndason, model# DP5200 is used to detect the water level in the sump pit. Basically it's a float switch. When water is rising, it pushes the float towards switch's open or close position depending on you mount the sensor upwards or downwards. I use 3 water level sensors and they are connected to Arduino interface's D11, D12 and D13 pins as shown in the schematic below. The three pins are configured as general digital inputs with internal pull-up. Interrupts are enabled on these three pins as well.
Shown below is the physical connection of the sensors and the development kit.
2. Software Project
ModusToolbox provides lots of template applications to exercise each part of the hardware's capability. We can easily start from a template application and modify it to become our own application. In this case, I will use GPIO Interrupt template application as my start point.
First, declare two more interrupt handler routines so each sensor input has its own interrupt handling. Also define two more global flags which indicates the interrupt has been triggered or not.
Then initialize three pins as general digit inputs with pull-up. The three Arduino data pins D11, D12 and D13 are defined as CYBSP_D11, CYBSP_D12 and CYBSP_D13 respectively in the BSP software. Next, we configure the interrupt handler, trigger signal and enable interrupt for each pin.
After initialization, it's a infinite loop like most bare-metal application. In the loop, we check which interrupt woke up the system and print out corresponding message to indicate the water level.
The last part is the interrupt handlers. Usually we should keep interrupt routine as short as possible. In this example, the routines only set the global flags then exit from interrupt.
The following is the console output after triggering three sensor sequentially.