This project is aimed to create a plant monitoring and watering system. The main task is to control the servo, relay and collect the soil humidity data from the plants. Huge amount of the sensors use analog signal as output but the Raspberry Pi doesn’t have an analog-to-digital converter. To solve this problem, I used an outer ADC module and an Arduino gateway because they have built in ADC. When we want to interact with the environment we usually need pulse width modulation. I found 3 ways to solve this problem. The first one is the software PWM, the second one was the Arduino gateway and the last one was to use a PWM capable module/IC. I implemented the first two methods because I've implemented an I2C device before. The ADC and PWM are used very often in the Arduino world so if we want to use GPIO on Raspberry Pi we usually want at least one of these features to run on our Raspberry.
The AppThe application has two modes: an automatic mode when it detects if the plant need some water and a manual mode where you can control the servos and relays manually. Because the servo can rotate approximately 180 degrees one servo can water only 2 plants. The automatic mode is the default. When we read soil humidity sensors we categorize its value. There are 5 categories. The driest one is in categories 5 and marked with red on the GUI. Its opposite the category 1 is marked with green. A timer will check periodically these values and if the category of 'plant A' or 'plant B' higher than acceptable (so the ground is too dry) it waters the drier one. In the same period the program checks and waters the other two plant ('plant C' and 'plant D') in a similar way and do this in every period.
The components- Servo SG90:
Driving a servo usually requires large GPIO clock frequency. The default provider is not good enough so I used the lightning provider. There was an issue with the first power supply of the Pi. I've read it somewhere that the Pi might need a better performing one and servo consume a lot of power compared to other sensors. These two resulted performance issues. Now with the iPad's charger it works much better but sometime it still hesitates. A servo circuit with outer power supply could solve the problem like this one:
And as I thought this has solved the problem and now it works perfectly. I've connected the servo's Vcc to the power supply's 5V and the signal remains the same and we have common ground. Here is the new connection:
Finally, it's not necessary to do this way. Maybe a better power supply for the Raspberry Pi or refinement in the software would solve every problem with the servo.
- ADS1115 16 bit I2c ADC:
I've tried to build in every function to the ADS1115 16-bit ADC. But it's still under development. For example, threshold registers aren’t set and it'd deserve an own project/tutorial. All in all, it's almost ready to be a fully functional ADC driver. There might be some logical issues and all built in functions haven’t been completely tested.
- BMP180 I2c temperature and pressure sensor:
The BMP180 driver I used is basically the same that this project uses. I've modified only the initialization because it was not fully compatible with lightning provider. I suppose measuring the temperature and pressure belongs to projects like weather station, plant monitoring and other similar projects.
- Relay:
Driving a relay requires simple GPIO operations. It's quite easy to understand from the source code.
- Photodiode circuit:
I've used this module because this measurement might be useful in similar projects too. The amplifier circuit can be found in the LTC 1050's documentation. The photodiode is an Osram BPW 21 optimized for daylight.
- Arduino gateway:
For gateway I used an Arduino Due because it has 3.3 V pulled up I2C bus. I could have use voltage level converter or an another bus with your own pull up (if I know right the Arduino 2560 and some other boards has more I2C buses and they are not pulled up so you might use them). The code is quite simple.
- Soil humidity sensor:
I've used Chinese ones with comparator modules.
In my opinion this project might be helpful to give a very basic idea how to water our plants and there are some features that you might want to apply in your own projects like:
- Communicating with an Arduino board on I2C bus (Arduino gateway)
- ADC on Raspberry Pi
- PWM on Raspberry Pi (servo)
- Azure connectivity
- Mobile app with Xamarin
- Replace I2C with Bluetooth to communicate with the Arduino
Comments