Hello community.
I am seeking assistance to my ultrasonic distance measure project.
I am using a Maxbotix 10 meter sensor with Arduino nano 3.1v.
I am running fast and manually triggered pulses, for real-time operation continuously calculating the distance between a subject (human) and a camera's film plane.
However, I get a lot of reported bad readings, when the subject moves. The sensor reports the background and the values are clearly wrong.
So how do I run a filter that can eliminate these obvious wrong readings? A filter that can ignore a reading that is "unexpected"? I am pretty new to Arduino, and I have been spending a lot of time to get this code right in the first place. So I would really appreciate all the help I can get from you guys!!
This is my code:
#include <SoftwareSerial.h>
SoftwareSerial HC12(5, 4); // HC-12 TX Pin, HC-12 RX Pin
const int pwPin1 = 3;
int triggerPin1 = 13;
long sensor1, cm1;
void setup() {
Serial.begin(19200); // Serial port to computer
HC12.begin(19200); // Serial port to HC12'
pinMode(pwPin1, INPUT);
pinMode(triggerPin1, OUTPUT);
}
void start_sensor() {
digitalWrite(triggerPin1, HIGH);
delay(1);
digitalWrite(triggerPin1, LOW);
delayMicroseconds(25);
}
void read_sensor() {
sensor1 = pulseIn(pwPin1, HIGH);
cm1 = sensor1/10;
}
void send_data()
{
HC12.println(cm1);
Serial.println(cm1);
}
void loop ()
{
start_sensor();
read_sensor();
send_data();
delay(25);
}
Thank you so much!!
All the best,
Lasse