Raspberry Pi and Arduino in Harmony – As a Sensor web Server



This Arduino and Raspberry Pi based project takes sensor data from the Arduino and sends it over USB to the Raspberry Pi. The data is then formed into a web page on the Pi. The web page is fully customizable. Here we use the Freetronics IR Thermometer Module to supply a stream of data to the Arduino then to the Pi. Its good if you want to have the Arduino host webpages that contain sensor data but you don’t have a Ethernet Shield. Just send it to the Pi to take advantage of more computing power.

You Will Need:

•— Raspberry Pi B, B+, 2 (So long as it has a USB port and Ethernet) & Power Supply
•— Arduino (Any model with USB connectivity will work) & USB Cable
•— IR Thermometer from Freetronics (Or you can use any sensor compatible with the Arduino. Just modify the code to suit)
•— Cable to connect sensor to Arduino



Part 1 – Construction and Programming

Step 1: Wire up the sensor to the Arduino. If you are using the IRTEMP module you may like to refer to here. Alternatively you can connect the IRTEMP module directly to the Arduino by connecting it to pins 3 – 6 on the Arduino (Refer to image).

Step 2: Flash an SD card with the latest version of Raspbian. Refer to this guide for more information

Step 3: If you are NOT using the IRTEMP module then you will need to write a piece of code for the Arduino that sends the output of the sensor over serial at a speed of 9600. If you ARE using the IRTEMP module then download the IRTEMPUSB.ino file from the downloads page.

Step 4: Now we will program the Raspberry Pi, so make sure that you have flashed the SD card with Raspbian and connected the Pi to your local network (Internet access required on Pi) and plug into power. Wait a minute for the raspberry pi to boot then find the IP address of the Pi. You can do this by logging into your router and looking at a list of devices on your network. Once you have found the IP address proceed.

Step 5: SSH into your Pi. You can use on of the many methods listed here. If you are using windows then I recommend PuTTY.

Step 6: We now need to setup the Pi as a web server. We do this by first updating the Pi with sudo apt-get update then sudo apt-get upgrade. Then we install the packages required;
sudo apt-get install apache2 libapache2-mod-wsgi python-setuptools python-flask python-serial. This may take a while depending on your Pi and internet connection.


Step 7: Once installed we need to make changes to the Virtual Host file in /etc/apache2/sites-available/000-default. This can be done by first making a copy of the original file with cd /etc/apache2/sites-available then sudo cp 000-default 000-default.orig. Use ls to ensure that the new file was created. Now that we have a backup lets get and install the file changes with wget -O 000-default https://raw.githubusercontent.com/jedhodson/arduino-and-pi-in-harmony/master/pi/000-default-mod.
This will update the 000-default file with the changes needed for this project. Take a look at them with nano 000-default and CTRL+X to exit.

Step 8: Now we need to make some changes to the user permissions. We do this by typing
sudo usermod -a -€“G dialout www-data then sudo a2enmod wsgi. Now we restart apache with
sudo /etc/init.d/apache2 restart. Now you have set up apache

Step 9: Now for the last part in setting up the software on the pi, we need to install the html files that will server the webpages and the python script to make the magic happen. First get to the home directory with cd then clone the GitHub repository with git clone https://github.com/jedhodson/arduino-and-pi-in-harmony.git. Now we make the directory to store the web server files with sudo mkdir /var/www/serialData followed by sudo cp ~/arduino-and-pi-in-harmony/pi/serialData/* /var/www/serialData/.

Step 10: Congrats! You have setup the Pi. Now all you have to do is start the script with python /var/www/serialData/index.py then plug in the set-up Arduino and navigate to http://YOURIP/serialData/index.py and you should see something similar like that shown below. To stop the script use CTRL+C.

Screenshot of output


7 Comments for “Raspberry Pi and Arduino in Harmony – As a Sensor web Server”


Hey Jed,
I am currently working on a similar project to this and just found your project which is super useful. I do have a problem downloading some information from your site. Could you give me a hand?


Jed Hodson


Hi Konstantin,
Sorry about the dead links. Had to shutdown our GitLab server. Here’s the link to the GitHub instead https://github.com/jedhodson/arduino-and-pi-in-harmony


Hey Jed,
Thank you the link works now no problem!!
I’m currently trying to the same project as you just using a different sensor shield type and sensor that goes with it. I already have the raspberry pi 3 B and the arduino uno latest one. On the raspberry pi I already did some work on it and did the first setups. I would have some more questions as I go along doing it. Would we be able to exchange email for that or you prefer over here?




sudo wget -O 000-default-mod https://www.prototypingcorner.me/?ddownload=113
–2016-12-25 10:38:29– https://www.prototypingcorner.me/?ddownload=113
http://www.prototypingcorner.me (www.prototypingcorner.me) çözümleniyor…
http://www.prototypingcorner.me (www.prototypingcorner.me)[]:443 bağlanılıyor… bağlantı kuruldu.
HTTP isteği gönderildi, yanıt bekleniyor… 500 Internal Server Error
2016-12-25 10:38:31 HATA 500: Internal Server Error.

Can you help about that?

Leave a Reply

Your email address will not be published. Required fields are marked *