Limit and Float Switch¶

Written by Grace Lo & Rachel Yan

The limit and float switches are used as external feedback sources to indicate when to stop opening and closing the chamber. At the top, the support pushes the lever of the limit switch to stop the motor and prevent collision with the mounted motor and PCB (left). At the bottom, the float switch triggers when water causes the float to shift upward to confirm the edges of the chamber have sealed against the water (right).

Concept Drawing

Pin Connections¶

Pin Connections

Pin connections from the each switch → Pico are as follows:

  • limit switch → GPIO 20 (pin 26)
  • float switch → GPIO 21 (pin 27)
  • GND → GND

Code¶

All code is in the CornellFluxChamber Github repository. The code for using the switches is incorporated into flux_chamber.c.

Includes¶

The first lines of code in the C source file include header files. Don't forget to link these in the CMakeLists.txt file!

The following files are required to enable the GPIO pins for the switches.

#include <stdio.h>
#include "pico/stdlib.h"

Initializations¶

The C source file initializes the GPIO's as inputs.

gpio_init(20);              // limit switch
gpio_set_dir(20, GPIO_IN);
gpio_pull_up(20);
gpio_init(21);              // float switch
gpio_set_dir(21, GPIO_IN);
gpio_pull_up(21);

Triggering the Switch¶

The switches are basic open and close circuits, with gpio_get used to get the state of each switch. The limit switch is triggered when its state is low and the float switch is triggered when its state is high.