arduino tutorial 2: secret door knock detector. agenda 1.sensor review 2.make: calibrate sensor...

11
Arduino Tutorial 2: Secret Door Knock Detector

Upload: douglas-morgan

Post on 21-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Arduino Tutorial 2: Secret Door Knock Detector. Agenda 1.Sensor Review 2.MAKE: calibrate sensor 3.PWM 4.Motors 5.MAKE: calibrate motor 6.Validation algorithm

Arduino Tutorial 2:Secret Door Knock Detector

Page 2: Arduino Tutorial 2: Secret Door Knock Detector. Agenda 1.Sensor Review 2.MAKE: calibrate sensor 3.PWM 4.Motors 5.MAKE: calibrate motor 6.Validation algorithm

Agenda

1.Sensor Review2.MAKE: calibrate sensor3.PWM4.Motors 5.MAKE: calibrate motor6.Validation algorithm7.MAKE: Secret Knock Detector8.Links

Page 3: Arduino Tutorial 2: Secret Door Knock Detector. Agenda 1.Sensor Review 2.MAKE: calibrate sensor 3.PWM 4.Motors 5.MAKE: calibrate motor 6.Validation algorithm

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

• Serial Monitor:Serial.begin(9600) to start communicationSerial.println(“msg”) to print to monitor

Page 4: Arduino Tutorial 2: Secret Door Knock Detector. Agenda 1.Sensor Review 2.MAKE: calibrate sensor 3.PWM 4.Motors 5.MAKE: calibrate motor 6.Validation algorithm

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

Page 5: Arduino Tutorial 2: Secret Door Knock Detector. Agenda 1.Sensor Review 2.MAKE: calibrate sensor 3.PWM 4.Motors 5.MAKE: calibrate motor 6.Validation algorithm

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

Page 6: Arduino Tutorial 2: Secret Door Knock Detector. Agenda 1.Sensor Review 2.MAKE: calibrate sensor 3.PWM 4.Motors 5.MAKE: calibrate motor 6.Validation algorithm

DC Motors

Current through in 1 direction turns them in 1 direction

More voltage = More speed, control?Use electronically controlled switch (transistor)

between motor and batteriesUse PWM pin to control switch

• They draw more current than USB/Arduino can supply (40mA per pin) so need another power supply: batteries / wall-wart

Motor

PWM

6v

Page 7: Arduino Tutorial 2: Secret Door Knock Detector. Agenda 1.Sensor Review 2.MAKE: calibrate sensor 3.PWM 4.Motors 5.MAKE: calibrate motor 6.Validation algorithm

Servo Motors

Control signal uses PWM, pulse width = position

3 wires: power = red ground = brown control = yellow

• Moves to desired position and stops, limited range of 180° in 2 directions

• Control circuit + potentiometer + DC motor + position shaft with gears

Page 8: Arduino Tutorial 2: Secret Door Knock Detector. Agenda 1.Sensor Review 2.MAKE: calibrate sensor 3.PWM 4.Motors 5.MAKE: calibrate motor 6.Validation algorithm

Servo Library

MAKE: Calibrate Motor

• #include <Servo.h>• Create object• Object.attach(pin)• Object.write(position) *in degrees

• 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!

Page 9: Arduino Tutorial 2: Secret Door Knock Detector. Agenda 1.Sensor Review 2.MAKE: calibrate sensor 3.PWM 4.Motors 5.MAKE: calibrate motor 6.Validation algorithm

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!

Page 10: Arduino Tutorial 2: Secret Door Knock Detector. Agenda 1.Sensor Review 2.MAKE: calibrate sensor 3.PWM 4.Motors 5.MAKE: calibrate motor 6.Validation algorithm

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/

Page 11: Arduino Tutorial 2: Secret Door Knock Detector. Agenda 1.Sensor Review 2.MAKE: calibrate sensor 3.PWM 4.Motors 5.MAKE: calibrate motor 6.Validation algorithm

[email protected]

Questions? Comments? Suggestions?