Example Code for MakeCode of Water
Last revision 2026/01/27
The article provides an in-depth look at water quality testing principles using MakeCode, focusing on TDS values. It covers basic knowledge of water, the importance of protecting water resources, and practical TDS measurement methods using probes. Readers will understand water's role in life, pollution challenges, and how to test different water sources, ultimately gaining insights into preserving our limited freshwater resources.
Principle
1.Basic knowledge of water
Water is the source of life. But how much do you know about water? Let's look at some little knowledge together.
Water (H2O) is an inorganic substance consisting of hydrogen and oxygen, a transparent liquid that is colorless and odorless at room temperature and normal pressure.
Water has three states: liquid, solid, and gas.
Seventy-two percent of the earth's surface is covered with water.
There are about 1.5 billion cubic kilometers of water on earth.

Ninety-seven percent of the earth's water is salty, and 2.1 percent of the water is still frozen in the polar ice sheet, so the fresh water that we can drink directly is less than 1 percent.
60% to 70% of our bodies are made up of water, i.e. about 42 kg of water in a 70 kg human body.
Where there is water on earth, there is life. Whether in almost boiling water or in strong acid.
2.Protecting water resources
We have just learned that we can drink less than 1% of the fresh water directly, and our drinking water resources are very limited.
Despite the limited freshwater resources, there is still a large amount of water that is polluted and wasted.
There are garbage and plastic bags floating in the river, industrial waste water sneaking into the river, etc....
What can we do to protect water resources?
To protect water resources, what we can do is to start with the little things, save water, turn off the tap, and not pollute the water source.

3.Water Quality Measurement and Analysis
Introduction of TDS Water Quality
In the last section, we learned that our drinking water resources are very limited, we understand water pollution, we know how to save water, protect water resources and so on. So now let's learn about water quality measurements.
To begin with, let's look at a noun: TDS. TDS is an important parameter that affects water quality.
(1) What is the TDS value?
The TDS value refers to the total dissolved solid, also known as the total amount of soluble solids, measured in mg/L. It shows how many milligrams of soluble solids are dissolved in 1L of water. The higher the TDS value, the more dissolved matter is contained in the water.
Simply put, the TDS value partly reflects the purity of the water. The lower the TDS value, the higher the water quality, the higher the TDS value, the more soluble solids contained in the water, but water with high TDS values is not equal to harmful.

For example, the water inside the river, TDS value is about 400. And tap water is about 100, bottled pure water is about 10, while the TDS value of juice is 500. From the values above, the purity of bottled pure water is very high, impurities are very small. The TDS value of fruit juice is 500, but it is harmless to humans.
But TDS is not the only criterion for determining water quality. TDS can only measure conductive substances in water, but cannot detect bacteria, viruses and other substances. We also need to comprehensively test the pH of water, acidity, bacterial content and so on project comprehensive assessment of whether water can be directly consumed. We also need to comprehensively test the pH of water, acidity, bacterial content and other projects to assess whether water can be directly consumed.
(2) Measurement and application scenarios for TDS values
The following image shows us the application scenario of TDS detection in actual production and life, such as water quality testing pen, water purifier, swimming pool, water treatment plant, etc. will do TDS value testing.
Although TDS value is not the only indicator to determine water quality, it is an important indicator to determine water quality.

Sample Code
Here we programming a water quality testing program to test different water sources and record the corresponding TDS values.
The program is as follows:

For more information, refer to the Getting Started guide.
Measure
1.Plugin TDS probe to TDS socket.

2.Put the probe to different water resources and shake it lightly, read and record data shown in the OLED display. The table form is shown as below:

By selecting different water sources in different locations for testing and recording, we will come up with a set of TDS data that can intuitively understand the pollution of different water sources in different regions.
Conclusion
Through the learning above, we have learned the following:
- The basic knowledge of water, and learned a little knowledge of water.
- Knew the importance of water to human beings, and knew that water should be saved.
- Understood the application scenario of water quality testing and the concept of TDS values.
- Learned to use TDS probe to test the TDS values of different water sources, and make a record table.
Was this article helpful?
