Sven Haiges
Published © CC BY

Calliope Mini Water Level Sensor

Use a Calliope Mini and a cheap water level sensor to sense water levels and potentially react on reaching a water limit.

BeginnerFull instructions provided1 hour5,455
Calliope Mini Water Level Sensor

Things used in this project

Hardware components

Calliope mini
Calliope mini
×1
Water Level Sensor
×1

Story

Read more

Code

Calliope Mini Water Level Sensor

JavaScript
let limit = 0
let max = 0
let level = 0
input.onButtonPressed(Button.A, () => {
    max = pins.analogReadPin(AnalogPin.C17)
    limit = max / 2
    basic.showNumber(max)
})
input.onButtonPressed(Button.B, () => {
    limit = pins.analogReadPin(AnalogPin.C17)
    basic.showNumber(limit)
})
basic.forever(() => {
    level = pins.analogReadPin(AnalogPin.C17)
    led.plotBarGraph(
        level,
        max
    )
    if (level > limit) {
        basic.setLedColor(Colors.Red)
    } else {
        basic.setLedColor(Colors.Green)
    }
})
max = 430
limit = max / 2
level = 0

Credits

Sven Haiges

Sven Haiges

4 projects • 17 followers

Comments