Introduction: Raspberry Pi Pico Water-level-indicator Using Potentiometer
Hello, I am a school student from Germany and this is my first Instructable. I‘m excited to show you how to make a water-level-indicator using Raspberry pi Pico and a Potentiometer. My parents gifted me the Raspberry pi Pico for Christmas and immediately I started trying out what it can do. It is a simple Project and maybe someone has done it before, but I made it all by myself, so let‘s get started...
Supplies
- Raspberry pi Pico and Micro USB Cable
- PiperMake (https://make.playpiper.com/)
- Breadboard
- Jumper-cables
- 3 LEDs, Red, Yellow and Green
- Buzzer
- 10k Ohms Potentiometer
- Stick
- Something that floats
Step 1: Connecting Potentiometer
Start building the Circuit.
First connect the potentiometer to the pico as shown in the image above: Connect the middle pin of the potentiometer to the pin 31/ GP26 / ADC0. Then connect one of the remaining pins of the potentiometer to any of the grounds (GND). The third pin of the potentiometer has to be connected to pin 36 / 3v3 OUT.
Step 2: Adding LEDs
Now connect the three LEDs to the pico.
The positive pin of the Green LED has to be connected to pin 17/ GP13. The positive pin of the Yellow LED has to be connected to pin 19/ GP14. The positive pin of the Red LED has to be connected to pin 20/ GP15. Connect the negative pins of all LEDs to any of the grounds (GND) of the pico.
Step 3: Adding Buzzer
Connect the positive pin of the buzzer to pin 20/GP15 (same as red LED ) and the negative pin of the buzzer to any of the grounds of the pico.
Step 4: Complete Circuit
When all components are in place, the circuit should look as in the picture above:
Step 5: Circuit on the Breadboard
On my breadboard, the circuit looks as in the picture above:
Step 6: Attaching Lever Arm
Attach the lever arm to the potentiometer with hot glue.
Step 7: Attaching Float
Attach a float to the other end of the stick.The float can be a block of styrofoam or a plastic ball. I have used a plastic ball as in the image above.
Step 8: Attaching Everything to a Bucket
Attach the potentiometer to a bucket, which at least should be as deep as the stick and the float together.
Step 9: Start Programming
The Water-level-indicator works by reading the values of the potentiometer and turning the LEDs on when a certain value is reached. Everything is programmed in PiperMake. Let‘s start with an simple ``repeat forever`` loop:
Step 10: Reading Values
Read the values from the potentiometer by using the `` print (read from pin ADC0)`` block.
Step 11: If/Else If Loops
Add 4 ``If/ Else if `` loops into the ``repeat forever`` loop below print.
Step 12: Adding Pins
Add the pins to the if and else if loops, as you connected them in the circuit
GP13 = Green LED
GP14 = Yellow LED
GP15 = Red LED
Step 13: Adding Values
The values depend on your construction.To get the values for your setup, we used the ``print`` block. The values will be shown in the console at the bottom of pipermake page.
Try out which values will be perfect at which water-level . Add the correct values in the program. The values may change after final calibration
Step 14: Circuit Python Code
The Circuit Python code:
## ---- Imports ---- ##
import time
import board
from piper_blockly import *
## ---- Definitions ---- ##
GP26 = piperPin(board.GP26, "GP26", "Analog")
try:
set_digital_view(True)
except:
pass
GP13 = piperPin(board.GP13, "GP13")
GP14 = piperPin(board.GP14, "GP14")
GP15 = piperPin(board.GP15, "GP15")
## ---- Code ---- ##
while True:
print(GP26.readVoltage())
if GP26.readVoltage() >= 0:
GP13.setPin(1)
elif GP26.readVoltage() < 0.35: ## ---- Values can change ---- ##
GP13.setPin(0)
if GP26.readVoltage() >= 0.35:
GP14.setPin(1)
elif GP26.readVoltage() < 0.35:
GP14.setPin(0)
if GP26.readVoltage() >= 0.7:
GP15.setPin(1)
elif GP26.readVoltage() < 0.7:
GP15.setPin(0)
time.sleep(0.5)
Step 15: Everything Working Together
How this project works. Link for above video
Step 16: End Note
I will submit this project for Raspberry Pi contest. Please like and vote for my entry.
This is only a basic version, so you can extend it with more LEDs for more waterlevels
I also make YouTube videos on programming in Scratch and Raspberry pi. Please subscribe to my Youtube channel PRO :)