Remote GPIO Management on Raspberry Pi via Web Interface

Webpage-Controlled GPIO Activation for Home Automation Projects

1. Introduction

This Raspberry Pi project showcases its role as an IoT device. It enables the manipulation of LED states (ON/OFF) via a webpage accessible from any device connected to the same network as the Raspberry Pi. The project’s principles serve as a foundation for diverse home automation endeavors.

2. Demonstration

3. Procedure

Follow these steps:

1. Set up the circuit connections according to the circuit schematics.

2. On the Raspberry Pi, create a new directory named ‘Web Server’ (or any name you prefer). Inside this directory, create another folder called ‘Templates’. Ensure that the folder name is ‘Templates’ as it is necessary for the webpage to function correctly during execution.

3. Save the Python file within the ‘Web Server’ folder.

4. Save the HTML file inside the ‘Templates’ folder.

5. Within the Python program, specify the IP address assigned to your Raspberry Pi. To find this address, open the command prompt and type ‘ifconfig’, then press enter. A list of connections will appear, showing the IP address under ‘lan’ (for LAN connection) or ‘wlan’ (for WiFi connection).

6. Start the Python program on the Raspberry Pi. Then, enter the IP address in your web browser to access the web page.



from flask import Flask
from flask import render_template
import RPi.GPIO as rpi
import time

app= Flask(__name__)

led1,led2,led3= 3,5,7

rpi.setup(led1, rpi.OUT)
rpi.setup(led2, rpi.OUT)
rpi.setup(led3, rpi.OUT)
rpi.output(led1, 0)
rpi.output(led2, 0)
rpi.output(led3, 0)

def index():
    return render_template('webpage.html')

def led1on():
    return render_template('webpage.html')

def led1off():
    return render_template('webpage.html')

def led2on():
    return render_template('webpage.html')

def led2off():
    return render_template('webpage.html')

def led3on():
    return render_template('webpage.html')

def led3off():
    return render_template('webpage.html')

if __name__=="__main__":
    print("Start"), host='')

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
Scroll to Top