Hello,
Could somebody help me with my project. I want to start a video when something is in motion. And what came to my mind is accelerometer. I can set it up so I get data from axis but what I need is that serial monitor prints number 1 when there are bigger changes on axis and 0 when it is not moving. can somebedy help me with that ? or if its even possible ? I heard that this sensor can work as a vibration sensor so besically when there are bigger vibrations write 1 and when they are low write 0.
You will need to give a little bit more information than this.
Something in motion could be a vehicle starting to move or a swinging ball on a fixed mount.
You will need to define the physical situation before decisions about how to handle the data can be made.
For example, if the accelerometer is always perfectly level, with the Z axis pointing up, then you could monitor and respond to acceleration in the X or Y directions, or both.
But that will work only if Z is always vertical, because the accelerometer also measures the acceleration due to gravity in the vertical direction.
Thank you for your answers, my english isnt that good so not sure if I will use correct vocabulary, but the sensor will be attached on pedal of old sewing machine, so the sensor will go up and down and when that happens I need to get signal from the sensor, dont care how fast it will go but just the fakt that it is moving. On the sewing machine machine is big wheel what you move with that pedal, so there is option that I could track that wheel but I am even less sure haw would I do that. There is also option just to put button like thing on the pedal so when person puts their legs on pedal, I will get signal but that is cheesy way.
You could measure the magnitude of the total acceleration, which is independent of direction, and check whether it deviates significantly from 1 g. If the float values ax, ay, az are the individual axial accelerations:
float magnitude = sqrt(ax*ax + ay*ay + az*az);
magnitude will be 1 g in accelerometer units when the sensor is still.
As others have said, it depends on various factors. For example, do you expect the sensor, such as accelerometer, vibration, tilt, mercury switch, etc, atached to the underside of the pedal or its 'lever arm'? Or nearby, which might suggest IR, PIR, LDR, photodiode, ultrasonic, etc?
Meanwhile, I rather favour a small magnet glued to the pedal or its 'arm', with a carefully positioned reed switch as the sensor.
Practical experiment will determine viability, such as the issue of wires hindering operation.
I plannig to put the sensor and arduino there(red squere) on upper part of the pedal. It will be in 3d printed black box.
So basically what I need to achieve is to get only one number from the sensor, not three and when it is in motion it will show higher number when it is static lower.
Hello, thank you for your help, now I have only one number, but the number is more of position number, rather then how much it moves or that its moving. So when I move sensor up I get higher number and the number stay like that, until I move it down. So my question is, is there a code what could be written there, whitch would be like: if there is numeric change in magnitude more then 100 either direction do this, if not dont do enything. So it doesnt matter how big is the number, but only if the number changes ether up or down it will send the signal.
This is the code what I used, I ended up using different sensor: