# US-100 - Ultrasonic Sensor

Hello,

I have an ultrasonic sensor US-100 that I want to use together with an Arduino pro mini.

I power the US-100 from a digital pin, because I want to use it with batteries.

I use the following sketch that is working:

``````#define US_100_PIN_VCC      5
#define US_100_PIN_GND      9
#define US_100_PIN_TRIGGER  6
#define US_100_PIN_ECHO     7

void setup()
{
Serial.begin(115200);

pinMode(US_100_PIN_VCC, OUTPUT);
digitalWrite(US_100_PIN_VCC, LOW);
pinMode(US_100_PIN_TRIGGER, OUTPUT);
digitalWrite(US_100_PIN_TRIGGER, LOW);
pinMode(US_100_PIN_ECHO, INPUT);
pinMode(US_100_PIN_GND, OUTPUT);
digitalWrite(US_100_PIN_GND, LOW);
}

// measure distance with ultrasonic sensor
uint16_t measureDistance()
{
unsigned long echoTime   = 0;
uint32_t distanceMM = 0;

digitalWrite(US_100_PIN_VCC, HIGH);                     // power on the US-100
delay(500);

digitalWrite(US_100_PIN_TRIGGER, HIGH);                 // Send pulses begin by trigger pin
delayMicroseconds(50);                                  // Set the pulse width of 50us
digitalWrite(US_100_PIN_TRIGGER, LOW);                  // The end of the pulse and start measure

echoTime = pulseIn(US_100_PIN_ECHO, HIGH);              // A pulse width calculating US-100 returned
if ((echoTime < 60000) && (echoTime > 1))
{
// distanceMM = (echoTime * 0.34mm/us) / 2 (mm)
distanceMM = (echoTime * 34 / 100) / 2;               // Calculating the distance by a pulse width.
}

//digitalWrite(US_100_PIN_VCC, LOW);                    // power off the US-100

// return the distance
return distanceMM;
}

void loop() {
Serial.println(measureDistance());

delay(1000);
}
``````

If I set the US_100_PIN_VCC to low to power off the sensor after my measurement the sensor will not report any values anymore, even when I set it to high before the measurement.

Does anybody have an idea, why it is not working?

Regards
Stefan

If I set the US_100_PIN_VCC to low to power off the sensor after my measurement the sensor will not report any values anymore, even when I set it to high before the measurement.

Please measure the current consumption of the module while it is sending. It consumes 2mA while being quiet so the consumption may be to high for a digital pin (max. 20mA) of the Arduino.