Go Down

Topic: Distance Sensor (Read 1 time) previous topic - next topic

teckel


I'm looking for a distance sensor that can reliably measure if someone is within about 10 ft of it.  A digital proximity sensor might work too, if I can pretty reliably change its max distance by playing with the input voltage.  Cheap is the name of the game here, but it does need to work.  I've been looking at the HC-SR04, but a couple of commenters said it only worked for them up to ~60 cm, while others said it worked up and beyond 10ft.  Any suggestions?  -- I'm looking at ultrasound because I will be using it at school where there are several Wi-Fi hotspots and a ham radio club, I don't know how much noise this'll cause an IR sensor.

I will be using this in a lab where the space directly in front of the sensor will be clear for at least 20 ft, but there will be some tables to the side.  I was thinking maybe I could put some kind of tube around the sensor to narrow it's detection width.  Something like a toilet paper roll or a disassembled flashlight tube.  Do you think this'll work or will it be likely to always go off because it's reading the tube?


The HC-SR04 works up to about 450-500cm.  Those that only work to 60cm are broken.  Don't make your decision based on a couple people with poorly sourced or broken sensors.  Using my NewPing library you should get good results even with a $2 eBay ultrasonic sensor from China.  But, I would suggest paying a little more and get one from Amazon as you'll get it much faster and if there's a problem you can send it back.

Tim
Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone


C_minus_minus

Alright, I just got in the HC-SR04.  And, as I feared, I'm not getting enough range.  I used the example you package with your NewPing library ("NewPingExample") with MAX_DISTANCE changed to 5000 and an if statement so that it'd only display the range if it was greater than the range that was displayed before (so I didn't just have tons of data constantly shooting across the serial monitor).  The max range I got (and only if I stood still in front of the sensor so that it could measure the range several times) was about 150cm.  I need the sensor to go off with a person walking toward it at normal (or slightly slower than normal) walking speed at about twice that range.
So should I try a different sensor?  Do I need an amplifier?

teckel


Alright, I just got in the HC-SR04.  And, as I feared, I'm not getting enough range.  I used the example you package with your NewPing library ("NewPingExample") with MAX_DISTANCE changed to 5000 and an if statement so that it'd only display the range if it was greater than the range that was displayed before (so I didn't just have tons of data constantly shooting across the serial monitor).  The max range I got (and only if I stood still in front of the sensor so that it could measure the range several times) was about 150cm.  I need the sensor to go off with a person walking toward it at normal (or slightly slower than normal) walking speed at about twice that range.
So should I try a different sensor?  Do I need an amplifier?


First, you can't set MAX_DISTANCE to 5000cm.  The max you ever need to set that to is 500cm as that's the maximum distance the sensor is able to read.  Setting it to 5000 will give you a much longer delay and possible problems if you're trying to ping frequently.  You should set MAX_DISTANCE to either 500 or the maximum distance you care about, but never more than 500.

I also believe you're making things too complicated for testing.  Use this sketch:

Code: [Select]

#include <NewPing.h>

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.

NewPing sonar(TRIGGER_PIN, ECHO_PIN); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}

void loop() {
  delay(35);                      // Wait 35ms between pings.
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  if (uS != NO_ECHO) {
    Serial.print("Ping: ");
    Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
    Serial.println("cm");
  }
}


Don't use pin 13 or a pin with an LED on the main board (pins 11 and 12 are safe if you're using an Arduino Uno).  Point it in a direction where there's nothing within around 17 feet and start the serial monitor.  Then, starting in front of the sensor, walk away till you're 17 feet away.  Flank the beam and review the results.

Tim
Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

Go Up