CTY SAR FCPS Shawn Lupoli, Elliot Tan Arduino Knock Lab CTY SAR FCPS Shawn Lupoli, Elliot Tan
What are we working with?
How to detect a physical Knock? A Piezo element can be used to detect vibration, which is produced by our knock. Piezo is an electronic device which generates a voltage when it is physically deformed by a vibration, sound wave or mechanical strain Can also put a voltage across a piezo piezo will vibrate and create a tone If the sensors output is stronger than a certain threshold, the Arduino will be knocked
Arduino Knock Schematic
Goal When we “Knock” the piezo element The LED will flash “Knock!” will be printed to the Serial Monitor
Programming “Knock”
Knock: Part 1 Initializing global variables Setup() The LED will be connected to pin 13 The piezo is connected to analog pin 0 (A0) Threshold value = 1 A variable to store the sensor reading A variable to store the last LED status Setup() pinMode(pin, mode) configures the pin to behave either as an input or an output Serial.begin(9600) starts using the Serial Port
Knock: Part 2 Loop() Read the sensor using analogRead() If the sensor reading is greater than the threshold turn on the light update the LED pin using digitalWrite() Send string back to the computer’s Serial Monitor Add in a delay to avoid overloading the serial port buffer
CODE
Building the Knock circuit
Supplies 1 Arduino Leonardo board 1 breadboard 3 short wires (two black, one red) 1 medium wire (red) 2 long wires (two black) 1 LED 1 resistor (1 MΩ) 1 piezo element * Notes: Wires are 22 or 24 AWG, solid Short wires = 5 cm Medium wires = 12 cm Long wires = 16 cm
Diagram of Knock Circuit
Running and reading output Run the program as normal, but open the Serial monitoring window for the Analog port.
Questions?