Can I adjust input trigger sensitivity? ESP32

#1

Hi all,

I’m messing around with some vibration sensors like these, and I’ve wired them up as per the suggestions in the link.

I’ve got a basic scope and can see that the devices are operating as expected, there is a very short positive pulse (shorter than seen in the link), but the vibration doesn’t seem to get registered on my ESP32.

My code looks like:

mgos_gpio_set_button_handler(4, MGOS_GPIO_PULL_DOWN, MGOS_GPIO_INT_EDGE_POS, 10, vibration_low_cb, NULL);
mgos_gpio_set_button_handler(0, MGOS_GPIO_PULL_DOWN, MGOS_GPIO_INT_EDGE_POS, 10, vibration_high_cb, NULL);

I’ve had a look around and haven’t found anything about using these with ESP32, so I was wondering if there was maybe some other ideas or some way to adjust trigger sensitivity of registering a HIGH on an IO pin.

#2

I assume you have two sensors connected to Vdd on GPIOs 4 and 0, and you are providing current for them through an internal pull-down resistor in the chip.
When the sensor detects some vibration it closes the circuit causing the voltage at the pin to rise to near Vdd for a moment, while it normally rests at a voltage near GND.
Assuming those two voltage levels are above the minimum level required to be considered a logic 1 and bellow the maximum accepted to be considered a logic 0, respectively, and that those pins can in fact be configured to be positive edge triggered interrupts, then as long as the pulses are longer than the shortest pulse duration required to trigger an interrupt, it will work.
Those are all datasheet values and there is nothing you can change.
Otherwise, you’ll have to trigger a flip-flop or a monostable or work with some required current through the sensor to guarantee some operation conditions; and feed the ESP32 with that.

#3

When I was testing the device it didn’t seem to operate like a switch, what I saw was when the circuit closed it actually had a resistance of 5-10k (hard to test) and O.C when not vibrating.
Based on that I’ve got 3.3v hooked to one side of the sensor, and the other side of the sensor hooked directly to GPIO0/4.

I think this is functioning, with a basic scope I was seeing ~3v when vibrating the sensor, but it was a VERY short pulse high.

#4

“very short” is a subjective concept.
Usually interrupts are internally synchronized via two flip-flops and those beasts require a hold time in the order of the ns. In worst cases a couple of CPU clocks are required, but we are talking about a >100MHz CPU. I don’t think your problem lies on that department.
I would properly amplify and condition those signals, feed a comparator with hysteresis for example, make sure you have a clear and defined pulse, sometimes edge interrupts are not triggered by ‘diffuse’ pulses.
If the sensor has an on-resistance around 10K and the pull-down current “looks like” a 20K resistor you might not get a logic ‘1’ on that resistor divider.

#5

ohhh great point! Hadn’t thought of that!