Why is my Ultrosonic Sensor working on my car without power?

Can anyone explain to me why my car detects objects using the HR-SR04 and its not plugged into any 5V power?

Difficult to say without seeing your schematic, wiring and sketch. :thinking:

Will upload for you in a sec

// motor driver 1
// Motor A connections
int m1F = 5;
int m1B = 4;
// Motor B connections
int m2F = 3;
int m2B = 2;

// motor driver 2
// Motor C connections
int m3F = 9;
int m3B = 8;
// Motor D connections
int m4F = 7;
int m4B = 6;

const int trigPin = 10; // trig pin of HC-SR04

const int echoPin = 11; // Echo pin of HC-SR04

float duration, distance;

void setup() {

// Set all the motor control pins to outputs
// motor driver 1
pinMode(m1F, OUTPUT);
pinMode(m1B, OUTPUT);
pinMode(m2F, OUTPUT);
pinMode(m2B, OUTPUT);

// motor driver 2
pinMode(m3F, OUTPUT);
pinMode(m3B, OUTPUT);
pinMode(m4F, OUTPUT);
pinMode(m4B, OUTPUT);
// Turn off motors - Initial state
// motor driver 1
digitalWrite(m1F, LOW);
digitalWrite(m1B, LOW);
digitalWrite(m2F, LOW);
digitalWrite(m2B, LOW);

// motor driver 2
digitalWrite(m3F, LOW);
digitalWrite(m3B, LOW);
digitalWrite(m4F, LOW);
digitalWrite(m4B, LOW);

pinMode(trigPin, OUTPUT); // set trig pin as output

pinMode(echoPin, INPUT); //set echo pin as input to capture reflected waves

Serial.begin(9600);
}

void loop() {

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH); // send waves for 10 us

delayMicroseconds(10);

duration = pulseIn(echoPin, HIGH); // receive reflected waves

distance = (duration*.0343)/2; // convert to distance

if (distance > 19) {

// move forward on motor A & B --->
digitalWrite(m1F, HIGH);
digitalWrite(m1B, LOW);
digitalWrite(m2F, HIGH);
digitalWrite(m2B, LOW);
// Turn on motor C & D B-->
digitalWrite(m3F, HIGH);
digitalWrite(m3B, LOW);
digitalWrite(m4F, HIGH);
digitalWrite(m4B, LOW);

}

if (distance < 18) {

// stop 
// Turn off motor A & B --->
digitalWrite(m1F, LOW);
digitalWrite(m1B, LOW);
digitalWrite(m2F, LOW);
digitalWrite(m2B, LOW);
// Turn off motor C & D --->
digitalWrite(m3F, LOW);
digitalWrite(m3B, LOW);
digitalWrite(m4F, LOW);
digitalWrite(m4B, LOW);

delay(2000);

// reverse 
// move back on motor A & B --->
digitalWrite(m1F, LOW);
digitalWrite(m1B, HIGH);
digitalWrite(m2F, LOW);
digitalWrite(m2B, HIGH);
// move back on motor C & D --->
digitalWrite(m3F, LOW);
digitalWrite(m3B, HIGH);
digitalWrite(m4F, LOW);
digitalWrite(m4B, HIGH);

delay(2000);

// left 
// move back on motor A & B --->
digitalWrite(m1F, HIGH);
digitalWrite(m1B, LOW);
digitalWrite(m2F, HIGH);
digitalWrite(m2B, LOW);
// move back on motor C & D --->
digitalWrite(m3F, LOW);
digitalWrite(m3B, HIGH);
digitalWrite(m4F, LOW);
digitalWrite(m4B, HIGH);

delay(2000);

}
}



Sorry was busy at work, this is for one of my students, and myself to know why this would go without power? I presume its because its drawing on the 9 volt battery....? But he did not plug in the VCC power jumper wire to the ultasonic sound. Very strange, could be a walking dead zombie...

More likely the HC-SR04 is being "phantom" powered by the voltage on the trigger pin.

  • As david said, see red highlight.

Also, the wire in green connects driver 5v in/out to the Arduino; suggest this not be connected while the Arduino is plugged into your PC.

Actually, try removing it and see what happens.


Hi, @debs_anderson
Welcome to the forum.

Is this from a kit or built from ground up?
Do you have a connection/schematic diagram?

Most probable answer.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia: