Smart Environment Monitoring system (SEM)

Smart Environment Monitoring system (SEM)

The Smart Environment Monitoring (SEM) system is an Arduino and web based (PHP) system that monitors, records and analyses environmental metrics both inside and outside (using external service) of the room that the Arduino device is located in.

The circuit schematic can be seen below. The main sensor used is an AM2302 which is a temperature and humidity sensor. The system also uses a photoresistor to measure light levels. Most Arduinos could be used to build this system, I used a Yun just because I had one available and the board had inbuilt Wi-Fi which made the system more portable.

The completed circuit can be seen below.

I put the system into a project box.

The following code was uploaded to the Arduino:

#include <Bridge.h>
#include <HttpClient.h>
#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to

#define DHTTYPE DHT22


double Light (int RawADC0){
double Vout=RawADC0*0.0048828125;
int lux=(2500/Vout-500)/10;
return lux;

String pass = "semcw2015";
int sendled = 3;

void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
digitalWrite(13, HIGH);

pinMode(sendled, OUTPUT);


void loop() {

float h = dht.readHumidity();
float t = dht.readTemperature();
int l = Light(analogRead(A0));

HttpClient client;

client.get("" + pass + "&t=" + String(t) + "&h=" + String(h) + "&l=" + String(l));

digitalWrite(sendled, HIGH);
digitalWrite(sendled, LOW); 


This code should work on any Arduino but the Bridge.h reference should be removed this is used to connect to the Yun’s Wi-Fi.

The URL in line 41 needs to be changed to the URL that you are using, this can be a internal IP.


The Arduino sends information to a server this can be hosted online or on something like a Raspberry Pi.

The Web code and MySQL setup can be found in the GitHub repository here.


The MySQL database can be setup using the SQL file in the SQL folder of the repository.


Download the web code from the Web folder of the repository.

Change the settings in the db.php file in the web folder to connect to your MySQl server.

Upload all the files in the Web folder to your server.

Setup a cronjob to run the offinecheck.php file every 15 minutes this code checks if the device is online and if not it sends an email to the system admin.

The weather information is provided by (now and this service requires a unique api key which can be acquired by registering for a free account. The system allows 1000 free api calls per api per day but the SEM system only uses roughly 470 api calls per day so this service should be free.

Login to your system using the default username (admin) and password (admin). Please change the password for security purposes.

Go to the settings page (click your username in the top right hand corner and click settings) on this page you need to setup the email reports and external weather settings.


Main Dashboard of the frontend. It contains both current and previous analysed data (Click on image for full size).

The graphs page has trendlines of several key measured data points over various periods of time (Click on image for full size).



As always if you have any questions please don’t hesitate to ask,



This project was originally published on GitHub ( in July 2015.

From time to time I will republish some of my previous projects with extra information in order to maintain a consistent publishing schedule.

Leave a Reply

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

%d bloggers like this: