44
1 Real-world Automation with Arduino Bob Igo [email protected] CPOSC 2012 Slides at http://bob.igo.name/?cat=21

Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

1

Real-world Automation with Arduino

Bob [email protected]

CPOSC 2012

Slides at http://bob.igo.name/?cat=21

Page 2: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

2

Problem 1: Crappy Garage Door Opener Reception

● My garage door can't hear either of our openers very well.– tried all basic troubleshooting steps

● Obvious next step:– make my house sense my car and open the

garage door

Page 3: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

3

Solution 1: Smart Garage Door Opener

● Requirements:

1: Know when I've driven away in a car.

2: Know when I've returned to the house.

3: Open the door when I've returned.

4: Prevent unauthorized usage.

Page 4: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

4

Final Physical Form

Page 5: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

5

Know when I've driven away in a car

● What happens on my Android phone when I've What happens on my Android phone when I've left the house in a car?left the house in a car?– GPS location changesGPS location changes– Speed > running/walkingSpeed > running/walking– WAP signal goes awayWAP signal goes away– Car bluetooth (usually) connectedCar bluetooth (usually) connected

Page 6: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

6

Know when I've driven away in a car

● What What cancan happen on my Android phone when I happen on my Android phone when I haven'thaven't left the house in a car? left the house in a car?– GPS location changesGPS location changes– WAP signal goes awayWAP signal goes away– Car bluetooth connectedCar bluetooth connected

Page 7: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

7

Know when I've driven away in a car

● Test for “left the house in a car“Test for “left the house in a car“– trigger: WAP signal goes awaytrigger: WAP signal goes away– test: GPS speed > 17.9 mphtest: GPS speed > 17.9 mph– pass: set AWAY=1pass: set AWAY=1

● Everything done in TaskerEverything done in Tasker

Page 8: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

8

Know when I've returned to the house

● Test for “returned to the house“Test for “returned to the house“– trigger: WAP signal appears trigger: WAP signal appears – test: AWAY == 1test: AWAY == 1

● Upon return, get a URLUpon return, get a URL● Everything done in TaskerEverything done in Tasker

Page 9: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

9

Know when I've returned to the house

● VZW-specific bugVZW-specific bug– In a call: can't associate with WAPIn a call: can't associate with WAP

Page 10: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

10

Open the door when I've returnedOpen the door when I've returned

● Requirements:Requirements:– I need something that runs a web serverI need something that runs a web server– wires between it and the garage door openerwires between it and the garage door opener– I need it to throw a switch (the opener)I need it to throw a switch (the opener)

● 5VDC, 1.5mA5VDC, 1.5mA

– + all the standard implicit requirements+ all the standard implicit requirements● Arduino can do all of that (with some help)Arduino can do all of that (with some help)

Page 11: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

11

Open the door when I've returnedOpen the door when I've returned

● Arduino + Ethernet ShieldArduino + Ethernet Shield– mini web server that can throw a relaymini web server that can throw a relay

● Android + TaskerAndroid + Tasker– gets the relevant URL when I've returned homegets the relevant URL when I've returned home

Page 12: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

12

Open the door when I've returnedOpen the door when I've returned

● Example Arduino web server does 99%Example Arduino web server does 99%– additional code:additional code:

● set the relay's control pin to OUTPUTset the relay's control pin to OUTPUT● when server responds, set pin HIGH for 500mswhen server responds, set pin HIGH for 500ms

Page 13: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

13

Prevent unauthorized usage

● Currently, WPA2 mostly does this– prevents anyone who lacks my WPA2 passphrase

from discovering the URL on my LAN● although it's

in myTasker task

Page 14: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

14

Prevent unauthorized usage

● Eventually– rolling codes as sub-URLs, synced between the

Arduino server and the phone

Page 15: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

15

Arduino Code

● Arduino IDE: Examples Ethernet Web Server→ →● Plus a relay controlled by Arduino pin 5:

– pinMode(5, OUTPUT);– void briefRelayThrow() {

digitalWrite(5, HIGH);

delay(500);

digitalWrite(5, LOW);}

Page 16: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

16

Arduino Code

● Add a call to briefRelayThrow() in loop(), after

client.println("HTTP/1.1 200 OK");

client.println("Content-Type: text/html");

client.println();

briefRelayThrow();

Page 17: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

17

Networking

● I couldn't do a wire run to the garage– no ethernet– no PoE

● I used a wireless bridge– Netgear WNCE2001– WAP WNCE2001 → →

ethernet shield

Page 18: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

18

Arduino Wiring Diagram

NOTE: No LED modeled

garage door opener

Page 19: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

19

Parts List

● Arduino Uno R3● Arduino Ethernet Shield R3● 5VDC SPST REED relay

– RadioShack #275-0232

● IN4004 rectifier diode– RadioShack #276-1103

● (optional Netgear WNCE2001)● (optional status LEDs and 1kOhm resistors)● smartphone (ideally, Android with Tasker)● protoboard, wires

Page 20: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

20

Tasker Side

● Seehttps://github.com/Human/igo-tasker

Page 21: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

21

Questions?

Page 22: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

22

Problem 2: Unaware Treadmill DeskProblem 2: Unaware Treadmill Desk

● When I'm working and walking, I want:When I'm working and walking, I want:– treadmill runningtreadmill running– AV receiver ONAV receiver ON– desktop apps runningdesktop apps running– fan ONfan ON

● Otherwise, I want the opposite.Otherwise, I want the opposite.

Page 23: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

23

Problem 2: Unaware Treadmill DeskProblem 2: Unaware Treadmill Desk

● Requirements:Requirements:

1: Determine if I am in walking position.1: Determine if I am in walking position.

2: Press several buttons without modding the 2: Press several buttons without modding the devices.devices.

3: Trigger workstation behavior based on my 3: Trigger workstation behavior based on my presence/absence on treadmill.presence/absence on treadmill.

4: Throw a relay to operate the fan.4: Throw a relay to operate the fan.

5: Provide a manual override.5: Provide a manual override.

Page 24: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

24

Current Physical Form

Page 25: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

25

Current Physical Form

Page 26: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

26

Current Physical Form

Page 27: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

27

Workstation Side

Page 28: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

28

Determine if I am in walking position

● sonic distance sensor– 15º Field of View (FoV)– accurate up to ~1 meter

Page 29: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

29

Press several buttons without modding the devices

● Need a transducerNeed a transducer– linear?linear?– rotary?rotary?

● Ultimately chose a servoUltimately chose a servo– a motor whose position you can requesta motor whose position you can request

● Servos are power-hungry for an ArduinoServos are power-hungry for an Arduino– minimize the physical resistance they encounterminimize the physical resistance they encounter– only fire one at a timeonly fire one at a time

Page 30: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

30

Trigger workstation behavior based on my presence/absence

on treadmill● Arduino's USB port is a serial interface

– send status output over serial to my workstation– read status with a daemon– react to status with a Sikuli script

Page 31: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

31

Throw a relay to run the fan

● 120VAC + relay + inductive load + solder = scary– I chose a pre-made Arduino-ready solution for

this

Page 32: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

32

Provide a manual override

● Position of the servos handles some of this– servo arm leaves room

Page 33: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

33

Provide a manual override

● One button enters override mode; the other re-enters automatic mode.– Red forces a “no walker present“ status and

disables distance sensor polling– Green re-enables distance sensor polling

Page 34: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

34

Provide a manual override

● Added a status LED to communicate override mode state.

Page 35: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

35

Arduino Code

● The DeskAttendant project utilizes several classes to toggle buttons and read from the distance sensor.

Page 36: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

36

Arduino Code

Page 37: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

37

Arduino Code

Page 38: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

38

Arduino Codevoid loop() { if (!manual_override) { distance_loop(); get_status_from_distance(); } else { new_status = walker_absent; }

process_status_loop(); override_button_loop();}

Page 39: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

39

Arduino Wiring Diagram (overview)

Page 40: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

40

Arduino Wiring Diagram (inputs)

Page 41: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

41

Arduino Wiring Diagram (status)

Page 42: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

42

Arduino Wiring Diagram (actions)

Page 43: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

43

Sources and Parts List

● See https://github.com/Human/DeskAttendant

Page 44: Real-world Automation with Arduino · Final Physical Form. 5 Know when I've driven away in a car ... – react to status with a Sikuli script. 31 Throw a relay to run the fan

44

Questions?