vb and arduino interface

well i posted the same thing a few days ago but my bad im not really active these days so im sorry for whoever help me but im not responding and once again im sorry for bad grammar.Well i will go straight to the topic,im trying to make project that my lecturer gave me(he let us choose the topic)and i chose monitoring level water.

im searching it on google and i saw this code
const int trigPin = 12;
const int echoPin = 11;
float duration, distance;
void setup()

{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);

}

void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(echoPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);
distance = duration*0.034/2;

Serial.print("Distance: ");
Serial.println(distance);

}

i go through many codes but thats one of them and from what i have seen most of them look familiar they just declare the trig and echo from ultrasonic sensor for the arduino pins and declare I/O.But its not working for me,any idea?And is code to measure distance is the same for monitoring water level?

Note:Im using hc-sr04 ultrasonic sensor and arduino uno

But its not working for me,any idea?

Yes. Stop using such lame phrases.

Some hardware is connected to the Arduino in some mysterious way. What hardware, exactly? Connected HOW?

The code DOES work. That it does not do what you expect means that your expectations are wrong. But, without knowing what the code actually does, or what you expect it to do, we can't tell you why your expectations are unrealistic.

Writing to an input pin is probably a problem.

In setup:
pinMode(echoPin, INPUT);

In loop:
digitalWrite(echoPin, HIGH);

pulseIn returns an unsigned long where you have duration declared as a float.

You say you found this on goggle, was it working where you found it? Did you try to contact the author?

How does vb factor into this (see your thread title)?

adwsystems:
Writing to an input pin is probably a problem.

In setup:
pinMode(echoPin, INPUT);

In loop:
digitalWrite(echoPin, HIGH);

pulseIn returns an unsigned long where you have duration declared as a float.

You say you found this on goggle, was it working where you found it? Did you try to contact the author?

How does vb factor into this (see your thread title)?

i changed the declaration and yeah its working fine for distance measurement about that vb factor that was my bad because i dont really understand this kind of things so im sorry about it.Its working but can it be use for monitoring water level?or do i need to modify something?

PaulS:
Yes. Stop using such lame phrases.

Some hardware is connected to the Arduino in some mysterious way. What hardware, exactly? Connected HOW?

The code DOES work. That it does not do what you expect means that your expectations are wrong. But, without knowing what the code actually does, or what you expect it to do, we can't tell you why your expectations are unrealistic.

you are right i dont really know what the code does.Thats why im here,im new to programming so what do you expect?

weslysubianto:
well i posted the same thing a few days ago

Here (or is it there?)

So how about answering the questions I asked?

Please

  • post the program you are trying,
  • tell us exactly what happens when you run it
  • provide a good diagram that shows how you are using it to try to detect the water level
  • where is the sensor,
  • where is the water,
  • what distance do you want to measure,
  • how accurately do you need to measure it?

…R

(deleted)

spycatcher2k:
You should not be using code you do not understand, if your lecturer gave you this work, go to your lecturer and tell her/him to teach you the basics before giving you assignments.

So you have code that works, and tells you the distance, you then ask if it can be used to monitor water levels!

The answer is yes, it can, point it down to where the water is, it will tell you how far away it is, job done.

well,at least your words is more polite than him.ik its wrong to use something without knowing what it does i will reflect on it and yes a few hours ago i went to meet him and ask him something tho im not asking the codes too much because its assignment from him(once again he did tell us but its "theory" and mostly its about parralel port which is rarely used right now)either way its my fault for not studying seriously and thx for the reply i appreciate it!thx for other who reply too.