Project tutorial
IoT: Connecting The RPi, Arduino And The World!

IoT: Connecting The RPi, Arduino And The World! © GPL3+

In this project, we will program a RPi and an Arduino, to work together to capture data from sensors, sending them to the Web.

  • 1 comment
  • 27 respects

Components and supplies

Apps and online services

About this project

This tutorial was one of the winners of INTERNET of THINGS 2016 Contest. Thanks a lot! In this project, we will program a RPi and an Arduino, to work together to capture data from sensors, sending them to the Web.

The functions will be split be split between the two devices:


  • Capture Temperature and Humidity data via an digital sensor (DHT-11)
  • Capture light information (simulating a simple ADC)
  • Communicate with Web, sending all captured data


  • Capture analog data with accuracy

The video bellow, shows data being captured by RPi and sent to website:

This project was part of my tutorial: Mobile Station prototype for Environmental Data Capture ("a Mars Rover emulator") that will be expand here for better understanding. The "Mars Rover" project was also featured on MagPi magazine.

Step 1: Bill of Material

For this project, we will need:

  • Rapsberry Pi2
  • WiFi dongle
  • DHT-11 Temperature and Humidity Sensor
  • Arduino Nano
  • Capacitor
  • Resistors
  • LDR (Light Depend Resistor)

Step 2: Installing the DHT11 sensor at RPi

First, get the Library from Github:

git clone 

Installing the Library:

sudo apt-get update
sudo apt-get install build-essential python-dev python-opensslcd /Home/Pi/Adafruit_Python_DHT
sudo python install 

Test the sensor running the file at monitor. Enter as parameters: 11 (Sensor DHT11) and 4 (GPIO where the sensor is connected):

sudo python /Home/Pi/Adafruit_Python_DHT/examples/ 11 4 
  • The result should be the temperature and humidity read by the sensor.

Step 3: Sending Data to Web

For the basic settings of the DH-11 sensor with the RPi, and sending data to internet, a great help was get from this tutorial:

Plotting DHT11 sensor data at using Raspberry Pi

From what was learned, the important is

  • Setting a Channel at
  • Run the Python Code bellow for tests

Step 4: Adding a "digital" light sensor

The general idea for this step of the project was learned from:

A LDR and a Capacitor was connected to GPIO24. If there is light, the GPIO24 will return HIGH and w/o light “LOW”.

The Python Code used in this test:

Step 5: Adding a anagog Light Intensity sensor

The next step was to get "light intensity data". To add the LDR to RPi the best is to convert the analog signal from the sensor to a digital value using an external ADC (Analog to Digital Converter). The RPi does not have an internal ADC as the Arduino. If you do not have an ADC, a good approximation is to use a capacitor charging/discharging technic. The "Raspberry Pi Cookbook" gives the solution (note that Instead the Potentiometer, a LDR could be used):

import RPi.GPIO as GPIO
import time
a_pin = 25
b_pin = 23
def discharge():
    GPIO.setup(a_pin, GPIO.IN)
    GPIO.setup(b_pin, GPIO.OUT)
    GPIO.output(b_pin, False)
def charge_time():
    GPIO.setup(b_pin, GPIO.IN)
    GPIO.setup(a_pin, GPIO.OUT)
    count = 0
    GPIO.output(a_pin, True)
    while not GPIO.input(b_pin):
        count = count + 1
    return count
def analog_read():
    return charge_time()
while True:

The best is to use the Arduino to capture this kind of info and send it to RPi. The result will be more accurate.

Step 6: Sending all data to the web

The previous Python Code was updated, including the new sensors:

Step 7: Sending an alarm tweet

A simple solution to send alarms, is t send a Tweet directly from the website. In this case the ”React” feature of can be used. Please see the details how to define an React in the video at introduction of this tutorial.

Step 8: Connecting the RPi and the Arduino using Serial Communication

The Arduino used was the NANO that is so powerful as the UNO but on a "small form factor".

For tests purposes, A potentiometer was connected to Arduino analog port A0 and the value transmitted via Serial to the RPi. In the test, RPi will be reading a Keyboard (connect to it or thru VNC) and depending on the command, the Arduino LED will be toggle "ON/OFF". Below the Arduino and Python code used on the tests:

Step 9: Sending Arduino data to the Web

Once the Arduino is connected with RPi, additional data captured by Arduino can also be sent to the Web, together with other data captured by the DH11 and LDR.

The Python code used to send data to the Website was changed to also included the data captured by Arduino (potentiometer value).

Step 10: That's all folks

As always, I hope this project can help others to find their way in the exciting world of electronics and IoT!

The updated code for this project can be found at GITHUB:

For more projects, please visit my blog:

Saludos from the south of the world!

Thank you







Similar projects you might like

IoT Made Easy w/ UNO, ESP-01, ThingSpeak & MIT App Inventor

Project tutorial by MJRoBot

  • 80 respects

The "Mars Rover" Emulator

Project tutorial by MJRoBot

  • 57 respects

How To Make An Mini IOT Weather Station

Project tutorial by Austin Detzel

  • 18 respects

Securely Connecting an Arduino NB 1500 to Azure IoT Hub

Project tutorial by Arduino_Genuino

  • 26 respects

OH HAI! on Windows 10 IoT Core

Project in progress by BuddyC

  • 51 respects
Add projectSign up / Login