Arduino Knock Lab CTY SAR FCPS SHAWN LUPOLI
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 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 The LED will be connected to pin 13 The piezo is connected to analog pin 0 (A 0) Threshold value = 1 A variable to store the sensor reading A variable to store the last LED status Setup() pin. Mode(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 If the sensor using analog. Read() the sensor reading is greater than the threshold turn on the light update Send Add the LED pin using digital. Write() string back to the computer’s Serial Monitor in a delay to avoid overloading the serial port buffer
CODE
Building the Knock circuit
Supplies 1 Arduino Leonardo board * Notes: 1 breadboard v Wires are 22 or 24 AWG, solid v Short wires = 5 cm v Medium wires = 12 cm v Long wires = 16 cm 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
Diagram of Knock Circuit
Running and reading output Run the program as normal, but open the Serial monitoring window for the Analog port.
Questions?
- Slides: 14