ArduinoGeneral

Digital Vibration Sensor on Firebeetle esp32

userHead g.varelas 2018-09-06 03:19:35 6172 Views5 Replies
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
2019-03-14 19:01:55 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. userHeadPic ankulikova164
2018-09-07 01:43:46 thank you very much for the help maker, works fine now :) userHeadPic g.varelas
2018-09-06 11:18:55 Here are my test results userHeadPic makermuyi
2018-09-06 10:59:40 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.
userHeadPic makermuyi