This is the take care of our plants project, an online an offline initiative to make automated/smart gardening much more accessible.
takecareofourplants.py, calc.py, and submit.py are the three Python files of the most recent r/takecareofourplants iteration. The reddit bot u/takecareofourplants will read in users comments from the previous day, and determine (based off of whether they said yes or no) whether or not to turn on the water pump and water the plant. The plant's survival is completely based off of user input. The users vote daily based off of past trends and the soil moisture levels.
This takes care of reading the soil moisture and turning on the pump for the plant. The pump and soil moisture sensor are attached to a Raspberry Pi Zero. The pump is attached indirectly through a relay and the sensor is attached directly to the GPIO pins (getting an ADC soon to have more accurate readings.
This is the code which looks at the post from the previous day, combs through user comments, and determines an overall counter value based on the yes/no votes. The counter must be greater than zero for the pump to be turned on. This result gets written to a file for the RPI to use.
This is the script which, both after reading in the comments and watering/not watering the plant, reads in the new soil moisture and makes the daily post with updated data for the users to deliberate over for the next 24 hours.
everything below this line is no longer maintaied and might not work! the garden monitor is a simple JAR file so it will but the old reddit component relies on alot of Node.JS libraries which, at the time, were not well maintained...
Index.js is the file for the first iteration of the project which lasted from November 2017 - May 2019. This file is a verbatim copy and paste. Copy this code into a local JS file, install the proper libraries, and input the proper keys for the reddit API and pubnub. What this does is it takes input from an arduino and raspberry pi, and takes users votes, based on this data, whether or not the plant(s) should be watered. This is the stepping stone for the more generally applicable, downloadable client based off of this project.
the following files are allocated to the Reddit aspect of this project:
- Index.js
- humid.js
Currently only for Windows
The next aspect of this project and the currently maintained one, is the Take Care of Our Plants Garden Monitoring System. This is currently in early beta stages, but a usable client (TakeCareOfOurPlants.exe) is posted above for download!!!
This system is written in Java with a small JS component which manages the reading of the data from your garden. I have set this up so that, following the detailed guide below, anyone can monitor their garden from anywhere in the entire world.
Click here to download it or get it above
- Raspberry Pi 3b
- Raspbian OS on a micro SD
- Arduino UNO microcontroller
- Soil Moisture Sensors x2
- Humidity/Temp Sensors
- Jumper Cables
- Arduino Power Cable
- Raspberry Pi power supply
- Download the following pieces of code -- TakeCareOfOurPlants.exe, write.jar, sensors.js, and send.js.
- First we are going to set up the executable program as this is the easiest. Just move it onto your desktop and double click on it. That program will inform you if you need to install any other packages in order to run it (java)
- the remaining 3 files are all to go on your raspberry pi. write.jar is a client to write your pubnub keys to a text file, sensors.js is the code which takes the arduino sensor data and writes it to text files, send.js sends this data to the pubnub servers which act as our in between service.
- go to https://www.pubnub.com/ and make an account with them. Once you go through all of the steps and log in, it should bring you to a dashboard. Here you are going to click "create new keyset" create 3 new keysets, name them respectively "soil1", "soil2" "humid".
- clicking into these keysets will show you your subscribe and publish keys. these are very important.
- Boot up your raspberry pi by inserting the micro SD card as well as plugging in the power cable. YOU WILL NEED A MOUSE AND KEYBOARD!!!!!
- configure the pi, set up your wifi network and then in raspberry pi configuration, turn on VNC. this will allow you to access the pi wirelessly from another computer
- once you have created a vnc account and signed into that on both the pi and the VNC connect app on your computer, connect to the pi from your laptop, it is much easier.
- ok now here comes the most technical part of all of this. open the terminal on the raspberry pi and type,
node -v
if that number is around 4,5 or 6, (or even higher!) we are ok. Then typenpm -v
if that number is around the same range we are also ok. if neither or either of these did not work as described we are going to go ahead and reinstall one, or both. - to do this, we are going to type in the terminal
sudo apt-get purge -y nodejs npm
this removes all nodejs and npm files if there are any and allows us to do a fresh install - after types YES or Y through all of the commands, we should have rid ourselves of old Node JS! Now to do a quick reinstall of the new stuff we type
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
then typesudo apt install -y nodejs
- after doing this, type the same commands
node -v
andnpm -v
and they should be working perfectly! if NPM by any chance does not show up, typesudo apt-get install npm
- Now, open the file system on your pi and create a new folder somewhere randomly within \home\pi. Call this folder whatever you like, within it you can create 3 new files, naming them respectively what the 3 remaining files you downloaded were. you can download "Filezilla" to transfer the files but honestly just copy and paste their contents into the files you just created in the folder.
- You can choose to use write.jar at your own risk, this file is finicky on the pi and it is genuinely easier to, once in your newly created folder, click file, create empty file, and then name it "list.txt" within this file you can add on each line 1) the pubnub channel name, SPACE 2) the pubnub subscribe key, SPACE 3) the pubnub publish key. This will allow the file send.js to easily send the data to the proper places. IF you can get Java working on the pi and that process is too complicated for you, use write.jar.
- now once the files have been sorted out, go to the terminal on the pi again, type
cd YOUR_FOLDER_NAME
then typesudo npm install -g pm2
- after setting up our files, before we can run them and read/send data, we need to set up the hardware components which will manage/send our data.
- open up your arduino, plug it in to your PC with the power cable you purchased. go to the Arduino Website to download the IDE and scroll down, and download.
- after opening that up go to Tools,Board and the choose Arduino/Genuino Uno after doing this go down on that same list and click ports click the "COM" port with the arduino name next to it.
- We are then going to load a script onto the arduino so we can read it directly from the raspberry pi!
- go to File, Examples, Examples for any Board, Firmata, Standard Firmata This is a script which allows the arduino to be accessed by external sources/libraries. Once this is opened, click the rightward arrow in the top left that says Upload when you hover over it. This should successfully upload the script to your arduino.
- Now we are going to wire up the Arduino pins with the soil moisture sensors. Pull out your two soil moisture sensors and plug the wires that they come with into the sensor itself properly. the BLACK wire gets plugged into the GND or Ground port of the arduino, the RED wire gets plugged into the 3.3V port of the 5V port, either one. and the BLUE wire gets plugged into port A0 for one sensor and A2 for the other. these are the ports that read the data. plug them in EXACTLY AS INSTRUCTED
- Pull Out your humidity sensors, open one up and plug the + port into the BOTTOM LEFT port of the Raspberry pi. when talking about directions bottom left is the leftpost GPIO pin on the opposite side of the board from the USB ports. This is also called PIN 2 the - port gets plugged into PIN 6 or the third pin up from the bottom left. The last pin which is the out pin gets plugged into PIN 29/GPIO5 or the 6th pin from the top right.
- In the raspberry pi terminal cd into your folder if not already and then type
npm install
this command is Supposed to install all proper libraries but rarely ever does so after typing this just to be sure type,npm install johnny-five
,npm install system-sleep
,npm install pigpio-dht
- after setting up the hardware and installing PM2, and other libraries. type
sudo pm2 start sensors.js --name sensorbot
and thensudo pm2 start send.js --name sendbot
in the raspberry pi terminal. - you can check on these bots by typing
sudo pm2 log
and stop them if they are throwing errors by typingsudo pm2 stop BOT_NAME
. - you are now all set up!!!! open up the desktop application (TakeCareOfOurPlants.exe) enter your credentials and you're ready to go!!!