Main Site Documentation

Vibration Sensor on Domino


Hi All

I am currently developing a prototype that reads levels of vibration of excavation equipment and was wondering the best was to implement the sensor.
I am currently using a little piezo vibration sensor and have a few questions.

What socket would it be plugged into (Digital or analog)?
How would I control the sensitivity of it (Ie the threshold of when it reads back that the threshold has been met)?
I want to check every 60 seconds if the sensor is meeting or exceeding this threshold?

Many Thanks



What is the vibration frequency that you are trying to measure? Do you know?

One option would be to amplify the piezo, rectify the signal and filter it. That yo can then measure via an analog pin and it will give you a straight analog value of the current maximum amount of vibration.

If you just hook it up to an analog pin, after amplifying, then you will be able to measure the instantaneous vibration, but you will have to take many many samples and find the highest value, or the average value, depending on your needs.

If the frequency isn’t too high then you can also look at a digital G sensor. The last one that I worked with sampled at 180 samples per second and is thus OK for vibration frequencies up to around 70Hz.

You can also look at an analog G sensor, which will not need amplification. Both G sensors will give you a calibrated G reading. The piezo you will have to calibrate yourself somehow.

Can you point me at a datasheet of your piezo?



I am currently using a small off the shelf piezo wired into a block and then plugged into an analog socket.
All i need is to correctly read the level from the sensor and then compare it against a common threshold value.

The sensor is just a simple Piezo element (knock sensor), similar to

Do you have any code to help me develop this further?




I would suggest you look into something like this(just use a local site, not from my country… :)):

All Piezo devices give AC. So you will need some circuitry. See below.

Will create some code for you(which I can’t test…:))


It is wired into a block call a vibration sensor and is by

on that site it comes up as a piezo disk vibration sensor


Is this the one you have ?


yes thats the one.


Then it might be fine. I just don’t know what the output voltage will be. Might be too little to measure directly.

using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;

namespace FEZ_Domino_Application2
    public class Program
        public static void Main()

            OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState);
            GHIElectronics.NETMF.Hardware.AnalogIn AN = new GHIElectronics.NETMF.Hardware.AnalogIn(GHIElectronics.NETMF.Hardware.AnalogIn.Pin.Ain0);
            AN.SetLinearScale(-512, 512);//Set 0V as -512, +3V3 as +512. The resistors bias the pin to 1/2 of 3V3.

            Int16 Count = 0;
            int MaxVib = 0;
            int An_Reading=0;
            while (true)
                // Sleep for 60 seconds
                //Get max. Many readings are required because if only one reading is taken then it probably will not be when the 
                //sensor is bent to the maximum. If the reading is taken at the exact wrong time then it might be busy swing 
                //form max + to max - and just at that moment be in the middle, then the reading will show zero.
                MaxVib = 0;
                for (Count = 0; Count < 1000; Count++)
                    //Get Analog Reading
                    An_Reading = AN.Read();

                    //Move negative values into positive range.
                    An_Reading = System.Math.Abs(An_Reading);

                    if (MaxVib < An_Reading)
                    {//Value read is bigger than current Max, set Max
                        MaxVib = An_Reading;

                if (MaxVib > 100)
                {//Too much vibration
                {//All OK




The first thing I would want to do is characterize the ‘vibration’.

Using accelerometers to find out what the frequency range of vibrations are likely to be seen on such equipment and to know exactly what you are looking for. Once you have an idea of the type of signal you are trying to capture then you can look at what other types of transducers might be useful in capturing the signal. With the accelerometer you can then calibrate your other sensor.


Many Thanks for all help received.

I will try it now



The vibration is what you would get from a piece of construction equipment, such as an excavator or a floor saw.
I want to pick up when it reaches a certain level and then react to that.

What would be nice is to be able to pick up when the level gets to a certain point and then start a timer and then stop it when it goes below it. The main thing is to record how long does it stay at that level for.



@ Floatingleaf: The vibration frequency can vary wildly.

For a caterpillar it might be the engine speed. Under 100Hz

For a jack hammer it would be the hammer speed. maybe 20Hz

For a table saw it would be the speed of the blade, times the number of teeth on the blade. At 18000rpm(300rps) and, say, 50 teeth, that would give you a frequency for 15000Hz. Hence the whine… :slight_smile:

You really need a spectrum analyzer to look at the frequency domain to know what you are measuring…


mm might be more than i actually want.

I only want to know if it is shaking/vibrating at a certain lvl


See, but that is the same as saying “I want to measure the weight of something”. Simple enough, use a scale.

But do you want to weight 1cu of hydrogen gas(lighter than air, but it still does have weight), a human, a car, a train, a building, a freight ship?

Vibration isn’t “just” vibration, just like weight isn’t “just” weight…


what if i just wanted to know that the sensor has detected something and not so much the level.
Ie when the machine is on and running.


Same question:
I want to know if there is something standing on my scale. :slight_smile:

If I design it to see if there is a car on the scale, then it will not detect a cat.
If I design it to see if a cat is on the scale then a car will break it.
Thus I need to know if I’m trying to detect a cat or a car.

In your case, if there isn’t enough vibration to excite the piezo enough to measure the signal directly then you will never see that the machine is running. In that case you must either amplify the signal or use a different sensor. On the other hand, if there is too much vibration then the sensor might provide a signal too big for the Panda, and blow it, or it might break the sensor in half.



I think it might be that is not picking it up accurately enough. Might need to be amplified…


Do you have an Oscilloscope? Maybe put the sensor on a scope and see what it gives you…


Hi All

On the Arduino you would open up a serial comms using the baud rate.
Is this why I cannot get this sensor to work correctly?
Would i be able to use the analog port using serial comms, in order to set the baud rate.
Would this be possible?

This link shows the sensor and the sample code for arduino



The sample code purely opens the serial port to allow the arduino to output the detected value back to a PC. That’s not part of the “sensor” at all.

What can’t you get to work? What actually happens, what actual code do you have??