Hello, I have a problem with the measurements from the sensor because it no longer measures then 2.2 meters, but in the description it said that it measures about 5 meters. What can I change in the code ??
this is my code:
#define TRIGPIN 11
#define ECHOPIN 10
float duration, distance;
void setup() {
Serial.begin(115200);
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
}
void loop() {
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(20);
digitalWrite(TRIGPIN, LOW);
duration = pulseIn(ECHOPIN, HIGH);
distance = (duration / 2) * 0.343;
Serial.print("distance: ");
Serial.print(distance);
Serial.println(" mm");
delay(100);
Your topic was MOVED to its current forum category as it is more suitable than the original
adamelo:
this is my code:
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
See also FAQ - Arduino Forum for general rules on forum behaviour and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…
Your code is incomplete and lacks code tags.
(pulseIn does not return a float, and you told us nothing about your sensor other than it might be waterproof)
You can post code by using this method that adds the code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps
press Ctrl-T for autoformatting your code
do a rightclick with the mouse and choose "copy for forum"
paste clipboard into write-window of a posting
best regards Stefan
system
Closed
December 17, 2022, 3:16pm
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.