HackerBox 0071: Ranger

by HackerBoxes in Circuits > Arduino

5972 Views, 12 Favorites, 0 Comments

HackerBox 0071: Ranger

F3QQU8VKUB8IQAT.png

With HackerBox 0071, we are exploring various electronic techniques to sense the presence of a physical object (proximity detection), determine how far away the object is (ranging or locating), or analyze the motion or speed of the object. We will configure the Arduino development environment and various libraries to work with ATmega328P microcontroller boards. Program flexible strips of addressable RGB LEDs. Produce colorful LED light shows responsive to sound using microphone sensors. Assemble and program a Doppler radar speed sensor system with operational amplifier interface circuitry. Wire and program laser distance ranging modules, thermal PIR motion sensors, Doppler radar motion sensors, and vibration detectors.

HackerBoxes is the monthly subscription box for enthusiasts of electronics and computer technology - Hardware Hackers - The Dreamers of Dreams.

There is a wealth of information for current and prospective members in the HackerBoxes FAQ. Almost all of the non-technical support emails that we receive are already answered there, so we'd really appreciate it if you can take a few minutes to read the FAQ.

Supplies

This Instructable contains information for getting started with HackerBox 0071. The full box contents are listed on the product page for HackerBox 0071 where the box is also available for purchase while supplies last. If you would like to automatically receive a HackerBox like this right in your mailbox each month with a $15 discount, you can subscribe at HackerBoxes.com and join the revolution!

A soldering iron, solder, and basic soldering tools are generally needed to work on the monthly HackerBox. A computer for running software tools is also required. Have a look at the HackerBox Deluxe Starter Workshop for a set of basic tools and a wide array of introductory activities and experiments.

Most importantly, you will need a sense of adventure, hacker spirit, patience, and curiosity. Building and experimenting with electronics, while very rewarding, can be tricky, challenging, and even frustrating at times. The goal is progress, not perfection. When you persist and enjoy the adventure, a great deal of satisfaction can be derived from this hobby. Take each step slowly, mind the details, and don't be afraid to ask for help.

Detection, Ranging, and Motion

intro.png

Various electronic techniques can be used to sense the presence of a physical object (proximity detection), determine how far away the object is (ranging or locating), or analyze the motion or speed of the object.

These techniques can be roughly broken down into three different approaches...

First, we can sense something inherent about the object. For example, detecting light or heat given off by the object itself.

Second, we can sense ambient signals reflected (or otherwise interfered) by the object. For example, human vision relies upon ambient light (from the sun, fire, or electric lights) reflecting off of an object and then falling upon the retina of an eyeball.

Third, we can emit a signal to interrogate the object. The sensing apparatus can generate light, sound, or radio waves to project onto the object and then analyze whatever is reflected back to the sensing apparatus. Radar, sonar, and lidar generally use this approach.

Their Crime Is Curiosity

Trash Files.png

"It's in the place where I put that thing that time..."

Listen: Full Official Soundtrack

Watch: YouTube (free with ads)

ATmega328P Arduino Nano

Nano.png


The Arduino Nano is possibly the most common microcontroller (MCU) modules currently in use. The Arduino Nano is a surface-mount, breadboard-friendly, miniaturized Arduino board with integrated USB. It is amazingly full-featured and easy to hack. The included variant is based on the ATmega328P MCU operating on 5V at 16Mhz. In includes an on-board MiniUSB port connected to a CH340 USB/Serial bridge chip. Detailed information on the CH340 (and drivers, if needed) can be found here.

Leave the pins unsoldered for now. The included Arduino Nano board comes with header pins, but they are not soldered to the module. Perform these initial tests on the Arduino Nano module prior to soldering on the header pins.

When you first plug the Arduino Nano into a USB port of your computer, the red power light should come on and shortly after that, another red LED should start to blink slowly. This happens because the Nano is pre-loaded with the BLINK program, which is running on the brand new Arduino Nano.

SOFTWARE: If you do not yet have the Arduino IDE installed, you can download it from Arduino.cc

Plug the Nano into a MiniUSB cable and the other end of the cable into a USB port on the computer. Launch the Arduino IDE software. Select "Arduino Nano" in the IDE under tools>board and "ATmega328P" under tools>processor. Select the appropriate USB port under tools>port.

Finally, load up a piece of example code:

File->Examples->Basics->Blink

Blink is actually the code that was preloaded onto the Nano and should be running right now to slowly blink the blue LED. Accordingly, if we load this example code, nothing will change. Instead, let's modify the code a little bit.

Looking closely, you can see that the program turns the LED on, waits 1000 milliseconds (one second), turns the LED off, waits another second, and then does it all again - forever.

Modify the code by changing both of the "delay(1000)" statements to "delay(100)". This modification will cause the LED to blink ten times faster, right?

Let's load the modified code into the Nano by clicking the UPLOAD button (the arrow icon) just above your modified code. Watch below the code for the status info: "compiling" and then "uploading". Eventually, the IDE should indicate "Uploading Complete" and your LED should be blinking faster.

If so, congratulations! You have just hacked your first piece of embedded code.

Once your fast-blink version is loaded and running, why not see if you can you change the code again to cause the LED to blink fast twice and then wait a couple of seconds before repeating? Give it a try! How about some other patterns? Once you succeed at visualizing a desired outcome, coding it, and observing it to work as planned, you have taken an enormous step toward becoming a competent hardware hacker.

Now that you have confirmed operation of the Nano module, go ahead and solder the header pins onto it. Note that the six pin (2x3 pin) header for the end of the board is usually not needed if you want to just leave it off. The process of testing out an MCU module by downloading some simple test code, modifying, and downloading again is a best practice whenever using a new, or different type of, MCU module.

If you would like additional introductory information for working in the Arduino ecosystem, we suggest checking out the Guide for the HackerBoxes Starter Workshop, which includes several examples and a link to a PDF Arduino Textbook.


Addressable RGB LEDs

LED.png

Each strip of addressable RGB LEDs is nominally 100 pixels in length and can be cut and separated between any two pixels. Note that the strips are packaged by approximate length and not by exact pixel count, so there may be +/- 1 or 2 pixels in each strip.

These flexible RGB LED strips are an easy way to add complex lighting effects to any project. Each LED has an integrated driver that allows you to control the color and brightness of each LED independently. The combined LED/driver IC on these strips is the extremely compact WS2812B (datasheet). If you look into a WS2812 "pixel" with a magnifier, you can actually see the integrated driver with bonding wires connecting it to tiny internal green, red, and blue LEDs.

The FastLED library is a powerful option to control the chain of WS2812Bs LEDs from the Arduino Nano.  The library includes an example sketch DemoReel100 which shows off some very cool animations.

One end of the LED strip will have DIN (data din) and one will have DO (data out). Be sure to work on the DIN (input) end of the strip while connecting to the Arduino Nano. Wire leads can be soldered directly to the three pads of the strip. Alternatively, set of three male header pins can be soldered against the pads to support connecting to a female DuPont wire or plugging into a breadboard. (If you're looking for some headers, the GY-VL53L0X Laser Ranging module sometimes includes a few extra header pins. Also, the six pin header from the end of the Arduino Nano is usually not needed.)

Wiring:

  • LED +5V to Nano VIN
  • LED DIN to Nano D5
  • LED GND to Nano GND

Library:

  • In the Arduino IDE, select Tools > Manage Libraries...
  • Select and install the FastLED Library

Sketch:

  • Load up File > Examples > FastLED > DemoReel100
  • Change necessary definitions in sketch
  • #define DATA_PIN   5
  • #define LED_TYPE   WS2812B
  • #define NUM_LEDS   100
  • #define BRIGHTNESS   30
  • Upload sketch to the Nano



PIR Motion Sensing With HC-SR505 Module

PIR.png

The HC-SR505 module features a passive infrared sensor (PIR sensor). PIR sensors are electronic sensors that measure infrared (IR) light radiating from objects in the sensor's field of view. PIR sensors most often used as motion detectors in security alarms or automatic lighting applications.

PIR sensors work entirely by detecting infrared radiation (radiant heat) emitted by or reflected from objects. They detect changes in the amount of infrared radiation arriving at the sensor, which varies depending on the temperature and surface characteristics of the objects in front of the sensor. When an object, such as a person, passes in front of the background, such as a wall, the temperature at that point in the sensor's field of view will rise from room temperature to body temperature, and then back again. The sensor converts the resulting change in the incoming infrared radiation into a change in the output voltage, and this triggers the detection event. (Wikipedia)

The HC-SR505 PIR motion sensor module is simple to wire up, only having three pins. It can be wired to 5V, GND, and one IO input pin of a microcontroller, such as the Arduino Nano.

This tutorial includes specification details of the HC-SR505 Module, information on how to wire it up, and an example Arduino sketch.

When the motion detection is triggered, the signal pin goes high. It will then stay high for several seconds before finally clearing itself automatically.

Try the example code from the link above. Note that the output is printed to the serial monitor. If you wish, modify the example to instead change the color or state of the the LED strip. Perhaps even display a "countdown to clear" for the several seconds that the PIR signal is high by decreasing the number of illuminated LEDs.

Proximity Sensing With RCWL-0516 Doppler Radar Module

Radar Switch.png

The RCWL-0516 is a proximity sensor that uses doppler radar. Its usage and output signal are similar to the PIR motion sensor, but instead of sensing heat (infrared radiation), the RCWL-0516 uses radio waves around 3GHz which it both transmits and receives.

When connecting the RCWL-0516, note that the 3V3 pin is an output from the module. Leave it disconnected. Do not put 3.3V into it. It is an output.

Connect three pins: GND, VIN (for 5V input), and OUT connects to an MCU I/O pin.

The OUT signal can be treated the same as the output signal from a PIR sensor. It will output a logic-high signal for a few seconds whenever there is an object detected by motion.

The RCWL-0516 module is equipped with a RCWL-9196 chip and leverages doppler microwave induction technology. The RF section consists of a high-speed NPN transistor Q1, which forms a Colpitts oscillator. The antenna is a trace on the PCB. The transistor Q1 also acts as a mixer that combines the transmitted and received signal and outputs the difference. The difference output is filtered by C9 and R8, which form a low pass filter. That signal is then amplified by the IC chip.

This page (and associated video) reviews the doppler effect with examples of using the RCWL-0516.

This repository has theory of operation, technical details, and modification notes for the RCWL-0516.


Vibration Detection With SW-420 Sensor Module

Vibration Sensor.png

The SW-420 module is a cost-effective vibration sensor module that can identify any object or motion capable of generating mechanical vibration of the sensor.

The SW-420 module is built around an SW-420 vibration switch. The onboard 10K potentiometer can be used to adjust the sensitivity of the LM393 comparator, which produces a smooth digital output. The LM393 comparator uses a preset to sense the vibrations in the surroundings and maintains a state. The module outputs a logic high if vibrations are detected. Otherwise the module outputs the default logic low signal. 

This tutorial provides details of operation and use of the SW-420 module as well as an example Arduino sketch. The example sketch uses an external LED on I/O pin 13. Pin 13 on the Arduino Nano is wired to the onboard LED, so there is no need to wire up an external LED. The sketch will use the onboard LED as is.

Sound Responsive Lights With KY-037 Microphone Module

AudioLED.png

Another mechanism for detecting vibrations is using a microphone. The KY-037 module consists of a capacitive microphone and an amplifier circuit. The microphone is useful for picking up loud sounds and heavy vibrations but it is not sensitive enough for capturing the subtle sounds of music or the human voice. Coarsely detecting the louder portions of an audio signal however is perfect for making a sound response switch or lighting effect.

A particularly colorful lighting effect using the Addressable RGB LED Strip is pretty easy to achieve using six jumper wires and leveraging the FastLED library that we've already installed.

Connect the KY-037 microphone module to the Arduino Nano:

  • KY-037 A0 to Nano A0
  • KY-037 G to Nano GND
  • KY-037 + to Nano 5V

Connect the Addressable RGB LED Strip to the Arduino Nano:

  • LED +5V to Nano VIN
  • LED DIN to Nano D5
  • LED GND to Nano GND

Grab this sketch, change NUM_LEDS to 100, and let it rip.

The microphone needs to be fairly close to whatever audio speaker is sourcing the sound. The potentiometer on the KY-037 module can be used to adjust the sensitivity thereby increasing or decreasing the responsiveness of the LED strip to the sounds.

Laser Ranging With GY-VL53L0X Module

Laser Ranger.png

The VL53L0X from ST Microelectronics (datasheet) is a time-of-flight ranging system integrated into a compact module. The VL53L0X features a 940 nm Vertical Cavity Surface-Emitting Laser (VCSEL), which is totally invisible to the human eye and is coupled with an internal infrared filter.

The VL53L0X can precisely measure how long it takes for emitted pulses of laser light to reach the nearest object and be reflected back to a detector. It is a self-contained LIDAR system. Time-of-flight (TOF) measurement enables the sensor to accurately determine the absolute distance to a target up to 2m (6.6 ft) away with 1 mm resolution.

Ranging measurements are communicated via I2C interface, which is also used to configure sensor settings. The module includes a 2.8V low-dropout linear voltage regulator that provides the voltage level required by the VL53L0X. The VIN supply can be either 3.3V and 5V. A level-shifting circuit for the I2C clock and data lines adjusts to the same logic voltage level as the supplied VIN to match the signal levels of the connected MCU.

Wiring:

  • Nano 5V to VIN
  • Nano GND to GND
  • Nano A4 to SDA
  • Nano A5 to SCL

Library:

  • In the Arduino IDE, select Tools > Manage Libraries...
  • Select and install the Adafruit_VL53L0X Library

Sketch:

  • Load up File > Examples > Adafruit_VL53L0X > VL53L0X
  • Upload sketch to the Nano
  • Open Tools > Serial Monitor
  • Set the baud rate to 115,200

Doppler Radar and the HB100 Module

HB100 intro.png

The HB100 Doppler Radar Module features a Dielectric Resonator Oscillator (DRO) to generate a 10.525GHz microwave signal. The signal is radiated by a microstrip patch antenna array. The radiated waves reflect from the target. The reflected waves will have a slightly different frequency that the original waves. The difference depends upon the relative difference in speed between the source and the target (according to the Doppler effect).

The reflected waves arrive back to the HB100 where the are received by a second microstrip patch antenna array. A mixer is used to combine the original signal with the reflected signal which generates beat frequencies at the difference between the frequencies of the two signals. As discussed, this difference is proportional to the relative speed of the source (sensor) and the target.

The output of the mixer is presented at the IF (intermediate frequency) pin of the HB100, but it is a very small signal that will require amplification to be sensed by our microcontroller.

The 10GHz radio waves exit and enter the HB100 on the PCB side, not on the side with the metal shield. Accordingly, the amplifier circuit that we add needs to mount onto the metal shield so that it does not interfere with the patch antennas on the PCB side of the HB100.

Amplifying Radar Signals With LM358 OpAmp

HB100 OpAmp.png

An LM358 OpAmp is a good option for amplifying the small IF signal from the HB100. The LM358 module features an LM358 OpAmp chip (datasheet) which contains two independent, high gain, internally frequency compensated operational amplifiers that were designed specifically to operate from a single power supply over a wide range of voltages.

Amplifier Assembly:

  • Solder three wires to back of LM358 header as shown
  • Mount LM358 to Metal Shield of HB100 as shown
  • use an insulator (like double sided tape) to prevent shorts
  • Solder the three wires from the LM358 to the HB100
  • LM358 VCC to HB100 +5
  • LM358 GND to HB100 GND
  • LM358 IN to HB100 IF

Jumpers to Arduino Nano:

  • Nano D8 to LM358 Out
  • Nano 5V to LM358 VCC
  • Nano GND to LM358 GND

Library:

  • In the Arduino IDE, select Tools > Manage Libraries...
  • Select and install the FreqMeasure Library

Sketch:

  • Grab the attached HB100_demo.ino
  • Upload sketch to the Nano
  • Open Tools > Serial Monitor
  • Set the baud rate to 115,200


Downloads

Magnetic AA/AAA Two Cell 5V MicroUSB Supply

Magnetic.png

Use two common AA (or AAA) battery cells to power any 5V microUSB device, such as a tablet or mobile phone.

Features a built-in DC-DC boost circuit to generate 5VDC from any input in the range of 1.5V-3V.

Please note that while many of the microcontroller boards that we encounter do have micoUSB ports, the included Arduino Nano is miniUSB (not microUSB).

Hack the Planet

outro.png

We hope you are enjoying this month's HackerBox adventure into electronics, computer technology, and hacker culture. Reach out and share your success in the comments below or other social media. Also, remember that you can email support@hackerboxes.com anytime if you have a question or need some help.

What's Next? Join the revolution. Live the HackLife. Get a cool box of hackable gear delivered right to your mailbox each month. Surf over to HackerBoxes.com and sign up for your monthly HackerBox subscription.