Page 1 of 1

Digital Vibration Sensor on Firebeetle esp32

Unread postPosted:Wed Sep 05, 2018 7:19 pm
by g.varelas
Hi,
Im trying to test the DFRobot Digital Vibration Sensor (SKU:DFR0027) on the firebeetle esp32. I have connected sensor to D2, GND and 3V3 and have uploaded the code from sensor page but nothing is displayed in serial monitor and no led light.
Code is :
Code: Select all
#define LED_PIN D9
#define SensorINPUT  2
unsigned char state = 0;

void setup() {
  pinMode(LED_PIN, OUTPUT);
  pinMode(SensorINPUT, INPUT);
  //Trigger the blink function when the falling edge is detected
  attachInterrupt(1, blink, FALLING);
}

void loop() {
  if (state != 0) {
    state = 0;
    digitalWrite(LED_PIN, HIGH);
    Serial.println("Shock Alarm");
    delay(500);
  }
  else
    digitalWrite(LED_PIN, LOW);
  Serial.println("no alarm");
}

//Interrupts function
void blink() {
  state++;
}
What is the problem?

George

Re: Digital Vibration Sensor on Firebeetle esp32

Unread postPosted:Thu Sep 06, 2018 2:59 am
by makermuyi
Hi。
I'm maker.
I am very happy to work with you to solve this interesting problem.
According to your description of the problem. Itested it basedon your code.Because you program in the way of interrupts in your project.Normally you should use digitalPInTolnterrupt(pin) to translate the actal digital pin tothe specialfic interrupt number.
Syntax:
attachInterrupt(digitalPinToInterrupt(pin), ISR, mode);
For example, if you connect to pin D2 , use digitalPinToInterrupt(D2) as first parameter of attachInterrupt function.
My code is:
#define LED_PIN D9
#define SensorINPUT D2
unsigned char state = 0;

void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(SensorINPUT, INPUT);
Serial.begin(115200);
//Trigger the blink function when the falling edge is detected
attachInterrupt(digitalPinToInterrupt(D2), blink, FALLING);
Serial.println("Initlalize successfully!");
}

void loop() {

if (state != 0) {
state = 0;
digitalWrite(LED_PIN, HIGH);
Serial.println("Shock Alarm");
delay(500);
}
else
digitalWrite(LED_PIN, LOW);
Serial.println("no alarm");
}

//Interrupts function
void blink() {
state++;
}
Hope help you.

Re: Digital Vibration Sensor on Firebeetle esp32

Unread postPosted:Thu Sep 06, 2018 3:06 am
by makermuyi

Re: Digital Vibration Sensor on Firebeetle esp32

Unread postPosted:Thu Sep 06, 2018 3:18 am
by makermuyi
Here are my test results

Re: Digital Vibration Sensor on Firebeetle esp32

Unread postPosted:Thu Sep 06, 2018 5:43 pm
by g.varelas
thank you very much for the help maker, works fine now :)

Re: Digital Vibration Sensor on Firebeetle esp32

Unread postPosted:Thu Mar 14, 2019 11:01 am
by ankulikova164
The DFRobot Vibration Sensor buffers a piezoelectric transducer that responds to strain changes by generating a measurable output voltage change which is propotional with the strength of vibration tutuapp.