Introduction: Wemos DHT11 PIR Sensor With Relay
These are instructions on how to wire and program a Wemos mini D1 so it can Read Temperature from a DHT11 and you can manipulate the information through the Blynk app via WIFI. Using the Blynk app will allow use to graphically display values ( Humidity and or Temperature) and if you wish you can set events through the Blynk app , making it more convenient since we can use an app instead of re-writing coded in the Arduino IDE every time we want to modify or add an event( check out www.blynk.cc) Second will be "hard code", I call it like that because if you want to modify the code you will have to manual upload it through the compiler as appose to using the Blynk app, the code is for the PIR sensor and relay. I will also include my STL file for my custom enclosure if you wish to print it. I do this as a hobby and I am fairly new to this. If there are any suggestion where i can improve this, by all mean let me know.
The Wemos mini D1 will be able to read Temperature and humidity and detect motion through the PIR. What you want to do with that is up to you. The Blynk app gives you many options on how to use this configuration.My code is set up to have the relay on for 30 minutes. You are more than welcome to change that if you would like through the code.
- Alternatively an option could be Read the Temperature from a room and with that given value , through the Blynk app create even with IF Statements. For example , I can read the temperature and set it to , IF room temperature is above THIS temp (lets set it to 90 deg), Then open relay ; AC can be plugged to relay , therefore when the room temperature is above a given temp then the AC will turn on. Else have the relay off. BUT you will have to re-code it and make the pin the relay is connected to virtual, and send it to the blynk appafter that you can manipulate the relay through the app.
This is how I connected my Wemos D1. I learned the hard way that you cannot connect anything to GPIO0, GPIO2 and/or GPIO15 otherwise it would be unable to reset the board to programming-mode and it would not let me upload my sketch while anything is connected to any of those pins. I Changed my PIR pin from the D4(GPIO2) to D1.
This is my custom enclosure that fit all my components well. It has a mount for the wall outlet and a grommet hole on the backside for the cables. If you don't have a 3D printer you can pick up 1-Gang outlet box from HomeDepot, just make sure you components fit. In the future i will redo the enclosure and add a spot for a female micro USB so I wont have to remove the Wemos from its enclosure any time I wish to upload a sketch to it..
Attached Is the code for the Wemods D1. Open in Arduino IDE change you WIFI network , Password , Blynk Auth code and then upload sketch.