Paid: Filtering code for Ultrasonic Distance Data

Hello community.

I am seeking assistance to my ultrasonic distance measure project.

I am offering 30$ to somebody who can help me with a correct code.

I am using a Maxbotix 10 meter sensor with Arduino nano version 3.1

The data is being transferred with a HC-12 radio 433 module, and the transfer works fine.

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 some bad and wrong reported readings, when the subject moves. The sensor sometimes reports the background for a brief moment 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 would like a code that can sort the data with a percentage. Taking the first reading and comparing it to the next with an adjustable filter in percentage. So if the new value deviates by more than ex 40% from the first, it should be ignored.

It is important to note, that the sensor should also reset the first value once in a while so that It won’t stay “locked” in the same position more than necesarry

This is my current 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);
  digitalWrite(triggerPin1, LOW);

void read_sensor() {
  sensor1 = pulseIn(pwPin1, HIGH);
  cm1 = sensor1/10;

void send_data()

void loop ()


Hello Peter,

Yes, I changed the Hc.12 to 19200 with module commands.

The transmitter is working perfectly.

This problem I am addressing is also happening with the sensor connected to a computer and range readings in the serial monitor.

Thanks for looking into this!

All the best,