Tuesday 27 March 2018

Switch a light on and off over WiFi using a Raspberry Pi

One night I walked into the PC room and thought to myself, this room seems really dark when you walk in for the first time. Would it not be cool if I can just switch on the light from my phone as I'm walking into the room, or even when I walk into the house?

If you thought that idea would be cool, then you will enjoy the below video of my little light project.





What are all those things on the table?


  • Mobile phone
  • Raspberry Pi 3
  • Relay board
  • Light bulb
  • Light bulb socket
  • Wires

How does it work?


The raspberry pi and the mobile phone are both connected to a WiFi hotspot.

A relay board is connected to the raspberry pi's GPIO and the electrical wiring is connected. (Please DO NOT attempt this with real electricity if you don't know what you're doing)

I wrote a little PHP website running on the Raspberry Pi which basically consists of 2 buttons and a status label.

Whenever the "LIGHT ON" or "LIGHT OFF" button is pressed, it executes a Python script on the raspberry pi, which sends a signal to the relay board that either opens or closes the circuit which causes the light to go on or off.

Before every request, The voltage of the output pin is checked and the status bar is updated accordingly.

I hope you enjoyed this post, I will add the code for the PHP website and Python script in the next couple of days.


No comments:

Post a Comment