Step 10: The (Hard) Hardware

Picture of The (Hard) Hardware
Now I am a hardware kinda guy, really that is where talent lies. If you look at any of my past 'structables you see I love to tinker. However, this was my first time using a Arduino, and, like a newbie, I ordered one, plugged it in, loaded the software and fainted. Well, not exactly fainted, but felt like I’d been thrown back in time to my first foray with a soldering iron when I worried I was about to burn myself, the project I was working on, followed by incinerating my house!

THIS helped me get started.

The basic logic of the program was this:

Someone pushes the doorbell, It activates a relay that rings the doorbell and activates the Arduino.

The Arduino then:

1) Ignores all activation commands for 4 mins (in case someone rings the doorbell again)
2) Starts a Applescript command on the host Mac computer
3) Activates a second relay (for future ideas)
4) Resets after 4 mins, and goes back to stand-by

Here is the code:

int ledPin = 13; // LED connected to digital pin 13
int potPin = 0; // white doorbell wire to analog pin 0
int val = 0;

long time = 0;

long debounce = 1000;

void setup() {
pinMode(ledPin, OUTPUT); // sets the digital pin as output
Serial.begin(9600); // open serial port at 9600 baud
digitalWrite(14 + potPin, HIGH); // set pullup on the analog pin
// (analog 0 = digital 14, a1 = d15, etc)

void loop() {
val = analogRead(potPin);
if (val < 100) { // if the circuit is completed
// (for me, it generally drops from 1023 to ~ 15 when 'ringing')
if (millis()-time > debounce) {
digitalWrite(ledPin, HIGH); // sets the LED on
delay(120000); // ... 240000 = 4 mins
digitalWrite(ledPin, LOW); // and turns the LED off
time = millis();

NOTE: The Appleshare Proxy program was only accepting every third "A" from my Arduino, so I send three and the board now responds instantly without error (I am sure it's sloppy code, but HEY it works!) The 'delay' is where the board ignores all key presses, so the program does not restart if someone keeps ringing the doorbell.