Greetings to one and all. I am a new member here and I am fairly new to writing sketches. I downloaded a sketch from Tinkernut.com for their ultrasonic sonar-project. I have checked and double checked the code as well as the schematic connections. The code uploaded and verified and was successfully uploaded to my Arduino Uno. Here’s my problem. As soon as I apply power to the board the buzzer comes on and stays on. The project description states that when the sensor is triggered the buzzer is supposed to beep faster as an object gets closer.I have attached a link to the code. I would appreciate any assistance with this problem. Thank you.
.https://create.arduino.cc/editor/robotz1948/db86f85f-1bea-451f-96f5-78e73b0bef87
Hi.
I hope you’re enjoying being a member of this community.
To be honest, I don’t know why you’re getting that error. We have a slightly similar project that uses ultrasonic sensor and buzzer. And it beeps faster as an object gets closer.
You can access to that project here: https://rntlab.com/module-1/parking-sensor/ and see if it works for you.
I hope this helps.
Regards,
Sara
Hello Sara,
I wanted to thank you for taking the time to respond to my inquiry. I also appreciate your welcoming me to the forum, as well as the site. I am still experiencing a problem using the ultrasonic sensor. I have been finding conflicting information concerning the sensor. Is a library still required; specifically the “NewPing” library? Is this perhaps the root of the problem I am experiencing? I have tried a number of different sketches and/or codes without success. I would appreciate your input on this query.
Thank you,
Lloyd
Hi again.
The need for a library will depend on the code you use.
You can get the distance using the library or without the library.
The difference is that with the library you can get the distance with one single line of code.
Without the library you need to make some calculations based on the time it takes to receive the reflected wave (https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2013/11/How-ultrasonic-sensor-works.jpg)
If you use the NewPing library you need to install it first.
It may be useful taking a look at our ultrasonic sensor guide.
I hope this helps.
Let me know if you need anything else.
Regards,
Sara
Hello Sara,
Once again I want to thank you for your prompt reply. I most certainly will take a look at the project example you referred me to. I will further download the New Ping library as per your suggestion. I will let you know how it works out for me. Thus far I couldn’t be more pleased with your customer service and support. I’m sure I will be purchasing more of your products in the future.
Lloyd
Sara,
I have looked over the ultrasonic Sensor with LEDs and buzzer example project and I do not want to use the LEDs in my project; so, I have highlighted all the lines of code that I want to remove. (printed in red with asterisk ). Would I be correct in modifying the code as I have marked? Would I need the; #include HC-SR04 library? and/or the tone library?
Thank you for your time.
Lloyd
/* * created by Rui Santos, http://randomnerdtutorials.com * Ultrasonic Sensor with LED's bar graph and buzzer */ int tonePin = 4; //Tone - Red Jumper int trigPin = 9; //Trig - violet Jumper int echoPin = 10; //Echo - yellow Jumper int clockPin = 11; //IC Pin 11 - white Jumper ************ int latchPin = 12; //IC Pin 12 - Blue Jumper *********** int dataPin = 13; //IC Pin 14 - Green Jumper *********** byte possible_patterns[9] = {************** B00000000, ************* B00000001, ************* B00000011, *************** B00000111, ************** B00001111, *********** B00011111, *********** B00111111, *********** B01111111, *********** B11111111, *********** }; *********** int proximity=0; int duration; int distance; void setup() { //Serial Port Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(clockPin, OUTPUT); *********** pinMode(latchPin, OUTPUT); *********** pinMode(dataPin, OUTPUT); *********** pinMode(tonePin, OUTPUT); } void loop() { digitalWrite(latchPin, LOW); ************* digitalWrite(trigPin, HIGH); delayMicroseconds(1000); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; /*if (distance >= 45 || distance <= 0){ Serial.println("Out of range"); } else { ln(" cm"); }*/ proximity=map(distance, 0, 45, 8, 0); //Serial.println(proximity); if (proximity <= 0){ proximity=0; } else if (proximity >= 3 && proximity <= 4){ tone(tonePin, 200000, 200); } else if (proximity >= 5 && proximity <= 6){ tone(tonePin,5000, 200); } else if (proximity >= 7 && proximity <= 8){ tone(tonePin, 1000, 200); } shiftOut(dataPin, clockPin, *********** digitalWrite(latchPin, HIGH); *********** delay(600); noTone(tonePin); }
Hi.
In this example, you don’t need to include libraries. It doesn’t use the new ping library. And the tone() is part of the Arduino by default.
Here is the code without the LEDs (I’ve made some modifications so that the beep sounds have the same frequency):
https://gist.github.com/RuiSantosdotme/9ad7a2cf1fe4d6c24c7892880fa3def6
You may find useful taking a look at the tone() function.
https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/
You can customize the frequency of the beep(which results in different sounds) and the time (beeps faster or slower).
I hope this helps.
Regards,
Sara
Hello Sara,
I think I discovered the source of my problem. The buzzer/siren I am trying to use is rated for 24 VDC, and is drawing too much voltage/ current from my Arduino, causing a “brown out”; if you will. I put a low voltage/current buzzer in its place and the sketch worked just fine.
I thank you for all of your kind assistance.
Lloyd