Sending Real-Time Sensor Data Through e-Mail

By Abuthahir Tajudeen

12011
Advertisement

This project is based on Raspberry Pi and Python programming, and sends real time sensor data via Gmail. Raspberry Pi is a single-board computer with several features. Connection details of the ultrasonic sensor with Raspberry Pi are shown in Fig. 1.

Pin connections between sensor and Raspberry Pi
Fig. 1: Pin connections between sensor and Raspberry Pi

Hardware includes Raspberry Pi 3, ultrasonic sensor HC-SR04, Internet connection and some hookup wires. The author’s prototype is shown in Fig. 2.

Author’s prototype for Sending Real Time Sensor Data through e-mail
Fig. 2: Author’s prototype

Software

Software required is Python Interpreter. Code is written in Python programming language. Make sure you have an updated version of Python in Raspbian operating system (Jessie) of Raspberry Pi. If not, update it by typing the following commands on the terminal:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install python3

Advertisement

In case you are using an older version of Python, you may need SMTP library. Type the command given below on the terminal to install the library.

$pip install smtplib

Now, write mailer.py code in Python Editor, or open the code (mailer.py) either via the terminal or Python Editor.

After opening the code, make the following changes:

1. In sender field, type your e-mail address.
2. In senpass field, type the password associated with the e-mail ID.
3. In receiver field, type the e-mail ID where you want to receive the email regarding the status of the sensor.

Then, save the changes and run the code. Whenever the sensor detects an object from a distance of 50 cm—you can change this from the code—a message will be sent to the configured e-Mail ID from the sender, Raspberry Pi. This action will be shown on the terminal, as shown in Fig. 3.

 Terminal window
Fig. 3: Terminal window

The e-Mail received on the receiver e-Mail ID is shown in Fig. 4.

Mail received from Raspberry Pi
Fig. 4: Mail received from Raspberry Pi

Select Less Secure Apps option under Gmail settings to access the alerts.

Thus, following the above method, we have successfully created a system which can send real time sensor data via e-Mail.

Download source folder here: Click here


Abuthahir Tajudeen is founder and chief executive officer, LEPoCUBE AssisTech, Tamil Nadu

Advertisement


SHARE YOUR THOUGHTS & COMMENTS

Please enter your comment!
Please enter your name here