HTMAA Week 9

Assignment Description: 

measure something: add a sensor to a microcontroller board that you have designed and read it

Link to the assignment page

Input Devices – Hydroponics

For the next few weeks I will be working towards my final project, an automated watering and feeding system for my hydroponic gardens. In order for the system to know when and how much water and nutrients to dispense, I will need a few sensors:


I used the board I designed and assembled previously.

Code


I wrote the following code to enable the use of my sensors. ChatGPT helped with a lot of the boilerplate here.

  • sensors.py - groups all of the sensors into a central location for testing
  • water_level_analog.py - Reads analog voltage from the water level sensor
  • ecsensor.py - Calibration and readings, rewritten library to support python3 and OOP
  • ds18b20.py - Mini library that supports temperature readings and OOP


Water Level Sensing


I first started by testing my water sensors. These are advertised to work both analog and digital, with the analog route roughly increasing in voltage as the sensor is exposed to more water, and the digitial running high if any water is detected. For what I expected to be a pretty easy to use sensor, I actually had quite a few problems, though it turned out that past Sam had sabotaged me. If you look closely, you may be able to spot my problem. More on that later.

Here you can see the absolutely tiny difference in voltage (4.9v to 5v) from placing the sensor in the water. I felt like something was up, so I pulled up the actual pinout for the Xiao RP2040 and noticed my problem. Instead of looking at the Xiao pinout, I had been looking at a diagram I made for myself in week 6, but it turns out that I had flipped my ground and 3v3 lines on all three sides. Somehow. The fixed diagram:

After flipping the power and ground pins, I had success (analog and digital):

Now that I have actually worked with them, I think that these sensors will not be ideal for measuring the water level inside the reservoirs due to condensation, so I may replace them with smaller float sensors.


Temperature


This sensor was pretty easy to use and no fuss once I found the right library to import to read the values. I implemented methods for reading single values as well as batch averages.

The readings on the right display the progression from room temperature to warming in my hand to a glass of water.


EC Sensing


This sensor was quite difficult to use given the library provided from the manufacturer had no documentation and was written in Python 2. I rewrote it and made it use OOP, which will be nicer to use once my project starts to baloon in complexity. I also integrated a nice use of my onboard button for the calibration.


I measured the EC of one of my gardens and it appeared to be in the right range!