Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

Web controlled Home Automation- (Part 11/12)

By Prabakaran P.M

This article focus on the techniques in making a Raspberry Pi as a web server which controls the home appliances. It includes Graphical user interface in web server side and electronic part which is used to control the electrical system.

Here is a simple example of four LEDs controlled by web interface is used by utilizing apache web server with PHP and JAVA codings for GUI and electronic part is handled by WiringPI library.

Web Controlled Home Automation System using Raspberry pi Prototype

Web controlled LED connection diagram


 

Prerequisites & Equipment:

You are going to need the following:

  1. A Raspberry Pi Model B or greater.

  2. A USB WiFi Adapter (Edimax – Wireless 802.11b/g/n nano USB adapter is used here).

  3. An SD Card flashed with the Raspbian OS (Here is a guide if you need)

  4. Access to the Raspberry either via a keyboard and a monitor or remotely.

 

Installing Wiring Pi:

The Wiring Pi project is used here to switch the GPIO pins high and low. Run the following commands for downloading Wiring Pi and install.

sudo apt-get install git-core

git clone git://git.drogon.net/wiringPi

cd wiringPi

./build

Download wiringPi on Raspberry Pi

Fig. 2: Download Wiring Pi On Raspberry Pi

 

Installing Wiring Pi on Raspberry Pi

Fig. 3: Installing Wiring Pi On Raspberry Pi

Let’s discuss about using the WiringPi library to turn on and off the first LED (Wiring pin 0). First need to set the pin as an output. Use the “gpio mode 0 out” command to do so. “0” is the wiring pin number and “out” is for output. Now you can use the “gpio write 0 1” command to turn on your LED. “0” is again the pin number and “1” is the status (1 for ON and 0 for OFF). If everything’s fine you should see your LED shining. By using the “gpio write 0 0” command you can turn it off.

If you want to use the actual pin number (GPIO-17) instead of the Wiring Pi number (0 is corresponding to GPIO-17), use the -g flag in your command. Ex: “gpio -g write 17 1” instead of “gpio write 0 1”.

The “gpio read” can be used to read the PIN status. It allows you to be sure of the pin’s status when you can’t see the Output. Using it is as simple as before, just type “gpio read 0” where “0” is the wiring pin number. The command returns the pin’s status (again 1 for ON and 0 for OFF).

Starting Apache web server:

Installing and Configuring of Apache web server is well discussed in previous articles. To start the server is simple as just copy the server files to the apache folder. Download the web server files and extract it to the home folder of Raspberry Pi using Samba webserver are FTP clients.

Copy these files to the apache web server folder which is /var/www and restart the web server. Now our website is alive you can navigate to the website by entering the IP address of the Raspberry Pi.

Controlling the LEDs with PHP:

We now have our apache web server and a Wiring Pi library. The PHP stands for “PHP: Hypertext Preprocessor” which will act as a bridge between these, and it’s a server side scripting language. It means that the PHP code is executed once (each time the page is requested) by the server and cannot be seen by the client. Executing system commands with a PHP code can be done with two different functions: exec (for execute) and system. Firstly, the “system” function. It takes two parameters: “system ( string $command, int $return_var )”.with this function you can execute “gpio mode 0 out” or “gpio write 0 1” commands.

Example:

<?php

system ( “gpio mode 0 out” );

system ( “gpio write 0 1” );

?>

Then, the “exec” function. This function is making exactly the same work than “system” but it reads and stores what the command printed. It takes three parameters: “exec ( string $command, array $output, int $return_var )”, again $command and $return_var are the same parameters and the only difference is the $output array. Thus, you can use this function if you need what the command prints like with the “gpio read 0” command.

Example:

<?php

exec ( “gpio read 0”, $status );

print_r ( $status );

?>

Building Graphical Interface:

We can now control our Raspberry Pi with simple PHP scripts, but the interaction with the user is pending. This can be done by the combination of Java script and the HTML. Each picture/bulb is corresponding to its LED, if you click on one of these, the LED corresponding will be turned on/off and the picture also will be changed accordingly. The page’s skeleton will be made with HTML, the server interactions with PHP and at finally JavaScript to manage interactions between the user and page’s animation. JavaScript is a client side language which is executed continuously by our browser. That’s why we can change the page’s look without reloading it. We first need an “index.php” file (extension is .php and not .html because we will use PHP code, it commands the browser that there is PHP to execute before sending the page). This main page contains 4 buttons with Bulb Picture. These buttons are first generated with a “exec ( “gpio read “.$i, $output );” and a for loop to replicate. To detect the user clicking on any one of these buttons, Java script is used which is in a separate file called “script.js” even though it’s still included in index.php. The script is to add an event listener to all of the four buttons and when one of these is pressed, it uses a function which is calling for gpio.php, receiving the answer then returning to the JavaScript which changes the button to ON or to OFF. You can download the full codes directly here.

Building Raspberry Pi Graphical Interface

Fig. 4: Building Raspberry Pi Graphical Interface

Project Source Code

###

//Program to 

###

 


Project Source Code

###

//Program to 

###

 


Circuit Diagrams

Circuit-Diagram-Web-controlled-Home-Automation

Project Components

  • Arduino Pro Mini
  • LED
  • Relay Switch
  • Transistor BC547

Project Video


Filed Under: Raspberry pi

 

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Introduction to Brain Waves & its Types (Part 1/13)
  • Understanding NeuroSky EEG Chip in Detail (Part 2/13)
  • Performing Experiments with Brainwaves (Part 3/13)
  • Amplification of EEG Signal and Interfacing with Arduino (Part 4/13)
  • Controlling Led brightness using Meditation and attention level (Part 5/13)
  • Control Motor’s Speed using Meditation and Attention Level of Brain (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • What are the battery-selection criteria for low-power design?
  • Key factors to optimize power consumption in an embedded device
  • EdgeLock A5000 Secure Authenticator
  • How to interface a DS18B20 temperature sensor with MicroPython’s Onewire driver
  • Introduction to Brain Waves & its Types (Part 1/13)

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Slope compensation ramp calculation for UCC38084
  • Parts storage / inventory best practices and organization
  • Unusual gap shape of ETD59 ferrite core?
  • Vco cadencd
  • WH-LTE-7S1 GSM module and SIM card problem

RSS Electro-Tech-Online.com Discussions

  • surge arresters
  • NOR gate oscillator in LTspice not working
  • HV Diodes
  • intro to PI
  • Very logical explanation on low calue C3
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering