We live in an era where the human being wants to control everything, and he wants to do that the easiest way possible, so this project lets you do that with your plants, most of the time i'm too busy and forget to water my plants. To solve this problem, I am building a portable irrigation system that waters my plants depending on the soil moisture, and sends the plant's temperature and humidity and soil's humidity to an internet plateform and i've chosen thingspeak, and also it sends those data by sms to my phone and alerts me when the humidity of the air is too high
why did I chose thingspeak
thingspeak has so many features
Some of ThingSpeak Features
- Real-time data collection and storage
- MATLAB® analytics and visualizations
- Alerts
- Scheduling
- Device communication
- Open API
- Geolocation data
- Available on GitHub®
Personally I especially like ThingSpeak because it's so easy to send data to it and it helps so much with analytics as it works with MATLAB ; Last couple months I had many problems with ESP8266 "ESP01" which is the wifi module i used; as it works with AT commands ( basic comands to send data) thus it's somehow difficult to send data with these commands , you can still flash your ESP-01 but I found that too complicated as i've been uploading firmwares or testing tools and IDEs. I have spend many times hours on small problems . And here I found ThingSpeak which I wanted to test. And you know what? In just 10minutes (really) I have created a new account ,I have added a new channel (device) and I have learned basic API examples
Next thing, i made a calculation on the temperature data ,I have tried to create a basic Matlab programe, which was calculating average temperature. or the correlation between temperture and humidity, you can find all of these codes examples in there website
thingspeak uses applications, one of its application is called talkback it uses the same API protocol as to send or get data from thingspeak but this time to control your IOT, i've used that to control the plants irrigation, so that my system wouldn't only be automatic, now I have full control etither I want it to work in the manual mode where I can command the pump from internet or I want it automatic where it will irrigat according to the soil humidity
But now what if we dont have internet, does the system stop sending data ?
there are many solutions and I have made some of them, thingspeak is an open plateform so I thought if I cant go to thingspeak I will make thingspeak come to me, I installed it in a raspberry pi 3, no probleme if you don't have a raspberry you can just install it in your pc, the only condition is that you have to install the rasbian distribution of linux ; another solution for saving your data in case the thingspeak server stops, i've put an SD card reader for the arduino so that the data is stocked localy in it
INSTALLATION OF THINGSPEAK PROCESS:
1. Install a Raspberry Pi Operating System image on SD card- Download the Raspbian image from RPI website
- Write image to SDCard
For more details please read RPI Install Guide
I was using the Win32DiskImager utility under W7Pro for that, worked like a charm.
- Inset card in RPI2
- Boot
- From raspi-config:
– Set to use entire SDcard space– Set hostname: RPIMON1– Enable SSH Server– Write down your new RPI IP: 192.168.2.xx
- Reboot for apply new hostname & settings
pi@RPIMON1~$ sudo reboot
3. System Update & required packages install- Switch over to SSH remote access with Putty – accept new key
- Change “pi” account password:
pi@RPIMON1~$passwd
- Set ROOT password, so you can then use root
pi@RPIMON1~$sudo passwd root
- System Update & upgrade :
- pi@RPIMON1~$sudo apt-get updatepi@RPIMON1~$sudo apt-get upgradepi@RPIMON1~$sudo apt-get dist-upgradepi@RPIMON1~$sudo sync
- Reboot:
pi@RPIMON1~$ sudo reboot
- Required packages:
pi@RPIMON1~$sudo apt-get -y install build-essential git mysql-server mysql-client libmysqlclient-dev libxml2-dev libxslt-dev libssl-dev libsqlite3-dev
4. MySQL Database configuration
pi@RPIMON1~$mysql –user=root mysql -p useyourpasswd here
pi@RPIMON1~$mysql> CREATE USER ‘thing’@’localhost’ IDENTIFIED BY ‘speak’;
pi@RPIMON1~$mysql> GRANT ALL PRIVILEGES ON *.* TO ‘thing’@’localhost’ WITH GRANT OPTION;
pi@RPIMON1~$mysql> commit;
pi@RPIMON1~$mysql> exit;
5. Ruby & Rails install
pi@RPIMON1~$wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gzpi@RPIMON1~$tar xvzf ruby-2.1.5.tar.gz
pi@RPIMON1~$cd ruby-2.1.5
pi@RPIMON1~$./configure
pi@RPIMON1~$make
pi@RPIMON1~$sudo make install
pi@RPIMON1~$cd..
pi@RPIMON1~$echo “gem: –no-rdoc –no-ri” >> ${HOME}/.gemrc
pi@RPIMON1~$sudo gem install rails
6. THINGSPEAK SERVER INSTALL
pi@RPIMON1~$git clone https://github.com/iobridge/thingspeak.git
pi@RPIMON1~$cd thingspeak/config/database.yml.example thingspeak/config/database.yml
pi@RPIMON1~$cd thingspeak
pi@RPIMON1~$bundle install
pi@RPIMON1~$bundle exec rake db:create
pi@RPIMON1~$mysql –user=root mysql -p
pi@RPIMON1~$mysql> show databases;
pi@RPIMON1~$mysql> exit;
IF all OK continue with loading Thingspeak DB configuration
pi@RPIMON1~$bundle exec rake db:schema:load
RUN the THINGSPEAK SERVER:
pi@RPIMON1 ~/yourthingspeak $ rails server webrick
in the Browser type : http://"raspberry ip adress":3000
And the result :
and that's already a big solution for the internet probleme after this you have your computer that works as a server
now all you have to do is set up the you arduino as it would send the data to the plateform and I chose the http protocol as my ESP01 works with AT commands :
https://www.sparkfun.com/datasheets/Cellular%20Modules/AT_Commands_Reference_Guide_r0.pdf
you just have to follow the code i've posted and change it following your parametres
for the wifi the raspberry and the arduino must be conected to the same router same network , change the apikey with your api key either you're sending data to the thingspeak website or localy ,or both ; and the hostname and password by your acces point's hostname and password
and you have to change this ip adress and put the raspberry adress
and also to make the code work you have to install these libraries
change the number in the SIM fonction
follow all the pins as in the schematic
or change the code according to your setting
- for the keypad pins
- for esp01 (wifi) pins
for the GSM you have to follow the schematic RX --->11, TX----->10
for other componants I recomand doing as the schematic because i've made many digital pins work as VCC or GND because there isn't much power pins for all the componants and as I wanted to put the system in a box that was one solution ; but as I always say there's always another solution so if you dont want to do that you can follow what pin i've set as VCC and which one GND and you just have to change them as you want
for the talkback, tyou have to change these following you API and comand id in thingspeak
if you follow that and the schematic everything should work great
now once you change the code, and upload it in your arduino and set up your raspberry and everything works ;
you have to start the server in the raspberry but then you dont want to plug your raspbberry to a screen everytime you want to start the server, so you can get your raspberry screen in your phone, all you have to do is install XRDP in your raspberry
and an XRDP app in your phone
conect to the raspberry with XRDP ;
and do as follow on your phone after pluging your raspberry without screen :
start the system , it should tell you enter the password, the password is "1234" (if didn't changed in the code)
and then it displays " press 0 for help " as follow
there is a menu for the keypad
"0" for help
"1" for diplaying temperature and time
"2" for diplaying humidity and time
"3" for diplaying the soil humidity and time
"5" for switching to the internet mode ( if the arduino is conected to internet if not do not enable that)
"D" for diplaying the date
A for the automatique mode
""B" for the manual mode, (this works with internet, if there's no internet do not enable it)
"#" to send data to the the local thingspeak
"5" + "#" send data to the local thingspeak and internet thingspeak
"C" to display the data that is saved in the sd card
here are some pictures
and here are some plots I have made with the internet singspeak
and here is the link to view my public chanel if you want to check the result
https://thingspeak.com/channels/416097
Comments