Back in 2016, I prototyped an outdoor passive infra-red (PIR) sensor using bare ESP8266 WiFi boards. They worked OK, although they were a bit kludgy and I never really was that happy with the results. Bare ESP8266 boards were difficult to use back then. Cramming wall warts into projects, wasn’t that much fun either, especially when trying to fit everything into a compact project case. My homegrown client/server network communication schemes certainly weren’t standard or portable.
Time marches on and much has changed in the physical computing world.
Today, we’ll take a first look at the prototype for my new and improved PIR yard sensor. We’ll summarize the project, explore the parts and discuss next steps.
The All Seeing Eye
As you’d expect, we have a monitored home alarm system along with locks on all our doors to keep bad guys out. Wouldn’t it be helpful to know that someone was approaching the front door or had just scaled the back yard fence at 3 a.m? We’d have a little extra time to throw a nice welcoming party.
Not only that, if we could record “incursions” onto the property, particularly when no one is home or during the wee hours, we could maybe see patterns of suspicious behavior and be able to take appropriate preventative action.
I recently picked up a few late-model NodeMCU WiFi boards from one of the big Internet vendors. That same shipment netted me several miniature 5-volt power supply boards. Over the past few years, I’ve also studied the fundamentals of MQTT, which is a simple and standard way to transport data between machines that are easily accessed in firmware and applications using libraries.
Now with updated electronics, a better understanding of how devices talk to each other and readily available, easy-to-use parts perhaps my high-tech property surveillance system will become a reality.
Simplify Your Prototype
The project only has three main components. The NodeMCU, the PIR sensor and the power supply. At some point, we’ll add a relay to switch a floodlight on and off.
The NodeMCU is basically a bare ESP8266 model 12E module, with a 3.3-volt regulator and USB interface circuitry, all rolled up in an easy to use 1-inch x 2-inch printed circuit board package. Think of the ESP8266 as an Arduino with built-in WiFi. Coding is seamless using any current Arduino IDE, although the board type has to be changed to “NodeMCU 1.0 (ESP-12E module)” before uploading any firmware. The general purpose input/output (GPIO) pins work with 3.3 or 5-volt logic without fuss. It needs a stable 5.0 volt supply from either the USB cable or the voltage input pin. I’ve frequently used a cellphone wall wart for this job.
I have a love/hate relationship with the little 5-volt cellphone wall warts. They work great for prototyping quick Arduino or a Raspberry Pi. Projects are easily powered using a standard USB-to-micro-USB cable.
On the other hand, using a wall wart in a finished project or one that will be housed in a weather resistant case is kludgy. You have to plug them into an outlet, power strip or extension cord somewhere. They can usually only manage to pump out between 1.0 and 1.5 Amps of current. That’s marginal for a Raspberry Pi 3. ESP8266 projects typically need about 700 mA when the WiFi radio transmits. Hook in a few LEDs and such and we can easily run low on current under heavy load, forcing a reset or other errant operation.
Fortunately, there is a wide selection of miniature 5-volt power supplies from the various DIY parts outlets. I picked up a three-pack of 5-volt, 2.0 Amp boards from Banggood for under $10. They’ll take AC power input from 85 to 264 volts. They’ll reliably supply 5.0 volts at 2.0 Amps continuous and up to 3.0 Amps surge current. These power supplies are perfectly suited to powering the NodeMCU board.
For this project, I simply wired the output of the power supply to the Vin and Ground pins on the NodeMCU. I used a common everyday lamp cord and plug on the AC power input side. When the time comes to put the yard sensor in its permanent outdoor enclosure, I’ll simply cut the plug off and wire the mini-system right into the backyard light circuit. Since the sensor will run 24/7, I’ll just leave the wall switch on all the time.
The PIR sensor module was purchased from Sparkfun quite a while ago. It is of the open collector variety and registers a LOW (0) value when detecting an object and a HIGH (1) value when it sees nothing. I routed the sensor alarm wire to GPIO pin 10 on the NodeMCU. The negative sensor pin is wired to ground and the positive sensor pin is wired to +5 volts.
I’ll add MQTT into the Arduino code, soon. MQTT is a mature protocol for transferring data between machines. It allows one-to-many and many-to-one messages. It is lightweight and is easily integrated using libraries into both the NodeMCU firmware and server data analysis applications. You just add a reference to the library at the top of the code, then call the appropriate function down in the main program loop. I’ve used it successfully in a few other projects and it works well. We’ll review the code in an upcoming story.