Customer:
I bought your vibration sensor module, but following your tutorial at https://e-radionica.com/hr/blog/2015/08/19/kkm-modul-sa-senzorom-vibracija/ it doesn’t work at all. I’ve tried both analog and digital input, so if you could provide example code or something similar that would help.
Original message (Croatian)
kupio sam vaš modul za detektiranje vibracije, ali prema vašem tutorijalu: https://e-radionica.com/hr/blog/2015/08/19/kkm-modul-sa-senzorom-vibracija/ nikako ne radi, probao sam i analog i digital input, pa ako može primjer koda ili sl.
Originally submitted via email support on 4 October 2017. Migrated to the forum for community visibility.
Soldered Support:
Can you describe or diagram how you’ve connected the sensor? Readings will always appear, even if nothing is connected to the pin.
Original message (Croatian)
trebamo znati kako ste spojili da bismo znali da je ispravno.. možete li nam napisati/opisati/nacrtati? Očitanja biste uvijek dobivali, čak i da niste ništa spojili na pin(probajte).
Customer:
The connection is very simple:
Sensor pins are:
- GND - connected to GND on the board
- A0 - not connected
- D0 - connected to digital pin 4 on the Arduino
- +5V - connected to +5V on the board
Here’s the code (I’m using Platformio plugin from atom IDE):
#include
const int vibration_sensor2 = 4;
void setup()
{
Serial.begin(9600);
pinMode(vibration_sensor2, INPUT); //vibration sensor
}
long current_value2 = 0;
void loop()
{
current_value2 = digitalRead(vibration_sensor2);
//current_value2 = analogRead(vibration_sensor2); //also doesn't work on analog input
Serial.println(current_value2); //prints 1 to serial monitor
}
//end
Instead of digitalRead I also tried using the function:
long TP_init(){
delay(10);
long measurement = pulseIn(vibration_sensor2, HIGH); //wait for the pin to get HIGH and returns measurement
return measurement;
}
but nothing.
I’ve now realized that the variable current_value2 returns 0 until I turn the potentiometer on the sensor to a certain angle, then it shows 1 and the LED on the sensor lights up. If I turn it back again it shows 0 again and the LED on the sensor goes out.
Original message (Croatian)
Spajanje je vrlo jednostavno: pinovi senzora su: gnd - spojeno na gnd od exp pločice, A0 - nije spojeno, D0 - spojeno na dig pin 4 od arduina, +5v - spojeno na +5v od exp pločice. Ovo je kod (koristim Platformio plugin iz atom IDE-a): #include const int vibration_sensor2 = 4; void setup() { Serial.begin(9600); pinMode(vibration_sensor2, INPUT); //vibration sensor } long current_value2 = 0; void loop() { current_value2 = digitalRead(vibration_sensor2); //current_value2 = analogRead(vibration_sensor2); //na analog inputu također ne radi Serial.println(current_value2); //ispisuje 1 u serial monitoru } //kraj Umjesto digitalRead probao sam i sa funkcijom: long TP_init(){ delay(10); long measurement = pulseIn(vibration_sensor2, HIGH); //wait for the pin to get HIGH and returns measurement return measurement; } ali ništa. Evo sad najnovije sam shvatio da varijabla current_value2 vraća 0 sve dok ne zakrenem potencimetar na senzoru do nekog kuta pokazuje 1 i ledica na senzoru zasvjetli. I ako opet vratim natrag pokazuje opet nulu i ledica na senzoru se ugasi.
Soldered Support:
First, the sensor must be positioned upright (as shown in the picture). If it’s horizontal, it will be active the whole time.
Second, A0 in combination with this sensor makes no sense - it’s the same as the digital output.
Most importantly, the sensor only gives a signal at the moment of vibration! Which means that signal is very short! So it would be better to use an interrupt, but if you’re a beginner, this will work:
//excerpt from loop
if(digitalRead(vibration_sensor2) == HIGH){
//whatever you want to happen when the sensor activates
}
Original message (Croatian)
za početak, senzor mora biti postavljen uspravno(kao na slici). Ako je vodoravno, cijelo vrijeme će biti aktivan. Druga stvar je da A0 u kombinaciji s ovim senzorom nema nikakvog smisla - tj. jednak je kao i digitalni izlaz. I ono najvažnije, senzor daje signal samo u trenutku vibracije! Što znači da je taj signal jako kratak! Dakle bolje bi bilo koristiti interrupt, ali ako ste početnik, i ovo će raditi: //isječak iz loop-a if(digitalRead(vibration_sensor2) == HIGH){ //nešto što želite da se napravi kada se senzor aktivira }
Customer:
Thanks for the information, it works now. What’s the potentiometer for?
Original message (Croatian)
Hvala na info, sada radi, a zašto služi potenciometar?
Soldered Support:
It adjusts the threshold at which the digital output will activate. It doesn’t really make sense for a vibration sensor, since the output is either 0V or 5V. For some other sensors (light, Hall effect) it has a purpose.
Original message (Croatian)
služi za podešavanje praga na kojemu će se aktivirati digitalni izlaz. Nema baš smisla za senzor vibracije, jer daje kao izlaz ili 0V ili 5V. Za neke druge senzore(svjetlosti, hall effect) ima svrhu.