Friday, 8 April 2011

The Arduino Doorbell - Part 2 Software!

Firstly, here is the final Arduino code that I am using, its as best to perfect as I can get at present with only one real hiccup.

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 < 200) { // if the circuit is completed
// (for me, it generally drops from 1023 to ~ 15 when 'ringing')
if (millis()-time > debounce) {
Serial.println("ON");
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // ...wait for 2 seconds
digitalWrite(ledPin, LOW); // and turns the LED off
time = millis();
}
}
}

I cannot take credit for this code please see this post http://rooreynolds.com/2008/05/14/hacking-the-doorbell/ for the original code, I have just modified aspects to suit my needs.

What this will do is when the button is pushed, it will light the test LED and send the "ON" text via the arduino to your pc's com port.



Now the hardest part! I have yet to find anyone who has done this hardware setup with a windows machine and wanting to use growl/prowl, the closest I could find was this post http://www.grantgibson.co.uk/blog/index.php/2009/03/29/putting-doorbell-online/as this guy is using a windows machine but is using a web function as a notification.

So now I have a base to use in ActivePerl as my listen and trigger code, now I wanted to run the command C:\Program Files\Growl for Windows\Growlnotify "There is someone at the door" as a dos command instead of the 'http://your action here' command.

Here is my Perl code:

use Win32::SerialPort;
use LWP::Simple;
my $port = Win32::SerialPort->new ("COM3");
$port->databits(8);
$port->baudrate(19200);
$port->parity("none");
$port->stopbits(1);

my $count = 0;

while (1) {
my $char = $port->lookfor();

if ($char) {
$char = substr $char, 0, 2;
print " Doorbell status: " . $char . " \n";
if ($char eq "ON") {
print "Doorbell is on \n";
system 'C:\growlnotify "There is someone at the Door"';
}
}
sleep(1);
}

Note: I have removed the bottom part of Grant's code as it wasnt needed for this application, then I changed the http line, to the system command, however this is the first time consuming problem, the command will not run from a folder that has a space in the name i.e Program Files therefore I had to copy the growlnotify.exe to the root directory and run it directly from C:\.

The text following the growlnotify command can be changed to anything you wish.

Note 2: Dont try and run the perl code with the arduino software open, as you will get an error as the com port is in use by the arduino software.

Note 3: Perl when installed doesnt tell you this but you need to reboot the machine in order to set the path variable to enable perl to run directly from any command line, test by using the command c:\perl -v this should return details about the perl version, if it doesnt you will need to do some troubleshooting.

Then all that needs doing is to set up growl and prowl, this will involve buying the prowl app, setting an API key, and modifing your growl settings all of which are fairly easy and there is plenty of info on the web.

That should be about it, set your hardware up, flash with code, set up perl, run perl doorbell.pl from your command line and push the button!



33 comments:

  1. led deck lights very nice blog you have written dear author i like your blog about led technology so carry on dear for further improvement

    ReplyDelete
  2. train horn Horns have a great importance on rail road crossings and railway station. Most of the train horns work similarly which basically the horn is oscillating, and create sound wave. very nice blog i have found here to read and to get information about horns so i would like to thank you for sharing it with us

    ReplyDelete
  3. Sean
    Any chance you wold be willing to make on of these for me? I'm willing to pay for the service and parts

    ReplyDelete
  4. Thanks for sharing. I don't have any experience with perl ,but maybe it's time to learn :)

    reading your elaborated post, I have but one question:
    will the growl/prowl solution work over the web as well, or only in the homegroup network?

    Thanks :-)

    ReplyDelete
    Replies
    1. I am replying to my own question in order to let the other interested readers that it actually does work over the internet, which is great!

      Thanks :)

      Delete
  5. These look great shining up from my handrails up stairs. Great subdued light effects

    ReplyDelete
  6. I agree with you that doorbell is good for our security purpose. Thanks for sharing this great post.

    Reliable Chimes

    ReplyDelete
  7. This is a amazing inspiring composition.I am gorgeous plenty pleased among your salubrious process.You put truly really cooperative info.limo rental Jersey City

    ReplyDelete
  8. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.70s Costumes

    ReplyDelete
  9. The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.onlinegevonden.com

    ReplyDelete
  10. The only exception is that we unfortunately have had to hold on to some related source code that uses proprietary code from 3-partys. However none of thus are essential, and binaries are made freely available for most of it. A list of non-released code is available at.recreation.tips

    ReplyDelete
  11. Once in Los Angeles he studied beneath the fabulous Stella Adler plus mood mime Jeff Corey. Hellos initial acting vacancy was active beside Steven Spielberg as the Pizza Human in E.T. Stretch in LA he continued to thing on TV moreover Movie. Today, he houses in Roseland Recent Jersey, acting besides filmmaking in the tri-commonwealth locale.Drug Possession Attorney West Palm Beach

    ReplyDelete
  12. Once I thought about things like: why such information is for free here? Because when you write a book then at least on selling a book you get a percentage. Thankfree prepaid credit cards

    ReplyDelete
  13. Higher efficiency means less energy consumption. Less energy consumption means lower costs and less pollution.native american drums

    ReplyDelete
  14. Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.goose feathers

    ReplyDelete
  15. exactly traditional; they include items like Asian-style vegetables and peanut sauce, but such crazy-quilt combos all somehow work very welexactly traditional; they include items like Asian-style vegetables and peanut sauce, but such crazy-quilt combos all somehow work very wel exactly traditional; they include items like Asian-style vegetables and peanut sauce, but such crazy-quilt combos all somehow work very welexactly traditional; they include items like Asian-style vegetables and peanut sauce, but such crazy-quilt combos all somehow work very wel exactly traditional; they include items like Asian-style vegetables and peanut sauce, but such crazy-quilt combos all somehow work very welexactly traditional; they include items like Asian-style vegetables and peanut sauce, but such crazy-quilt combos all somehow work very welred bow tie

    ReplyDelete
  16. I don't want to make this personal, but this is a thread so deeply flawed that it should be censored. But male enhancement products , you say? That might be a bit too much. Clear? I can recommend some wonderful English Comprehension courses that would help you.red bow tie

    ReplyDelete
  17. No any life in this world which would be safe from the period of declination in his life as every person in this world have to face some bitter experience in his life but the best one is the one who seeks positive lesson from his problems.compare conveyancing

    ReplyDelete
  18. Its like you read my mind! You seem to know so much about this,like you wrote the book in it or something. I think that you could do with some pics to drive the message home a bit, but other than that, this is great blog thisschwimmbadüberdachungen

    ReplyDelete
  19. The next time I read a blog, I hope that it doesn’t disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought you would have something interesting to say.conveyance fee

    ReplyDelete
  20. I read your excellent post. I really appreciate your post. Thanks a lot for share this interesting post.Honeymoon

    ReplyDelete
  21. Thanks a lot for sharing us about this update. Hope you will not get tired on making posts as informative as this.Compare Money Transfer

    ReplyDelete
  22. I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me.prepaid cards

    ReplyDelete
  23. That was bit funny conversation. I could get an interesting topic to read through this article. Thanks for the share about the scrambled eggs.penis enhancement spells

    ReplyDelete
  24. This is just the information I am finding everywhere. Thanks for your blog, I just subscribe your blog. This is a nice blog.lawveritas.com

    ReplyDelete
  25. Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me.Janitorial cleaning companies

    ReplyDelete
  26. There are some factors that you will need to know before you start taking any penis enlargement pills. When you are taking the pill, you will need to ensure that you drink plenty of water.professional cleaning services

    ReplyDelete
  27. I’m happy I located this blog! From time to time, students want to cognitive the keys of productive literary essays composing. Your first-class knowledge about this good post can become a proper basis for such people.web room booking

    ReplyDelete
  28. Its like you read my mind! You seem to know so much about this,like you wrote the book in it or something. I think that you could do with some pics to drive the message home a bit, but other than that, this is great blog this.escort paris

    ReplyDelete
  29. Traveling is not just about fun and looking for a moment will never be forgotten. But more to learn thank favors God has given us.Lipo battery

    ReplyDelete
  30. Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to meconference room scheduling software

    ReplyDelete
  31. That's what makes you the best. You should keep publishing more articles and you will Such Become One of the best writers ever.Ryanair

    ReplyDelete