How To Use A Turbidity Sensor

About the project

If you've ever needed a sensor to examine the cleanliness of water a turbidity sensor is what you need

Project info

Items used in this project

Hardware components

Raspberry Pi 3 Model B Raspberry Pi 3 Model B x 1
Raspberry Pi Pico Raspberry Pi Pico x 1
Arduino UNO Arduino UNO x 1
Turbidity Sensor, Phototransistor Output Turbidity Sensor, Phototransistor Output x 1

Software apps and online services

Thonny Thonny


Turbidity Sensor:

A turbidity sensor is a device that measures the amount of suspended particles in a liquid. These particles can include sediment, algae, bacteria, and other organic or inorganic matter. The sensor works by shining a light through the liquid and measuring the amount of light that is scattered or absorbed by the particles. The more particles that are present, the higher the turbidity, or "cloudiness, " of the liquid will be. Turbidity sensors are often used in water treatment plants to monitor the clarity of water and ensure that it meets regulatory standards. They can also be used in other industries, such as brewing and food processing, to measure the clarity of liquids.

the turbidity sensor used in these examples:Gravity: Analog Turbidity Sensor

The Turbidity Sensor can be used in either digital or analog mode, depending on your preference. You can switch between the two modes using the switch on the PCB (printed circuit board). If you choose to use the digital output, you can set a threshold for the clarity using the variable resistor on the PCB. This allows you to specify the level of turbidity that you want to measure and trigger an action, such as sending a signal to a microcontroller or activating an alert. By using the digital output, you can easily monitor the clarity of a liquid and take action based on the sensor readings.

Raspberry PI Pico:

Code for the pico

simply connect the turbidity sensor to one of the picos analogue input pins, upload the code when you're ready to go.

Raspberry PI:

Code for the Raspberry PI

The Raspberry Pi does not have built-in analog input pins, which means it can only interpret digital signals. However, if you want to use the Turbidity Sensor's analog output with a Raspberry Pi, you can add an analog-to-digital converter (ADC) such as the MCP3008 chip. This will allow you to read the analog output of the Turbidity Sensor and convert it to a digital signal that the Raspberry Pi can understand. You can find more information on how to do this by visiting Adafruit. This will allow you to use the Turbidity Sensor with your Raspberry Pi projects and analyze the sensor data using software such as Python.


Code for the Arduino

If you have an Arduino and a Turbidity Sensor, you can use the analog output of the sensor to measure the turbidity of a liquid. To do this, you will need to connect the sensor to one of the analog input pins on the Arduino. Then, you can upload a sketch, or program, to the Arduino that reads the analog input and converts it to a digital value that can be displayed or used in your project. There are many examples of sketches available online that you can use as a starting point, or you can write your own code to customize the behavior of the sensor. Using an Arduino to read the analog output of the Turbidity Sensor is a simple and effective way to monitor the clarity of a liquid and take action based on the sensor readings.

if you enjoyed this post please consider supporting me on patreon:


Turbidity Sensor Examples


Photo of Mellow_Labs


Hellow im Mellow


Leave your feedback...