Hi there,
I’ve recently started playing around with a Netduino and some sensors - specifically the ultrasonic range sensor (from 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");