Presentation Slides

Arduino Tutorial 2:
Secret Door Knock Detector
1.Sensor Review
2.MAKE: calibrate sensor
5.MAKE: calibrate motor
6.Validation algorithm
7.MAKE: Secret Knock Detector
Analog Review
• Analog Arduino mapping: 0-5V  0 -1023
• Piezo: vibration sensor
Generates voltage between its 2 leads
Sensitive! Needs resistor in parallel
• Serial Monitor:
Serial.begin(9600) to start communication
Serial.println(“msg”) to print to monitor
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
• 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
More voltage = More speed, control?
Use electronically controlled switch (transistor)
between motor and batteries
Use PWM pin to control switch
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.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
MAKE projects
Jeremy Blum Tutorials (#5: motors and transistors)
Questions? Comments? Suggestions?
[email protected]