Vibration Detection Arduino Santiapps

Arduino Honduras Santiapps Marcio Valenzuela

Tutorial Detector de Vibraciones

Detectar Movimiento.  PiezoVibration.ino.

Requisitos:

  1. Computadora (mac)
  2. Arduino MEGA (u otra variante Arduino) o incluso Arduino clone, Edison, Raspberry…  Este tutorial en particular usa una Arduino MEGA.
  3. Piezo Vibration Sensor
  4. Breadboard
  5. Arduino IDE (https://www.arduino.cc/en/Main/Software)
Arduino Tutorial Piezo Vibración Detector de Movimientos Santiapps Marcio Valenzuela
Arduino Tutorial Piezo Vibración Detector de Movimientos

 

El código:

[code]
const int ledPin = 13; // led connected to digital pin 13
const int knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 100; // threshold value to decide when the detected sound is a knock or not
// these variables will change:
int sensorReading = 0; // variable to store the value read from the sensor pin
int ledState = LOW; // variable used to store the last LED status, to toggle the light
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
Serial.begin(9600); // use the serial port
}
void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading = analogRead(knockSensor);
// if the sensor reading is greater than the threshold:
if (sensorReading >= threshold) {
// toggle the status of the ledPin:
ledState = !ledState;
// update the LED pin itself:
digitalWrite(ledPin, ledState);
// send the string “Knock!” back to the computer, followed by newline
Serial.println(“Knock!”);
}
delay(100); // delay to avoid overloading the serial port buffer
}
[/code]

Ese proyecto se puede ver aquí:

Es todo!  Parece insignificante pero la base es importante.  Porque?  Pues los dejo con estas ideas:

  • Esa LED podría ser un motor o un cerrojo o una valvula de flujo
  • En lugar de repetir el ciclo cada segundo, podríamos controlar el flujo en cada ciclo agregando una condición, ie: Si un botón esta oprimido, o un sensor ( de luz, sonido, calidad de aire, temperatura, huella digital, código ingresado etc) cumplen con las condiciones requeridas para enviar esa corriente.
  • O que pasa si, en lugar de solo enviar corriente, mandamos o leemos datos?  A internet?  A un celular?  A un BT, NFC etc…

Allí es donde se pone interesante.  Nos vemos en el proximo donde controlaremos la LED usando botones y potenciometros y aprenderemos a leer electricidad, no solo escribirla!

Leave a Reply