ARDUINO NANO + Ultrasonic sensor HC-SR04
HTML-код
- Опубликовано: 11 сен 2024
- This video is about Arduino tutorial Ultrasonic sensor HC-SR04
Parts list
- Arduino UNO R3
- HC-SR04 ultrasonic sensor
- jump wire
Arduino Sketch : goo.gl/Vh5TKj
::::::::::: SUPPORT CHANNEL ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Please Donate To Help Me Afford New Equipment And Software To Make My Videos More : goo.gl/1m8Dg2
Don't forget to subscribe!
#include
const int TriggerPin = 8;
const int EchoPin = 9;
long Duration = 0;
int Delay_timer = 1000;
void setup() {
pinMode(TriggerPin, OUTPUT);
pinMode(EchoPin, INPUT);
Serial.begin(9600);
}
long Distance(long time){
long DistanceCalc;
DistanceCalc = ((time * 0.034) / 2); // centimeters
return DistanceCalc;
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(TriggerPin, LOW);
delayMicroseconds(2);
digitalWrite(TriggerPin,HIGH);
delayMicroseconds(10);
digitalWrite(TriggerPin, LOW);
Duration = pulseIn(EchoPin,HIGH);
long Distance_cm = Distance(Duration);
Serial.print("Distance = ");
Serial.print(Distance_cm);
Serial.println (" cm");
delay(Delay_timer);
}
Thank you so muchh bhai
Short, effective and straight to the point - thanks for the tutorial. Also, well commented code.
i cannot get the code running because Distance was not declared onscope
so when i plugged it in my computer disabled usb ports because it was using to much power and i unplugged everything and it still wouldnt work
I was thinking about to download a library just to do this, but you just show me how easy is to make. Tks
Code:
const int TriggerPin = 8; //Trig Pin
const int EchoPin = 9; //Echo Pin
long Duration = 0;
void setup() {
// Put setup code here, to run once:
pinMode(TriggerPin, OUTPUT); //Trigger is an output pin
pinMode(EchoPin, INPUT); //ECHO is an input pin
Serial.begin(9600);
}
void loop() {
// main code:
digitalWrite(TriggerPin, LOW);
delayMicroseconds(2);
digitalWrite(TriggerPin, HIGH); //Trigger Pin to HIGH
delayMicroseconds(10); //10us high
digitalWrite(TriggerPin, LOW); //Trigger Pin to HIGH
Duration = pulseIn(EchoPin, HIGH); //Wait for the Echo Pin to get high
//Return the duration in milliseconds
long Distance_cm = Distance(Duration); //Use function to calculate the distance
Serial.print("Distance = "); //output to serial
Serial.print(Distance_cm);
Serial.println(" cm");
delay(1000); //Wait to do the next mesurement
}
long Distance(long time)
{
long DistanceCalc;
DistanceCalc = ((time * 0.034) / 2); //Actual calcutatio in cm
//Distance = time / 74 / 2 //Actual calcutatio in inces
return DistanceCalc; //Return calculated value
}
I used the same code but it didn't work. The program is giving errors in the code.
can we attach a buzzer with this ??
My code does upload but I cant see any calculations.
Which window is at end of video.
link broken, now redirects to firewall scam page.
Is it working for Nano i know İTS not a good question but i must do it
Hi can u help me in my project plz plz plz . i had already made the project but mess in its codes
can you make one code for my project chargeable basis. ..
const int TriggerPin = 6; //Trig pin
const int EchoPin = 5; //Echo pin
long Duration = 0;
void setup(){
// put your setup code here, to run once:
pinMode(TriggerPin,OUTPUT); //Trigger is an output pin
pinMode(EchoPin,INPUT); //Echo is an input pin
Serial.begin(9600); //Serial 0utput
}
void loop(){
//put your main code here, to run repeatedly:
digitalWrite(TriggerPin,LOW);
delayMicroseconds(2);
digitalWrite(TriggerPin,HIGH); //Trigger pin to HIGH
delayMicroseconds(10); // 10us high
digitalWrite(TriggerPin,LOW); //Trigger pin to HIGH
Duration = pulseIn(EchoPin, HIGH); //Waits for the echo pin to get high
//returns the duration in microseconds
long Distance_cm = Distance(Duration); //Use function to calculate the distance
Serial.print("Distance = "); //0utput to serial
Serial.print(Distance_cm);
Serial.print(" cm");
delay(1000); //Wait to do next measurment
}
long Distance(long time)
{
long DistanceCalc; //Calculation variable
DistanceCalc = (time * 0.034 / 2); //Actual calculation in cm
//DistanceCalc = time / 74 / 2; //Actual calculation in inches
return DistanceCalc; //return calculated value
}
what is pin 7 motor?
What software are you using for circuit
Please , fritzing.org/home/
@@MakerTutor101
Hi
From indonesia
maximum meter ?
Distance kitni hogi jisme ye work kre
Can u please interface two ultrasonic sensors..one will send ping and other will recieve
Why is your goal with trying to use two ultrasonic sensors ? It will works with only one.
i cant access to sketch :(
Dual sensor kaise lagaye
how to i gave this code
It is only showing output as "Distance=0 cm".. That`s it value is not changing.. Plz help me
I have the same problem. Did you ever get pass it?
Same here
@@marcelodive Conseguiu resolver?
@@vinicius71999 , acho que era um problema utilizando "delay()" em outras partes do código, mas confesso que não lembro 100% como consegui resolver. Quer que eu dê uma olhada no meu código mais antigo?
@@marcelodive Se puder, eu ficaria agradecido, estou com dois arduínos nano e dois sensores, acredito que não seja defeito
Also explain how to execute plzz
I mean the whole entire working part after writing the code
Code plzzzzzz
link not working
send coding
tell how
please share code
I will donate you 7000$
I will give you $7,000 and tell me how
no problem,