How can I use my Range sensor as a Motion detector

Disclaimer: French and not an Arduino expert.

My Range Sensor:

Hello. I'm currently working on a light system for my forklift at work. Basically I want the light to be white when I'm moving and Red when I'm stopped.

Right now I already have my prototype version of the circuit. I already know some basics of the Arduino on how to control my LEDs

But ..

I'd like to know how I can use the range sensor as a motion detector. What I mean is when the sensor is not moving and aiming at the ground, since the ground is also not moving, the value is always the same. (Example from the serial print: 5cm, 5cm, 5cm, 5cm ..)

So whenever I move the sensor this value change wich is good. It means that if my forklift is moving the value is changing and If I'm not moving the value won't move.
(Serial print: 5cm , 5cm, 6cm , 7cm, 4cm //moving)

So now I'm wondering how can I use that to trigger an action when my forklift is moving or not.

I tried storing the value of the sensor in the EEPROM memory but didn't worked for me that way.

Thanks in advance if you can help me :wink:

You could keep a moving average of the range measurements, and if one or more measurements deviates "significantly" from the average, the sensor or target is moving.

You would need to decide what deviation is significant, depending on the environment.

I for some time was the chief designer in a european fork lift compay. Your idea is fun but there is a high risc for misworkings like false "standing still" indication while moving. Sensing the accelerator and the brake pedal would be preferable in general.

But the ground is always the same distance from the sensor (unless really bouncy.)

It may be better to put a sensor on the driveshaft. A magnetic "prox" sensor can detect bolt heads on a flywheel or coupling with high reliability.

@MorganS Very good suggestion.
Or use a number of motion sensors.....

An accelerometer such as the ADXL345 can be used very simply as an "inactivity" sensor. Then your device can be inside a sealed box with no way for dirt or moisture to attack it.

What does the accelerometer say while driving at constant speed on a smooth floor?

If you could put a wheel with bumpy tread on a castor under the middle of the lift, a piezo disk could pick up vibrations from movement.

Maybe even try a pickup on some other part that only vibrates to a certain level when moving.

I have a very important question about the fork lift. Is it electric powered or does it have an engine that is always running? If electric, check the current going to the motor.

What about when the forklift is stationary, but the forks are moving up/down?

Paul

Railroader:
What does the accelerometer say while driving at constant speed on a smooth floor?

No floor is that smooth.

Seems like an optical mouse type of affair would do it if you could account for the distance. But, how would you protect it and keep it clean?

Hello. To answer most of the questions. There's a lot of things I can't do but would love to do instead of my method. I do not own the forklift. So I'm not allowed to do any major/permanent modifications.
My current version is portable. I can attach it only in one specific spot and I can't have long cables running around. It needs to be compact ^^

That's why I thougt the Range sensor could work. But I might also try your idea @MorganS with the accelerometer.

@Paul_KD7HB Electric but I can't plug anything to the circuit (Not allowed)

MorganS:
An accelerometer such as the ADXL345 can be used very simply as an "inactivity" sensor. Then your device can be inside a sealed box with no way for dirt or moisture to attack it.

How can I do that ?
When I tried to use the example file ADXL3xx from Arduino,

All I got in my serial monitor is that and I don't know what I'm supposed to do with that

It's a 3D sensor. Those are 1 reading each acceleration on 3 axes. Gravity is acceleration straight down, when the device is held still you can tell which way the sensor is pointing by the values. Any change in velocity or direction is also acceleration, the sensor gives its own 3 axes. If you're not sure then turn the sensor until 2 axes report 0, the 3rd will be pointing up or down. Repeat for the other two.

Have you checked the datasheet of the sensor for what the numbers mean?

Tip: if you find yourself needing trig for angles, pre-calculated lookup tables in flash can be used to speed your sketch enormously even if you interpolate the table. Uno has 32K flash, see when you compile how much your sketch uses.

Avoid using Arduino float or double on AVR chip Arduinos. You get 32-bit float on an 8-bit chip with no FPU.

Pick up the sensor and move it. Simulate the forklift moving forward and back. Maybe driving over a bump in the floor.

Look at the numbers. See what numbers respond to each motion.

If the ultrasonic pulse bounces off the floor when the lift is moving, the path will be longer than when it is stopped. Look for reported distance > actual distance.

Will the sensor get a sufficient reflection if mounted 45 degrees to the floor?

Will the forklift move far enough in the few hundred microseconds while the pulse is in transit? Remember we need to detect speeds less than walking speed.

The sensor would point straight down only and the height of it above the floor would be a big part of how slow it could detect, would not get very slow motion.

If the receiver could block returns that are not direct or tell directness then ping straight down could test if the receiver moved.

It's not perfect for anything like slow movement because the lift will move up and down a few mm, the floor won't be completely flat but consider the consequences being what color lights are on.

The smart thing is to monitor at least 2 wheels all the time. Then you will know if moving or not.

If you want to make doppler sonar you send continuous timed pulses and get returns. With analog you would subtract the return from the signal and listen to the difference as sound, it works with radar for ground surveillance and listening to things move is a real gas!