Can I "Focus" an Ultra Sonic Distance Sensor

I have a script to control the intensity of a LEDS illuminating artwork. The script can set the initial brightness and then regulate it by how close or how far a subject is from the art work. I’ve posted the script below. Problem I’m having is that the leds flicker at an unacceptable rate unless I hold a large “target” (I’m using a 24’‘x24’’ piece of cardboard) in front of the sensor. I understand we have a transmitter and a receiver working here, I was just wondering if anyone had success with a "focusing solution where I could narrow the … “beams”.

FYI. I’m using either the Radio Shack USDS or the PING sensor (both with the 3 pins).

#include "Arduino.h"
class Ultrasonic
    Ultrasonic(int pin);
    void DistanceMeasure(void);
    long microsecondsToCentimeters(void);
    long microsecondsToInches(void);
    int brightness;

    int _pin;//pin number of Arduino that is connected with SIG pin of Ultrasonic Ranger.
    long duration;// the Pulse time received;

Ultrasonic::Ultrasonic(int pin)
  _pin = pin;
/*Begin the detection and get the pulse back signal*/
void Ultrasonic::DistanceMeasure(void)
  pinMode(_pin, OUTPUT);
  digitalWrite(_pin, LOW);
  digitalWrite(_pin, HIGH);
  digitalWrite(_pin, LOW);
  pinMode(_pin, INPUT);
  duration = pulseIn(_pin, HIGH);
/*The measured distance from the range 0 to 400 Centimeters*/
long Ultrasonic::microsecondsToCentimeters(void)
  return duration / 29 / 2;
/*The measured distance from the range 0 to 240 Inches*/
long Ultrasonic::microsecondsToInches(void)
  return duration / 74 / 2;

Ultrasonic ultrasonic(7);
const int transistorPin = 9; // from dimmer sketch
void setup()

  pinMode(transistorPin, OUTPUT);

void loop()

  long RangeInInches;
  long brightness;
  ultrasonic.DistanceMeasure();// get the current signal time;
  RangeInInches = ultrasonic.microsecondsToInches();//convert the time to inches;
  Serial.print(RangeInInches);//0~240 inches
  Serial.println(" inch");
  float maxdistance = 108;
  float mindistance = 36;
  float maxbrightnessper = 100; //set max brightness when between min and max distance(0 to 100)
  float minbrightnessper = 25;  //set min brightness when between min and max distance(0 to 100)
  float maxbrightnessout = 100; //set brightness when under the min distance (0 to 100)
  float minbrightnessout = 15;  //set brightness when over the max distance(0 to 100)
  float maxbrightness = maxbrightnessper * 90 / 100;
  float minbrightness = minbrightnessper * 90 / 100;

  if (RangeInInches > maxdistance)
    brightness = minbrightnessout*255/100;
  else if (RangeInInches < mindistance)
    brightness = maxbrightnessout*255/100;

    float mm = ((minbrightness - maxbrightness) / (maxdistance - mindistance));

    float b = maxbrightness - mindistance * mm;
    float brightnessindegrees = mm * RangeInInches + b;
    float rad = DEG_TO_RAD * brightnessindegrees;
    brightness = 255 - cos(rad) * 255;
  analogWrite(transistorPin, brightness);

There is no way (for a hobbyist) to focus ultrasonic beams. You are stuck with the beam pattern of the transducers.

You might try averaging a few readings, throw out some outliers, or use a different type of sensor. The Lidar Lite laser ranging sensor is one possibility.