Example Code for Arduino-Vibration Detection

Detect the status of IO3 and print it in serial port

Hardware Preparation

Software Preparation

Wiring Diagram

Connection

Sample Code

/*!
 * @File  Infrared_Approach_Sensor.ino
 * @brief  Detect the status of IO3 and print it in serial port
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @licence  The MIT License (MIT)
 * @version  V1.0
 * @date  2021-03-15
 */
int  OUT = 4;
int  i = 0;
void setup()
{
  Serial.begin(9600);
  pinMode(OUT, INPUT);
}
void loop()
{
   i = digitalRead (OUT);
   Serial.println(i);
   delay(5);
}

Result

Read the IO3 status: when vibration detected, serial print 0, otherwise, serial print 1.

Result

Was this article helpful?

TOP