Hi there,
I've recently started playing around with Netduino and some sensors - specifically the ultrasonic range sensor (seed studio). I've connected it to my digital pin.
If I aim it at the same place, I get fluctuations of about 20cm sometimes... usually from 85cm -> 120cm at the same place? Any ideas?
Here are some environmental situations:
The 5V range sensor is on the breadboard with a LED and a resistor (330ohm)
Code:
while (true)
{
outPort.Active = true; // Put port in write mode
outPort.Write(true); // Pulse pin
outPort.Write(false);
outPort.Active = false;// Put port in read mode;
bool lineState = false;
// Wait for the line to go high, for start of pulse.
while (lineState == false)
lineState = outPort.Read();
long startOfPulseAt = System.DateTime.Now.Ticks; // Save start ticks.
// Wait for line to go low.
while (lineState)
lineState = outPort.Read();
long endOfPulse = System.DateTime.Now.Ticks; // Save end ticks.
int ticks = (int)(endOfPulse - startOfPulseAt);
lastReading = ticks / 580;
Debug.Print(lastReading.ToString() + " cm");
Inconsistent reads on ultrasonic range sensor?
Started by Daniel Minnaar, Nov 11 2011 10:40 AM
2 replies to this topic
#1
Posted 11 November 2011 - 10:40 AM
#2
Posted 11 November 2011 - 12:44 PM
Hello Reactive, and welcome to the forum.
Could you specify a link with the sensor specs?
Cheers
Biggest fault of Netduino? It runs by electricity.
#3
Posted 11 November 2011 - 01:58 PM
The busy-loop method is not very accurate as a single read can take pretty long - i've used an InterruptPort to detect the edges (you'll need another port or some piece of circuitry with e.g. a 555 to trigger the sensor reading, since there's no tristate for interrupt ports ...).
Mario, it's at http://www.seeedstud...surement_module - it's basically the same as the Parallax Ping))) which already has some threads here.
I believe that no discovery of fact, however trivial, can be wholly useless to the race, and that no trumpeting of falsehood, however virtuous in intent, can be anything but vicious.
-- H.L. Mencken, "What I Believe"
-- H.L. Mencken, "What I Believe"
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users