Introduction: UCL-IIOT - Data Loggings on Raspberry Pi

About: Obayda Haj Hamoud Student at UCL Odense

This instructable was created by Obayda Haj Hamoud and Sidse Henriksen for a school project.

The main idea is collecting data from alight sensor, logging the data to a database wirelessly on a raspberry pi and monitor that data through a dashboard created using Node red .

Step 1: Building the Circuit



● NodeMcu

● Raspberry pi

● Photocell light sensor

● Led

● Resistor

● Jumber cables


● Node Red

● Mosquitto server

● Mysql data base (phpmyadmin)

● Arduino IDE

Step 2: Arduino Code

The following code is used to call the mosquitto broker installed on raspberry pi and get the published data.

'The final arduino file is inserted in the end of this instrutable'

void callback(String topic, byte* message, unsigned int length) { 
 Serial.print("Message arrived on topic: ");
  Serial.print(". Message: ");
  String messageLight;

Step 3: Installing Software on Raspberry Pi

1. Installing MQTT Broker on Raspberry pi.

- Open a Terminal and insert the following commands line by line:


 sudo apt-key add mosquitto-repo.gpg.key
cd /etc/apt/sources.list.d/

- For jessie version

sudo wget

in case you have wheezy version on Raspberry pi, insert the
following command instead

sudo wget

- Updating the source list

apt-get update

- installing the broker

apt-get install mosquito 

apt-get install mosquitto-clients

2. Installing MYSQL data base for the server

- Installing apache server

sudo apt install apache2

- Installing PHP

sudo apt install php php-mbstring

- Confirming PHP is working:

- delete the file “index.html” in the directory “/var/www/html”. by inserting the command:

sudo rm /var/www/html/index.html

- Create index.php file

echo "<?php phpinfo ();?>"> /var/www/html/index.php

- Install MYSQL

sudo apt install mysql-server php-mysql

- Verify that MySQL is working correctly. First create a MYSQL user and password.

sudo mysql -u root -p

- Replace ‘username’ and ‘password’ with your chosen username and password

GRANT ALL PRIVILEGES ON mydb.* TO 'username'@'localhost' IDENTIFIED BY 'password';

- Installing PHPMyAdmin

sudo apt install phpMyAdmin

- Check that PHPMyAdmin is working properly by inserting the following line in your web browser:

- If you still get an error, it could be because PHPMyAdmin has moved to another directory. In this case, try the command and check again.

sudo ln -s /usr/share/phpmyadmin/var/www/html/phpMyAdmin

Step 4: Node Red

Mosquito mqtt node has been used to read data from the light

sensor convert it to integer with a Change node and then create a gauge and set the data to database reading format which will be inserted into database (mydb) afterwards with SQL Insert function .

After the data has been inserted to mydb, it will be used to create a chart to be monitored from the dashboard.

Max form has been created to specify the max amount of readings should be shown on the chart form starting from the first reading to max inserted by the user interface.

Step 5:

Step 6:

Final files