domenica 9 giugno 2013

How to make a wifi datalogger for temperature and humidity.


In this project I use two Arduino boards: the first one (Arduino UNO) is used for measuring temperature and humidity, the second one (Arduino MEGA 2560) for wifi connection
to my home lan. The two boards communicate each other through serial connection.

The Arduino UNO board has a DHT11 sensor (but you can use a more accurate DHT22 sensor) with a 10 kΩ resistor, a RTC module (from Adafruit: http://www.adafruit.com/products/264) and
a SD card module (from Adafruit: http://www.adafruit.com/products/254). This is a complete datalogger for temperature and humidity, infact it saves these two values with the time every 10 minutes (you can set this frequency in the sketch as you like, even if I suggest not less than 10 minutes because the file becomes too big) in a CSV file stored into the SD card. The sketch creates automatically the path for the log files using the path /templog/yy/mm/dd. You can read the logs putting the SD card into your pc's card reader.
The sketch provides some APIs for serial communication. The commands are:
1) sf& (size file):  the syntax is sf&yy/mm/dd?
   If you type this command on the serial monitor, the board will show the size of the file /templog/yy/mm/dd
2) rf& (read file): the syntax is rf&yy/mm/dd&startbyte&stopbyte?
   If you type this command on the serial monitor, the board will read the file /templog/yy/mm/dd FROM "startbyte" TO "stopbyte" and will send it through the serial port.
   So, if you want read the whole file, you must put startbyte = 0 and stopbyte = size of the file (in bytes). This syntax allows to split the file in several chunks, if it  is too big.

For example: the log for April 24th 2013 is in the file /templog/13/04/24, suppose its size is 2184 bytes. First you want to know the size of the file so you must type the command sf&13/04/24? on the serial monitor. The board will reply printing the value 2184. Then you can read the whole file typing the command rf&13/04/24&0&2184?


So: 
1 - connect the Arduino UNO board as shown in the figure below 
2 - create the "templog" folder in the SD card 
3 - insert the SD card in its module
4 - download the sketch test_comunicazione_seriale_UNO.ino from   https://github.com/rickit69/techrm/tree/master/test_comunicazione_seriale_UNO
5 - download the dht library from https://github.com/adafruit/DHT-sensor-library
6 - download the rtc library from https://github.com/adafruit/RTClib
7 - load the sketch

The board will start to save temperature, humidity, hour, minutes every 10 minutes. Use the serial monitor as explained above, to interrogate the board.



Wiring scheme




You can use the second board (Arduino MEGA 2560 with Weburban wifi module) to download the log files wireless:
1 - wire the board following the instructions in the article http://techrm.blogspot.it/2012/12/how-to-interface-arduino-mega-2560-to.html  and download the modified wireless     library from the same article
2 - download the sketch test_comunicazione_seriale_MEGA.ino from   https://github.com/rickit69/techrm/tree/master/test_comunicazione_seriale_MEGA

The sketch communicates serially to the UNO board through the Serial3 port. So wire the two boards following the scheme below:

MEGA                   UNO
pin 14         to         pin 0
pin 15         to         pin 1
GND          to         GND


Now open a shell and go in the folder where you downloaded the python script. These are the parameters for the script:

[techrm@notebook-dell test_comunicazione_seriale_python]$ python test.py -h
usage: test.py [-h] [-c COMMAND] [-y YEAR] [-m MONTH] [-d DAY] [-v]

optional arguments:
  -h, --help            show this help message and exit
  -c COMMAND, --command COMMAND
                        the command
  -y YEAR, --year YEAR  year (yy)
  -m MONTH, --month MONTH
                        month (mm)
  -d DAY, --day DAY     day (dd)
  -v                    verbose


In particular, -c is the parameter for the command. In the script the only command is "rf" (read file). For example, we want to download the log file for May 06th 2013 , so type
in the shell the command line   python test.py -c rf -y 13 -m 05 -d 06 
If you want to redirect the output to a file, type the command line   python test.py -c rf -y 13 -m 05 -d 06 > 13_05_06.txt




Finally, I wish to thanks my friend Mauro Pala for his suggestions about C language.

domenica 24 marzo 2013

How to remotely measure a temperature using Arduino and WiFi

First you need an Arduino Mega 2560 board and a Weburban WiFi board (this board uses standard connectors over SPI to an Arduino compatible Microchip 802.11b/g/n MRF24WB0MA).
Connect them as showed in http://techrm.blogspot.it/2012/12/how-to-interface-arduino-mega-2560-to.html
In this example I use ArduinoIDE version 1.0.3.
Follow the instructions about the setting of the WiShield library (you can load it from https://github.com/rickit69/techrm/tree/master/WiShield_Arduino_IDE_1.0.3). This library is modified to properly work with Arduino Mega 2560 board AND ArduinoIDE version 1.0.3.

Now you need a DS18S20 digital thermometer (http://www.maximintegrated.com/datasheet/index.mvp/id/2815) and a 4.7 kΩ resistor. Now connect them to the Arduino board as shown in the picture:























Now you need to download two applications and a library from https://github.com/rickit69/techrm:
1) test_wifi_temperature, a simple sketch for measure temperature remotely
2) test_arduino_temp_wifi, a simple php application to use with test_wifi_temperature sketch
3) OneWire, more informations at http://playground.arduino.cc/Learning/OneWire

Place the OneWire folder into your Arduino Library. Here are the default library folder locations:
On  Mac:: In (home directory)/Documents/Arduino/libraries
On  Windows:: My Documents -> Arduino -> libraries
On  Linux:: (home directory)/sketchbook/libraries

Put the folder test_arduino_temp_wifi in the documents folder of your  Apache server (for example, in my Fedora Linux it is /var/www/html/). Put the test_wifi_temperature folder in the sketchbook of your Arduino IDE.

In the test_wifi_temperature.ino file modify the wireless parameters (ip address, subnet mask, gateway, SSID, security type,  WPA/WPA2 passphrase or WEP keys) according to your wireless network parameters.

Compile the sketch and load to the Arduino.

Now go in the folder test_arduino_temp_wifi and, in the test.php and test_controller.php files, modify the ip address (in the example it is 192.168.0.3) according to the ip address in the test_wifi_temperature.ino.

Open a browser and go to the URL http://localhost/test_arduino_temp_wifi/test.php.

You'll see a webpage with a form and one button. The button is to send a request to Arduino which will reply with a xml file containing the temperature value. The php page will display this value. You can see a screenshot below:










giovedì 10 gennaio 2013

How to remotely control a led using Arduino and WiFi

First you need an Arduino Mega 2560 board and a Weburban WiFi board (this board uses standard connectors over SPI to an Arduino compatible Microchip 802.11b/g/n MRF24WB0MA).
Connect them as showed in http://techrm.blogspot.it/2012/12/how-to-interface-arduino-mega-2560-to.html
In this example I use ArduinoIDE version 0021.
Follow the instructions about the setting of the WiShield library.

Now  connect a 470 ohm resistor and a led in series between pin 12 and pin gnd of the Arduino, as shown below:

  This picture shows the final result:

                                                                                                           

Now you need to download two applications from https://github.com/rickit69/techrm:
1) test_arduino, a simple php application
2) test_my_server, a simple sketch.

Put the folder test_arduino in the documents folder of your  Apache server (for Linux it could be /var/www/html/). Put the test_my_server folder in the sketchbook of your Arduino IDE.

In the test_my_server.pde file modify the wireless parameters (ip address, subnet mask, gateway, SSID, security type,  WPA/WPA2 passphrase or WEP keys) according to your wireless network parameters.

Compile the sketch and load to the Arduino.

Now go in the folder test_arduino and, in the test.php and test_controller.php files, modify the ip address (in the example it is 192.168.0.3) according to the ip address in the test_my_server.pde.

Open a browser and go to the URL http://localhost/test_arduino/test.php.
You'll  see a web page with a form with 2 buttons. One button is to turn on the led, the other one is to turn it off.

The sketch test_my_server receives the commands from the php app test_arduino and then turns on/off the led.

The video below shows you the application running: