Introduction: People Counter
The project was created in order to be used in the PET room of UFES 'computer engineering to control the number of people inside it, in addition to measuring temperature and humidity. So that you can have total control, these numbers are changed and sent to a website, which can be accessed from anywhere.
Step 1: Components
The following items will be used for the project:
- 1 NODEMCU ESP8266;
- 1 DHT11 Humidity and Temperature Sensor;
- 2 Infrared Reflective Obstacle Sensor.
All of these materials can be easily found on the Internet. If the idea is to make this project as fast as possible it is recommended to buy the items on the website Mercado Livre (only if you live in Brazil) since it has safe and fast shipping (the products will arrive at the destination in about 1 or 2 weeks). However, if the project doesn’t need to be done in a hurry, it’s a lot cheaper to buy the items abroad on websites like eBay, AliExpress, etc. But there is no guarantee as to when and if the product will arrive at the destination. Total average purchase cost on Mercado Livre: +/- R$ 56,72 (around 10,58 United States Dollar).
Step 2: Hardware - Setting Up the Circuit
The circuit schematic can be found in the ContadorDePessoas.fzz file below. We used the Fritzing program to create it, and thus understand the connections in the protoboard. Mount it on a protoboard to test and if everything works correctly, make a PCB board for your circuit.
Step 3: Software - Downloading the Code
The codes and libraries used in this project can be downloaded from the file below or from the following link:
Download the Arduino IDE on your computer and add the libraries to upload the code to NodeMCU.
Step 4: Software - Explanation of the Code
For the project, we created 3 different codes.
For the Backend, some consts were used to create the server, with the installation of WebSocket and express. The wss.on function is aware of any connection on that server, if it occurs and the client sends a message, the ws.on ('message') function will be called. This message will be stored in the data variable. In the setInterval function, which is called every 100 ms, it will evaluate whether the new message is the same as the previous one, otherwise, it will send it to all connected clients, using the ws.send function.
Finally, we have the .ino code that controls the nodemcu. For this project, 5 libraries were used, namely:
- DHT.h - To use the temperature and humidity sensor.
- ESP8266WiFi.h - So that it can be possible to have a Wifi communication.
- WebSocketsClient.h - Responsible for communicating with the websocket.
- NTPCliente.h and WifiUdp.h - Responsible for taking the current time and showing when the last update was.
Initially some variables are created to store some important values for the course of the code. Some functions were created to manage these variables. One of them is the webSocketEvent function (WStype_t type, uint8_t * payload, size_t length), dedicated to receiving the value of the variables and sending it to the backend of the application.
And we have the functions void verificaAlteracaoData() and void contaPessoas() that will update the values of temperature, humidity and count of people.
Step 5: Printed Circuit Board (PCB)
If everything has worked out so far, make a PCB board (we usually use EAGLE CAD software to do this) and then solder the components.
Step 6: Project Operation
Watch the video of the final demonstration of the project.
Step 7: Project's License
This work is licensed under the Creative Commons Attribution 4.0 International License.