Introduction: DIY Arduino and Raspberry Pi Weather Station and Web Server
This is a project that will take the temperature using the TMP36 IC temperature sensor and a Arduino board. This data will be send over serial to the Raspberry Piboard editing a web page that the Raspberry Pi is hosting itself. For this project you will need these components :
- Arduino board
- Raspberry Pi 2 board
- TMP36 temperature sensor (or any other analog IC temperature sensor)
- Half-Sized breadboard for testing
- Wireless keyboard & dongle
- Wireless mouse & dongle
- Pliers
- 3 long jumper wires
- 2 micro USB cables
- USB power brick
- 8 GB or large micro-SD card and adapter
- Cordless soldering iron (or a wired is fine but it is easier to do it with a cordless one)
- Solder
- Thin wire
- 3 male headers
- A laptop or desktop PC or Mac
- Ethernet wire or Wi-Fi dongle
- HDMI wire
- HDMI capable TV or Monitor
And this software:
- Raspbian Wheezy(Download on laptop burn to SD card and insert into the Raspberry Pi )
- Apache2 server(Raspberry Pi)
- FTP server(Raspberry Pi)
- ApplePi-Baker or win32-disk imager (on laptop)
- Arduino IDE (Raspberry Pi)
Step 1: Set-up the Raspberry Pi
First of all connect all the peripherals to the RPi and power it on. On the screen you should be promoted to sign in, so for the User Name use 'pi' and password 'raspberry'. Once you're logged in type in 'startx' to get into the Graphical User Interface or GUI. Open the Terminal by clicking on the monitor icon on the top left of the screen. Type in 'sudo apt-get update && upgrade' and then 'sudo apt-get install arduino' to install the Arduino IDE. Next follow this great video by Tinkernaut to setup the web server. Just a comment if you are on a Mac or a Linux PC you don't need to ssh using putty just open a terminal window and write 'ssh user@ipadress' and you should be in.
Step 2: Setting Up the Arduino & Editing the Webpage
Now we're going to set up the test of our sensor. If the flat side is facing towards you the bottom pin is Vcc or 5V the middle pin is the analog output an the top pin is ground. Now open the Arduino IDE, go to tools -> port and select your Arduino board. Remember the serial port you will need it later. Now upload this code to your board.
int temperaturePin = 0; void setup() { Serial.begin(9600); } void loop() { float temperature = getVoltage(temperaturePin); temperature = (temperature - .5) * 100; Serial.println(temperature); delay(1000); } float getVoltage(int pin){ return (analogRead(pin) * .004882814); }
So we have our default webpage on the pi account in /var/www/index.html. I have written a python script that imports the serial library, makes a serial connection to /dev/ttyACM0. Next it makes a command called tempupdate() that edits the webpage and substitutes in the current temperature outside. On your RPi open Python 3 under Start - Programing - Python 3. click on File-New window and paste this code in:
import serial import time ser = serial.Serial('/dev/ttyACM0', 9600) def tempupdate() : var1 = ser.readline() repr(var1) fob = open('/var/www/index.html', 'w') fob.write('<html><body><h1>The temperature outside is :' + repr(var1)+ 'at'+ time .strftime('%l:%M%p on %b %d, %Y') + '</h1></body></html>') fob.close()
Next press f5 save it as tempupdate.py on your desktop and in the newly opened python shell type after the >>> 'while 1 :
tempupdate()'
Well now it's done. If you wan to you can use the wire and make a extension outside like me so that you don't have to put the whole contraption outside. I hope you enjoy your Arduino/RPi weather station.