Introduction: Data Transmission of Non-internet Connected Solar Systems With Arduino, PHP and MySQL
The aim of this arduino project is to acquire and transfer data via the GSM network. The benefit is to be able to collect data (for example monitoring of a solar plant) even if there is no hard wired internet connection available.
This is how it works:
- A value is read from arduinos analogue input A0 (in this case temperature)
- The GSM modem is started and a is connection established.
- pass.php gets called and the data value and security key is passed to the script.
- The script saves the value, the IP address and the current server time in the database.
- Arduino waits for a specified interval before repeating.
- The data can be plotted in a graph with plot.php or written to a csv file with csv.php
The code was inspired by and contains snippets from:
- Arduino (Leonardo)
- GSM Shield
- 10 kiloohm thermistor
- 10 kiloohm resistor
- SIM card (APN information required)
- Arduino IDE
Approximately every 10th connection attempt fails. It is unknown if the malfunction is related to the service provider or if other factors influence this behaviour (maybe weather?). If you have experiences concerning this problem you're welcome to leave a comment.
Potential for Improvement
Regular time intervals
At the moment the time value belonging to the measurement is defined when the measurement is written to the database. Because the time to build the connection to the GSM network varies, the time intervals are irregular.
Because the GSM modem is constantly powered and builds up connections frequently, the solution is rather energy demanding. To save energy and therefore improve the duration when powered by a battery pack, the measurements could be stored in an array and get uploaded in a bundle. This would allow the GSM Shield to be shut down for most of the time but would also require a method to determine the time locally on the arduino. Hopefully this solution would also solve the Bug at the same time.
Step 1: Webserver
The functionality of the project was tested with the Webserver bundle Xampp. Installing a webserver locally on your machine is useful for development and testing purposes. For logging data on a long term basis it would be advised to rent a webspace from a hosting service.
For the webserver to function properly an exception has to be added to the firewall to allow the service to connect to the internet.
If your computer is part of a wireless network you'll have to set up your router to forward port 80 to your network IP address.
Step 2: Webserver Scripts
The zip file contains a folder containing five php scripts. Simply copy the folder to the htdocs folder in your Xampp directory.
This is the only file you'll have to change.
Change the database login information according to your setup. You'll have to define a security key, which the arduino passes on to the webserver, to prevent unauthorized access.
This script sets up a database and table to write to.
If you're running a fresh Xampp install you should be able to run install.php without modifying config.php.
Allthough, to keep your database safe you should set a password for the root user in phpMyAdmin.
Arduino calls this script via the GSM network and passes the collected data on. The script stores the value to the database along with the current time and the ip address the value is coming from.
This script uses the library JpGraph to plot the values in a graph. You'll have to download JpGraph and place it in your htdocs directory before being able to execute this script.
This script writes the collected values to a csv file for further usage (for example in excel or the statistical computing program R).
Step 3: Thermistor Circuit
Arduinos analog in pins can read a voltage between 0 and 5 Volts and convert it to a number between 0 and 1023.
If solemnly the thermistor was connected to the input, the current would change proportional to the resistance instead of the voltage.
To achieve a change of voltage proportionally to the resistance we have to build a voltage divider circuit. By doing this the maximum voltage won't lie at 5 volt anymore, so we have to tell the Arduino what the new reference voltage is (Aref).
Step 4: Arduino Setup and Code
If you're using Arduino Mega or Leonardo follow the instructions for using the GSM Shield with these builds. This step is necessary for the serial communication between arduino and your computer.
Configure the setup variables in the arduino code for your web server, APN and thermistor circuit and information.
Upload the sketch and execute. Open the Serial Monitor in the Arduino IDE to check the functionality and for debugging.
We have a be nice policy.
Please be positive and constructive.