Arduino – Temperature Web App with Raspberry Pi

This project allows you to get a temperature value from the Arduino, pass it to the Raspberry Pi, have a Python Script process that value and store it in a file, then have a PHP Script read the file and create a dynamic web page. This is a simple project, but shows the concept of designing a system that hands tasks between different physical devices and programming languages.


Functional Parts in the Project:

Arduino Sketch

#define sensorPin A0

void setup() {

void loop() {
  int reading = analogRead(sensorPin);
  float voltage = reading * 5.0;
  voltage /= 1024.0;
  float temperatureC = (voltage - 0.5) * 100 ;
  float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;



Install Apache on Raspberry Pi

sudo apt-get install apache 2

Install PHP on Raspberry Pi

sudo apt-get install php

Change Ownership of HTML Folder on Raspberry Pi

sudo chown pi /var/www/html

Python Script

import serial

if __name__ == '__main__':
    ser = serial.Serial('/dev/ttyACM1',9600, timeout=1)
    while True:
        if ser.in_waiting > 0:
            line = ser.readline().decode('utf-8').rstrip()
            file = open("/var/www/html/data.txt","w")

tempApp.php PHP Script

<meta http-equiv="refresh" content="5">


$temp = file_get_contents("data.txt");

if ($temp >= 70){
	}else if($temp >= 60 && $temp < 70){
	} else if($temp < 60){
	} else {
print "<h1 style='text-align:center;'>Arduino/Raspberry Pi Temp Web Device</h1>";
print "<br>";
print "<p style='text-align:center; font-size:200px; margin-top:10px; margin-bottom:10px; color:".$color.";'>".$temp."</p>";


Get IP Address of Raspberry Pi

sudo ifconfig
sudo ip address

On another computer go to the in the web browser

Be the first to comment

Leave a Reply