Sensor not being powered by 5v

Hello, I am new to the arduino community, so if my error has an easy fix that I just haven't come across yet, apologies in advance. I used this code with this setup with the HC-Sr04 sensor, and all was working good. I plug it into my computer with no modifications to either the wiring or the code, and the board powers on, but there is no more buzzing from the sensor, and no data is ouputted into the serial monitor either, so I assume the sensor is just not powering on. As for it being a dead sensor, I have so far tried 14 individual sensors, all with the same result. I also bought two additional boards, and both also had the same problem. Any solutions would be greatly appreciated (code attached).

That’s an ultrasonic distance sensor, what buzzing ?


Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.


In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.
Use the </> icon from the ‘posting menu’ to attach the copied sketch.

Schematic:


Sensor: Amazon.com

Actual wiring:

Yes not exactly a buzzing, but there was always some low pitched noise when it used to be turned on, and very noticeable

Have you tried different wires.

Yes I have tried several different ones.

Normally for me when ultrasonic sensors are running, there is a clicking and not a buzzing (if I put my ear right up to it). Have you tried testing it with an ultrasonic library like this one?

At least that would rule out it being an issue with the code.

Try this with different pins:


const int pingPin = 7; // Trigger Pin of Ultrasonic Sensor
const int echoPin = 6; // Echo Pin of Ultrasonic Sensor

void setup() {
   Serial.begin(9600); // Starting Serial Terminal
}

void loop() {
   long duration, inches, cm;
   pinMode(pingPin, OUTPUT);
   digitalWrite(pingPin, LOW);
   delayMicroseconds(2);
   digitalWrite(pingPin, HIGH);
   delayMicroseconds(10);
   digitalWrite(pingPin, LOW);
   pinMode(echoPin, INPUT);
   duration = pulseIn(echoPin, HIGH);
   inches = microsecondsToInches(duration);
   cm = microsecondsToCentimeters(duration);
   Serial.print(inches);
   Serial.print("in, ");
   Serial.print(cm);
   Serial.print("cm");
   Serial.println();
   delay(100);
}

long microsecondsToInches(long microseconds) {
   return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds) {
   return microseconds / 29 / 2;
}

Tried it with the different pins and this code but no luck

The last sketch works perfectly here.


  • If you can upload a simple sketch like blink there is nothing wrong with the USB cable.

  • Have you tried some simple sketches that successfully print to the serial monitor ?

  • Measure the 5V power pin voltage to confirm it gives 5V.

  • Replace all 4 wires going to the sensor.

Simple sketches, such as blink and other ones I have tried, seem to be correctly compiling and the L light is blinking on the board, yet nothing shows in the serial monitor. Baud rate is still 9600, the arduino board is selected and shown with COM4, is there anything I am doing wrong that is preventing absolutely anything from being displayed in the serial monitor?

What happens on the serial monitor screen with this sketch ?

int counter;

void setup() 
{
   Serial.begin(9600);
}

void loop() 
{
  Serial.print(“Counter value = “);
  Serial.println(counter++);

  delay(500);

}

Compilation error stray 342

"stray 342" is due to a bad copy/paste operation. The upper right corner of the code box in post #13 has an icon to push, which copies the code for the Arduino IDE code editor.

I used that button and still got the same error

Look, just type the 11 lines of code yourself, should only take 20 seconds.

I typed it myself and there were no compilation errors, but nothing showed up in the serial monitor again.

Hi.

can you explain how it was working? I wonder how to know without serial monitor. How did you get the data from your sensor?

Boy, you work on a store, or you are really motivated!

Please note as the example given by @LarryD, distance should be a float number rather than int (because of the division)

Hello, before this was happening the serial monitor was working fine, and displaying constant data from the sensor multiple times a second. For whatever reason, something is happening that, apparently, makes the entire serial monitor cease to display anything at all. I tried replacing the int with a float, but that gave no results either. As far as the amount of board and sensors I've tried, yes I am quite motivated to get this project to work haha!