160 likes | 928 Views
Arduino Tutorial 2: Secret Door Knock Detector. Agenda. Sensor Review MAKE: calibrate sensor PWM Motors MAKE: calibrate motor Validation algorithm MAKE: Secret Knock Detector Links. Serial Monitor: Serial.begin (9600) to start communication
E N D
Arduino Tutorial 2: Secret Door Knock Detector
Agenda Sensor Review MAKE: calibrate sensor PWM Motors MAKE: calibrate motor Validation algorithm MAKE: Secret Knock Detector Links
Serial Monitor: • Serial.begin(9600) to start communication • Serial.println(“msg”) to print to monitor Analog Review • Analog Arduino mapping: 0-5V 0 -1023 analogRead(pin) • Piezo: vibration sensor Generates voltage between its 2 leads Sensitive! Needs resistor in parallel
MAKE: Calibrate Sensor • Connect sensor to analog pin with 1M resistor in parallel • Open skeleton_sensor_calibrate • Use Serial Monitor to report value from sensor, find out minimum value produced by a knock THRESHOLD • Modify delay between readings so it won’t ignore two quick knocks or give you extra knocks DEBOUNCE CHALLENGE: • Add LED to indicate knock
Pulse Width Modulation • Duty cycle = percentage of time signal is positive in square wave • Min-Max voltage: 0 – 5v • Min-Max Arduino mapping: 0 – 255 • PWM pins have a ~ on Arduino 10% average 50% average 90% average
DC Motors • They draw more current than USB/Arduino can supply (40mA per pin) so need another power supply: batteries / wall-wart • Current through in 1 direction turns them in 1 direction 6v PWM • More voltage = More speed, control? • Use electronically controlled switch (transistor) between motor and batteries • Use PWM pin to control switch Motor
Servo Motors • Moves to desired position and stops, limited range of 180° in 2 directions • 3 wires: power = red ground = brown control = yellow • Control circuit + potentiometer + DC motor + position shaft with gears • Control signal uses PWM, pulse width = position
MAKE: Calibrate Motor • Connect Servo motor to PWM pin, power and ground • Open skeleton_motor_calibrate • Find “opened” and “closed” positions by sweeping shaft • **Don’t disconnect sensor, will use later! Servo Library • #include <Servo.h> • Create object • Object.attach(pin) • Object.write(position) *in degrees
MAKE: Secret Knock Detector • Secret knock is stored as array of time intervals • Validation logic: compare time intervals within allowed error • Start with skeleton_basic_door_knock, using serial monitor • When that works add servo movement instead of printing • Verify code with staff and try the BIG DOOR!
Useful Links Original Instructables project http://www.instructables.com/id/Secret-Knock-Detecting-Door-Lock/ MAKE projects http://makezine.com/arduino/ http://makezine.com/category/electronics/arduino/?post_type=projects Jeremy Blum Tutorials (#5: motors and transistors) http://www.jeremyblum.com/category/arduino-tutorials/
Questions? Comments? Suggestions? academics@ieee.concordia.ca ieee.concordia.ca