Smart Home – The Idea

The idea is to monitor via several sensors the status of the house and to have some kind of control. We will also have a gesture sensor attached to a relay, we can then swipe to turn on and of the lights. The sensors will post their data to a MySQL server running on a raspberry pi 3.


Per room I have decided:

  • 1 x ESP8266 NodeMcu (the microcontroller with WiFi) EUR 3,15 China.
  • 1 x relay (the relay allows you to control house mains power turning it on and of) EUR 1,00 China.
  • 1 x DHT22 (the DHT22 allows monitoring of temperature and humidity) EUR 2,89 China.
  • 1 x Door Or Window Contact Magnetic Reed Switch (apply to windows, detects if windows are open or closed) EUR 2,48.
  • 1 x PIR Motion Human Sensor (detects movement, my idea is to position near the door not to monitor the room itself) EUR 4,65.
  • 1 x Apds-9960 (this is a gesture sensor, we will use this to turn the relay on and off using hand gestures) EUR 2,01.

Total price = 16.18 (price is estimated just made random eBay searches, no doubt could get cheaper by buying packs of 5 etc. I estimate Euro 12.50 per room).

The main challenge I have had so far is controlling how the data is inserted into the MySQL database. I am learning as I am going and thus may not be using the best practices but my aim is to “get it to work”.

Even if I have to rewrite all of the code for security/reliability or even debugging that is fine, but for now, I will be just getting the system linked together and working.

The second challenge I have is PHP iv never used PHP so scrapping the internet of database control has been a real mission.

So how far have I got?

I have added the gesture sensor and relay to the NodeMcu, I am able to control the relay via hand movement.

I have managed to get the NodeMcu to post the status either “light on” and Light off” to a MySQL database, I have done this via posting the parameters 0 or 1 to a PHP page. The PHP page then updates the database.

Geture On -> Relay turns on -> URL post to PHP Page -> PHP Page updates database.

I have also created a website that can show the current status 0 = off 1 = on, it got a little complicated here. I needed a way to change the status via a webpage. I knew the NodeMcu will accept parameters as well so after a little googling I found Curl was the best approach.

Website posts 1 or 0 to Curl page -> Curl creates the URL post to NodeMcu -> NodeMcu turns light on or off -> NodeMcu then posts new status back to MySQL.

I agree to accept feedback, but please provide feedback on your ideas or even how I can make this better. Any comments like “left open to MySQL injection” etc without how to actually fix it, is not feedback and such will not be approved for commenting