What Will I Learn?
- You will learn what a Knock Impact sensor (KY-031) is.
- You will learn how the sensor works and how to use it with the arduino uno board.
- You will learn the programming code used to make this sensor work.
Requirements
- Arduino Uno
- Knock Impact sensor (KY-031)
- LED
- Resistor (220 ohms)
- Breadboard
- Jumper Wires
- USB type A to B cable
- Computer
Software
- Arduino Software/ Arduino IDE
Knowledge
- Basic electronics and programming
Difficulty
- Basic
Project description
- This project uses a Knock Impact sensor (KY-031) that is connected to the arduino uno board. The KY-031 knock sensor is set to be the input device and detect shock in the area while the LED will be the output device to indicate the status of the sensor. Once shock has been identified it will then send a HIGH signal to the arduino uno board then turns the LED on.
Component description
Arduino Uno - is a type of arduino board that is commonly by specialist and hobbyist because of its robust design. It is equipped with a microcontroller board that is based on ATMega328P with 14 advanced I/O pins (6 are PWM outputs), 6 analog inputs, 16 Mhz quartz crystal, a power jack, a USB port, an ICSP header and a reset button.Reference
Knock Impact sensor (KY-031) - is a device that is capable of detecting shock or vibration in the area. It is a great alternative for the SW-420 vibration sensor. It consists of a spring sensor that will detect the vibration,a pull up resistor and three header pin that is allocated for the VCC (+5 Volts), GND (Ground) and S (Signal).
Tutorial Contents
Step 1: Gather the Parts
- You can get the components in your nearby electronics shop or you can go ahead and order it online.
Step 2: Construct the Circuit
Connect the Sources
Connect the 5V pin of the arduino uno board into the top/bottom slot of the breadboard. The connections here are horizontally connected making it an ideal for the sources.
Connect the GND pin of the arduino uno board into the top/bottom slot of the breadboard but make sure not to place them together to avoid shorting the arduino board.
Connect the LED
- Connect the Anode(+) of the LED to a 220 ohm resistor that is connected to pin 2 of the arduino uno board. This resistor will protect the LED from over supply of current.
- Connect the Cathode(-) of the LED to the common ground.
Connect the Sensor
- Connect the VCC(+) pin of the knock sensor to the voltage source in the breadboard.
- Connect the GND(-) pin of the knock sensor to the common ground in the breadboard.
- Connect the S(signal) pin of the knock sensor to pin number 3 of the arduino uno board.
Step 3: Programming
- Connect the arduino uno board to the computer using the USB type A to B cable.
- Once connected, open the Arduino IDE and click Tools > Board: > then select the Arduino/Genuino Uno.
- Copy the code below into your sketch in the arduino IDE.
int ledPin = 2 ;//declares the LED @pin 2
int knockPin = 3; //declares the Knock sensor @pin 3
int value; //defines the variable value
void setup ()
{
pinMode (knockPin, INPUT) ; //sets the sensor as INPUT
pinMode (ledPin, OUTPUT) ; //sets the LED as the OUTPUT
}
void loop ()
{
value = digitalRead (knockPin) ; //value will read the status of the knock sensor
if (value == HIGH) //if it reads a HIGH value
{
digitalWrite (ledPin, HIGH); //the LED will turn on
delay(5000); //duration of 5 seconds
}
else //otherwise
{
digitalWrite (ledPin, LOW); //the LED is turned off
}
}
1st code block: Declares the variables of the sensor and the LED.
int ledPin = 2 ;//declares the LED @pin 2
int knockPin = 3; //declares the Knock sensor @pin 3
int value; //defines the variable value
2nd code block: In the setup function it sets the knock sensor as the input while the LED as the output.
void setup ()
{
pinMode (knockPin, INPUT) ; //sets the sensor as INPUT
pinMode (ledPin, OUTPUT) ; //sets the LED as the OUTPUT
}
3rd code block: In the loop function it sets the 'value' to read the status of the knock sensor. If it reads a HIGH value it will turn the LED on. Otherwise, the LED is turned off.
void loop ()
{
value = digitalRead (knockPin) ; //value will read the status of the knock sensor
if (value == HIGH) //if it reads a HIGH value
{
digitalWrite (ledPin, HIGH); //the LED will turn on
delay(5000); //duration of 5 seconds
}
else //otherwise
{
digitalWrite (ledPin, LOW); //the LED is turned off
}
- After typing the code in your sketch in the arduino IDE, click the Verify button to save it and start compiling the sketch. This will also check for any errors in the program.
- Once saved and no errors are found, click the Upload button to start installing the program into the arduino uno board.
Step 4: Testing
- After the programming is done, remove the arduino uno board from the computer and connect it with a 9 volts battery pack to power up the device.
- Now, knock/shock the area around the sensor, this should make the LED turn on for 5 seconds because the sensor will detect the vibration in the surrounding and the LED is indicating the sensors status.
- Now stop knocking the area, the LED should be turned off to indicate that the sensor is not detecting any vibration in the surrounding.
Curriculum
Check out my other arduino tutorials below:
- Arduino 101: Using a Sharp IR sensor (analog) (GP2Y0A21)
- Arduino 101: Using a KY-036 metal touch sensor
- Arduino 101: Using a Flame sensor module
- Arduino 101: Using a Capacitive Touch sensor to control an LED
- Arduino 101: Using a Reed switch
- Arduino 101: Using a Force sensitive resistor to adjust an LED
- Arduino 101: Using a Gas sensor module
- Arduino 101: Controlling a solenoid lock
- Arduino 101: Alcohol sensor circuit using MQ-3 module
- Arduino 101: Using 2 ultrasonic sensors and servo motor
- Arduino 101: Automated parking gate circuit using ultrasonic and servo motor
- Arduino 101: Motion activated Servo motor with Arduino
- Arduino 101: PIR based burglar alarm with Piezoelectric buzzer and Arduino
- Arduino 101: Tilt Sensor with Arduino
- Arduino Shields
- Arduino for beginners
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you very much👍
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
yhaya
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @creon, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Following you!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @ted7 I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit