Project tutorial
Portable Range Detection Device

Portable Range Detection Device © CC BY-NC

Portable range/distance detection device using an Arduino, ultrasonic sensor, and buzzer.

  • 10,586 views
  • 6 comments
  • 26 respects

Components and supplies

Necessary tools and machines

3drag
3D Printer (generic)
I used an Anet A8
09507 01
Soldering iron (generic)
Hy gluegun
Hot glue gun (generic)
Dremel
Or any rotary tool

Apps and online services

Ide web
Arduino IDE
Will need to download NewPing library
Simplify3D
Or any slicer of choice

About this project

Introduction

The Lehman College Exercise Science Department was conducting studies around weight training. There were inconsistencies in range of motion for repetitions, which could significantly influence the data. I was approached to create a device that would identify full range of motion for exercises that used machines or larger weights.

The device needed to meet the following conditions:

  • Adjustable Distance
  • Not permanently fixed to machines.
  • Tripod Compatible
  • No wires

Video

Parts

Most parts are shown below, but for a full list, refer to the BoM above. The parts used are selected not because they're optimal; that's what I had to work with. The footprint could be greatly reduced with custom PCBs, SMT components, or a LiPo battery.

Code

The NewPing library is required for the code (provided at the bottom) to compile.

The buzzer frequency and the upper/lower bounds are global variables that can be altered. The upper/lower bounds refer to the min and max distance the sensor reads, which is mapped to the analog value [0,5]V from the potentiometer.

int frequency =      700;     //Frequency in Hz
int lower_bound = 60; //Distance in mm
int upper_bound = 200; //Distance in mm

3 beeps occur on power up to indicate that the boot was successful (see the setup() loop). Next, loop() continuously requests data from the ultrasonic sensor and compares it to the threshold set by the potentiometer.

3D Printing

All files have been uploaded to thingiverse, or one condensed file can be found at the bottom of the page. How to use CAD will not be covered here. The model was made with the limitations of 3D printing in consideration. Overhangs were minimized by using 45 degree chamfers, which reduces support material. Clearances were generous, so parts should fit despite being printed on differently calibrated printers.

Print times will vary, but my print times were as follows:

  • Top Piece: 2 hours 40 minutes
  • Bottom Piece: 2 hours 20 minutes
  • Knob: 20 minutes

Assembly

The circuit schematics are provided at the bottom of the page. Parts are inserted without being wired to confirm the fits.

Salvaged IDE cables provided all the wires. Groups of wires can be peeled while remaining attached to one another, which provides some order.

Most of the electronics are mounted to one of the printed parts, so some thought must be put into wire routing and management.

The SMD indicator LEDs on the TP4056 board were desoldered. Extension wires and 3mm THT LEDs were soldered in their place. Current limiting resistors are still integrated with the board. There is a video of someone performing this relocation.

The arduino nano only had 2 accessible ground pads, so a stripboard was used to expand the number of ground pads. The same was done with the 5V line, which can be see in the picture below.

Breaking the connection on the strip is necessary so that 5V is not shorted to ground. The red "X" illustrates the location of the break. Only the top copper needs to be disrupted, not the entire fiberglass board.

Components were wired outside the enclosure. They were occasionally fitted in the enclosure to measure wire length and check for wire interference.

The potentiometer was trimmed by 6mm so that it would not protrude as much.

The connection to the 18650 was soldered on directly, which is bad practice. Overheating the cell will damage it and can fail over time. Spot welding an aluminum strip is the correct way of connecting 18650s.

Hot glue was shamefully used to secure the electronics. Avoid using hot glue when possible. Correct mechanical design and fasteners will outlast hot glue. It is bound to fail over time. It is understandable for prototypes, but production parts will never use hot glue.

Summary

In retrospect, I would have preferred using an IR sensor rather than the Ultrasonic, but there was no way I could have known this until I began to experiment with the Ultrasonic sensor. IR sensors have a narrower FOV with a tradeoff of a far lower maximum distance (~3ft).

If there were to be a second version, a LiPo would replace the 18650. The large knurled adaper nut is heavy and consumes space. The standard thread for tripod mounts is 1/4", so a simple 1/4" nut from the hardware store suffices. Custom PCBs would reduce the volume by half.

For a prototype that was conceived from concept to hand off within 2 weeks, I am content.

Future of the Project

When I was experimenting with the ultrasound sensor, I learned more about its limitations. The first being that its FOV has an angle of ~±15° (30° total). This meant that an object can trigger the buzzer before it's directly above the sensor. This yields inaccuracies and undesirable readings. Additionally, if the object's plane is not perpendicular (or within the angle of tolerance) to the transmitted sound wave, the sensor will not receive a reflected wave and won't be able to process a value for distance.

My initial plan was to have the unit rest on the ground and allow for the plates on a weight training bar to trigger the buzzer when they were lowered past the threshold. This system consisted of a fixed sensor and a moving trigger. My fellow engineering buddy had proposed an alternative solution, which involved inverting the system. He proposed mounting the sensor to the moving bar while pointing it to the ground. This way the ground became the trigger. It also eliminated inaccuracies due to a wide FOV as previously mentioned.

The proposal was not only a great solution to the given issues, but it is also very easy to implement. The order for the 1/4" tripod nut adapter came with a 1/4" -> 3/8" adapter AND a 3/8" -> 1/4" adapter. The second one will actually come into use!

As I did not have access to my dremel when I first began to 3D model, that forced me to account for the entire tripod adapter. This in combination with an 18650 cell increased the weight significantly. I do not want to add any more weight than I need to, so I will cut down the second tripod adapter before modeling the mount. I will get back to the project in a week to complete this alternative mounting solution. Until then, it still works nonetheless!

Code

RangeDetectionDevice.inoArduino
/**
    Viktor Silivanov
    3/22/2018
    Portable distance detection device using the HC-SR04 Ultrasonic sensor with distance adjustment for triggering the buzzer.
**/

//******************** Libraries ****************************************************************************************************************************************************************************************************************
#include <NewPing.h>

//******************** Pins ********************************************************************************************************************************************************************************************************************

//Analog Pins
#define wiper        A5
//Digital Pins
#define echo         2
#define trig         3
#define ON_LED       7
#define buzzer       8
#define buzzer_LED   9

//******************** Global Variables *********************************************************************************************************************************************************************************************************

//User Modification Allowed
int frequency =      700;                                                   //Frequency in Hz
int lower_bound =    60;                                                    //Distance in mm
int upper_bound =    200;                                                   //Distance in mm

//Do Not Modify
int buzz_time =      250;                                                   //Time in milliseconds for buzzer right upon startup
int buzz_delay =     280;                                                   //Time in milliseconds for buzzer delay right upon startup
int max_distance =   400;                                                   //Argument for object in the NewPing library
int i =              0;
int distance;
int threshold;
 
NewPing sonar(trig, echo, max_distance);                                    //Instanciation of object "sonar"

//******************** Setup ********************************************************************************************************************************************************************************************************************
//This function runs only once

void setup() {
  Serial.begin(9600);                                                       //Allows use of serial monitor with a baud rate of 9600

  //Pin I/O Type Declaration
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(buzzer_LED, OUTPUT);
  pinMode(ON_LED, OUTPUT);

  digitalWrite(ON_LED, HIGH);                                               //Turns on green LED; Stays on while unit is on

  //Buzzer beeps 3 times upon turning on device 
  while(i < 3){
    digitalWrite(buzzer_LED, HIGH);
    tone(buzzer, frequency, buzz_time);
    delay(buzz_delay);  
    i++;
  }
  digitalWrite(buzzer_LED, LOW);
}

//******************** Runs Endlessly ***********************************************************************************************************************************************************************************************************

void loop() {
  distance = sonar.ping_cm();                                              //Object "sonar" utilizes ping_cm() function from the library, which returns a value in cm. Distance then take on that value
  threshold = analogRead(wiper);                                           //Obtain analog value from wiper of the potentiometer
  threshold = map(threshold, 0, 1023, lower_bound, upper_bound);           //Translate analog readings into trigger range. Update values of threshold
  
  if(distance != 0 && distance < threshold){                               //Condition to trigger the buzzer
    tone(buzzer, frequency);
    digitalWrite(buzzer_LED, HIGH);
  }
  else{                                                                    //State of buzzer & LED otherwise
    noTone(buzzer);
    digitalWrite(buzzer_LED, LOW);
  }

  //serial_test();                                                           //Uncommment this to view data from the serial monitor
}

//******************** Test Function ************************************************************************************************************************************************************************************************************
//Utilizes serial monitor to display some values. Used for testing/debugging purposes.

void serial_test(){
  Serial.print("Ping: ");
  Serial.print(distance);
  Serial.println("cm");

  Serial.print("Range: [");
  Serial.print(lower_bound);
  Serial.print(", ");
  Serial.print(upper_bound);
  Serial.println("] cm");
  
  Serial.print("Threshold: ");
  Serial.print(threshold);
  Serial.println("cm");
  delay(100);
}

Custom parts and enclosures

Enclosure
All 3 parts are saved to one file

Schematics

Circuit Schematic
Circuit schematic ccwyc5xrr2

Comments

Similar projects you might like

This Device Will Never Get You Heat Stroke

Project tutorial by Hemesh chadalavada

  • 3,942 views
  • 2 comments
  • 15 respects

Otto DIY+ Arduino Bluetooth robot easy to 3D Print

Project tutorial by Team Otto builders

  • 77,652 views
  • 136 comments
  • 219 respects

Ultrasonic Glasses for the Blind

Project tutorial by Team GardnerTech

  • 20,995 views
  • 28 comments
  • 81 respects

3D Printer Fire Safety

Project tutorial by Miles Nash

  • 9,502 views
  • 6 comments
  • 42 respects

Open Vortexer

Project tutorial by Federico Vivaldi

  • 3,136 views
  • 0 comments
  • 11 respects

Easy Motion and Gesture Detection by PIR Sensor & Arduino

Project tutorial by ElectroPeak

  • 64,136 views
  • 13 comments
  • 302 respects
Add projectSign up / Login