We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.
The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ...
For more information on how Google's third-party cookies operate and handle your data, see: Google Privacy Policy
Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.
Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
About the Author
Les is a maker and trainer who has worked with the Raspberry Pi Foundation and the BBC to deliver computing training.
We all love a cup of tea/coffee/juice/water. But what if we need to alert people to an oncoming flood? How can we detect when water reaches a certain level? Well, we can and all we need are a micro:bit, two crocodile clips and some aluminium foil. This simple project uses the conductivity of water to close a circuit when water touches the two foil sensors. For this, we read analog values, ranging from 0 to 1023 which relate to 0V to 3V. Anything over 1000 will trigger our project to life.
For this project, we shall be using the Javascript Blocks Editor https://microbit.org/code/ and we should already be comfortable copying code to our micro:bit.
When our micro:bit starts up, we need to see that it is ready to go and we use the “Show Icon” block from Basic. In this case, we chose to use a tick to indicate readiness.
We need to slow down the code, using “pause” from the Basic menu we set the delay to 1000ms, which is 1 second. This enables us to see the tick before the main code runs.
Inside our forever loop we need to place an “if true then..else” block found in Logic. This block handles decisions. Such as if the water is touching the foil.
From Logic, we need to grab the “0 < 0” comparison block and place that over the True of the if block. Then change the < to a >.
From the Pin section, found in Advanced. Drag “analog read pin P0” and place it in the first zero. In the second change the value to 1000 which is the trigger for our sensor.
So if the sensor is triggered, we need to alert the user, and using the “repeat 4 times” block from Loops we can start an animation loop.
These blocks from Basic are “Show Icon”, which we use to display a large square. Then we delay for 100 ms using “pause.”
Again from Basic, we use “Show Icon” but this time we have a small square, and another “pause” when the loop runs it will look animated!
Inside the else part of our condition, we add another “Show Icon” with a chessboard design. This is the default that shows when the water level is low.
That’s it, now download the code to your micro:bit and when it has finished, drop the foil sensors into a cup or bowl and slowly fill it up with water. When the water touches the sensors, the LED matrix on the micro:bit will change and alert you to high water.
Well done you have made your own flood sensor! Can you change the code to make a buzzer sound for a blind person? Or perhaps send a radio message to a remote micro:bit?