IoT: How to Remote Control Appliances Using Raspberry Pi

by Noor Ali  July 14, 2016

Hey there buddies! I hope you are doing well. Today I will be taking things a little bit further than what we did previously. If you guys haven’t read the previous blog yet, click here and go through it. It will give you a broad idea about how to create a two-way communication between your pi-node and the web app.

Last time, the project was very simple in which a simple channel for Raspberry Pi was created that submitted  values to the cloud app hosted on Cloudways. These values could come from any source, whether a sensor or the CPU itself. For the purpose of the app, I pushed CPU usage values to the cloud app.

How-to-Remote-Control-Appliances-Using-Raspberry-Pi-Banner

Today, I will be doing something similar but the flow of data will be reversed. I will demonstrate how to send instructions to the Raspberry Pi from the Cloudways-hosted app. To keep things simple, I will show how to light up a simple LED. Although the demonstration is very simple, it is  enough to create a foundation of a system that could operate (switch on and off) a host of devices. This allows you to implement a smart system of remote-controlling appliances.

So let’s get started. There are some prerequisites, so  just grab your things and get ready.

Requirements  

  • Raspberry Pi B+ (you can use any version. Just be sure about pin allocation)
  • Simple PHP Cloudways App. If you do not have one, click here to launch one!
  • Jumper Wires
  • Breadboard
  • Red, Blue, and Green LEDs

What Is Happening on the Web Page and Raspberry Pi

On the web page, I will use a simple form with 6 buttons to control LEDs connected to the Raspberry Pi. I will make a REST API in our RPi made on Python-Flask. Then, I will call the API routes to perform certain actions. With every route I have appended a GPIO action, which will turn the LEDs on and off. Sounds too much?  Just hold on and I will explain.

Before starting to code, let’s check some of the Raspberry Pi settings.

R-Pi Configuration  

1- The Raspberry Pi should be accessible remotely via an IP. If not, there might be several issues that could be easily fixed. Checkout this link

2- Flask framework must be installed on the Raspberry Pi. Check this documentation for installation

Python Program on Raspberry Pi

  • – SSH into your Raspberry Pi with your credentials.
  • – Make a new directory and move into it.

Running the Python Program

– Save and Exit VIM

– Run your program using the following command

Circuit Construction

The circuit consists of the Pi, LEDs, and a resistor to limit the current that can flow through the circuit.

All the ground are connected to the (GND) pin of the Rpi that basically acts like the negative or 0 volts of a battery. On the other hand, he GPIO Pins 17 , 18 and 19 act like the positive terminal of a battery. When the signal is HIGH, the LED will light up and when the signal is LOW, the LED will stop glowing.

Now take a look at the circuit diagram below:

rpi

Code for Cloudways App

You have to change your R-Pi IP-address in the buttons’ actions. This will give a layout of buttons which you can use to turn your circuitry on and off.

Testing

Now visit the app. You will see something like this:

rpi remote control

Click on any action and you will see the result on the Raspberry Pi.

This is it! A tiny setup which enables you to control appliances from a remote app.

Start Creating Web Apps on Managed Cloud Servers Now!

Easy Web App Deployment for Agencies, Developers and E-Commerce Industry

About Noor Ali

Noor Ali is an Associate Software Engineer at Cloudways. He loves to solve technical problems through programming and mathematics.

Stay Connected:

You Might Also Like...