Digital Vibration Sensor on Firebeetle esp32
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 :
George
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
What is the problem? #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++;
}
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. ankulikova164
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. makermuyi
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. makermuyi