1

I am able to detect a vibration when I am using 801s vibration sensor module sensor

How to measure and print the amount of vibration level on the screen in C? I am checking now only state: HIGH and LOW. I am using a digital signal not analog signal so my question is, can I use this type of signal in this sensor to display the value of vibration or we can't. How to retrieve the data from this sensor in C, value not only states high or low.

I am playing with the code from this video project

#include <wiringPi.h>
#include <stdio.h>
#define VibratePin 0
#define Gpin 1
#define Rpin 2
int tmp = 0;
void LED(int color)
{
pinMode(Gpin, OUTPUT);
pinMode(Rpin, OUTPUT);
if (color == 0)
{
digitalWrite(Rpin, HIGH);
digitalWrite(Gpin, LOW);
}
else if (color == 1)
{
digitalWrite(Rpin, LOW);
digitalWrite(Gpin, HIGH);
}
else
printf("LED Error");
}
void Print(int x){
if (x != tmp){
if (x == 0)
printf("Vibration Detected:  .......Device1 On\n");
if (x == 1)
printf("Vibration Detected:  Device2 On........\n");
tmp = x;
}
}
int main(void)
{
int status = 0;
int tmp = 0;
int value = 1;
if(wiringPiSetup() == -1){ //when initialize wiring failed,print messageto screen
printf("setup wiringPi failed !");
return 1;
}
pinMode(VibratePin, INPUT);

while(1){
value = digitalRead(VibratePin);

while(1){
value = digitalRead(VibratePin);
if (tmp != value){
status ++;
if (status > 1){
status = 0;
}
LED(status);
Print(status);
delay(1);
}
}
return 0;
}
0

1 Answer 1

3

The Raspberry Pi does not have any analog input PINs. Thus you will not be able to interpret analog input signals without some additional hardware.

In order to be able to read not only HIGH or LOW levels from your sensor, you need to use an analog-to-digital converter (ADC), e.g. in the form of a ADC-HAT extension for the Rasperry Pi. Then you can connect the analog output pin of your sensor A0 to the ADC and read in the analog input level.

7
  • Which ADC converter will be the best solution for R Pi 4B?
    – tellarwind
    Commented Oct 25, 2019 at 21:13
  • If I connect ADC I will be able to interpret an amount of vibration with 801s vibration sensor.
    – tellarwind
    Commented Oct 25, 2019 at 21:23
  • Is not the better option to buy Arduino?
    – tellarwind
    Commented Oct 25, 2019 at 21:33
  • sure, arduino or e.g. nodemcu or any dev board with analog Input will work for you.
    – oh.dae.su
    Commented Oct 25, 2019 at 21:35
  • Note there does appear to be a D0 on the sensor from the question, so an ADC may not be necessary.
    – goldilocks
    Commented Oct 27, 2019 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.