loading
Christmas is coming closer, so here is my contribution to put you in the right mood. It is a blog hitcounter, that rings a bell. Literally. It puts a smile on your face, every time someone hits your blog.

It consists of an Arduino board, a bell, a servo and a couple of lines of code in c, python and php. Most parts are fairly common and should be easy to get.


Step 1: Tools and Materials

So what is needed?

  • Arduino Board. I got an Arduino Diecimila from Adafruits. In the meantime there are really cheap and handy clones out there, e.g. the really bare bone board from Modern Devices, especially if you want to use them on a breadboard.
  • A servo motor. Any servo will do. I took an old one that was used in my former hobby.
  • A bell. Preferably one that is small enough to shake it with the servo.
  • Two paperclips. A large one to hold the bell and a small one to build the actuator to ring the bell.
  • Wires to connect the servo with the Arduino.
  • A website. In fact it has not to be a website or a blog. Actually everything that can be counted, will work.
  • A PC or a Mac to connect the Arduino board with the blog or website.
You may need an soldering iron, if the wires can not be connected directly to the Arduino.

Step 2: Hardware Assembly

The bell is held by a strong paperclip. The small paperclip is used to form a kind of arm that is atached to the servo motor.

Note, that you want to bent the paperclip that holds the bell in a way, that already a little shaking generates a ding.

Step 3: Schematics

There is no real schematic. Just attach the servo motor to the Arduino. The servo has three wires:

  • yellow or orange: signal
  • red: VCC
  • brown: GND
The red and the brown one are attached to the according pins on the Arduino (5V and GND). The orange one is wired to pin 2. It will signal the servo in which direction to turn.

You may want to solder small connectors to the wires if the wires do not fit directly into the Arduino or the servo.

Step 4: Programming the Arduino

Arduino

If you are new to the Arduino, it is a small board, fully assembled with a AVR microcontroller. It is well suited for hacking and interacting with your environment. Many things that are hard with microcontrollers are rather easy with Arduino. Some of the advantages:

  • no need for a separate programming device (programmer)
  • comes with an integrated development environment (IDE)
  • runs on any platform, Windows, Mac, Linux.
  • easy connection to your PC with USB
  • hardware is open source (but the name Arduino is not)
  • has a great community
More information can be found at the official Arduino website. Be sure, to check out John's Arduino instructable for further details on how to get started with Arduino.

What does the software do?

The small piece of software that gets uploaded to the Arduino, controls the servo. It receives single bytes via the serial connection over the USB cable. If it receives a value of 5, it moves the servo arm five times forth and back. So the max value to send is 255.

Program the Ardiuno

So I assume you have downloaded and installed the latest Arduino IDE from Arduino.cc. For now it is version 0010 Alpha.
To drive the servo more comfortably you have to download a library. You can find it on the Arduino Playground. Unzip it and put the folder in .../arduino-0010/hardware/libraries/.

  • Attach the Arduino to your PC with the USB cable.
  • Open the IDE and start a new sketch. Sketch is Arduino speak for program. Select File -> New.
  • Select the appropriate serial device (Tools -> Serial Port). This depends on your environment, for me it is /dev/tty.usbserial-A4001JAh.
  • Download the attached source file and paste it into the new sketch. Hit the save button.
  • Hit the verify button. This compiles your sketch into a hex file that can be transferred to your Arduino.
  • Hit the upload button to transfer your sketch to the Arduino.
Testing

Now your hitcounter is ready for some action. Let's see if it works.

  • Hit the serial monitor button.
  • Select the text box next to the send button.
  • Hit the tab key and send it.
  • By now the servo arm should move forward and back.
Phew. That was the hardest part. For now you can send a byte to the Arduino and the servo waves at you. Next is to find something that you want to trigger the bell.

We are almost done.

Step 5: Make It a Hitcounter

To make it a hitcounter for your website, we need two small code pieces. One two create and take care of the counter and a second to fetch the value of the counter and to send it to the Arduino.

Note: If you are not familliar with Python or PHP, the scripts can be easily ported to your favorite programming language.

The counter

Here is a small PHP script, that reads a value from a file (hitcounter.txt), increments it and writes it back to the file. That is all, that is needed. This file can be saved as counter.php on your server for example. You can then trigger a count with you webbrowser pointing to http : //www.youdomain.com/counter.php. I included this snippet in my wordpress blog.

$hits = file($count_my_page);
$hit = trim($hits[0]);
$hit++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hit");
fclose($fp);
echo $hit;
?>

The glue code

This next code snippet is used to fetch the counter. I used Python but anything should work. It opens an HTTP connection and fetches the hitcounter.txt. If the value has changed since the last fetching, the diff is calculated and pushed to the Arduino. This is done every ten seconds until you interrupt the script with crtl-c.
Adapt the myUrl and the serial connection below to your needs.

#
# fetch counter
#
import time
import urllib
import serial

# usb serial connection to arduino

ser = serial.Serial('/dev/tty.usbserial-A4001JAh', 9600)
myUrl = 'http://tinkerlog.com/hitcounter.txt'

last_counter = urllib.urlopen(myUrl).read()
while (True):
_ counter = urllib.urlopen(myUrl).read()
_ delta = int(counter) - int(last_counter)
_ print "counter: %s, delta: %s" % (counter, delta)
_ ser.write(chr(ord(chr(delta))))
_ last_counter = counter
_ time.sleep(10)

I could not upload files with php extension, so you have to rename the counterphp.txt to counter.php.

If your Arduino is still attached to your PC, then start the Python script to fetch your hitcounter.

..>python counter.py

and you should see the output of the counter. If you point your browser to the URL of your counter.php and hit reload, you should hear your hitcounter ringing.

Yes, now we are done. Time to lean back and enjoy our work.

Step 6: Conclusion

It is the first time, that I built something, that has moving parts. That is the first step to bridge the gap between the virtual and the real world. And it was really easy, the code is straight forward. Also most of the parts were in my trash bin, except the bell. Putting everything together and waiting for someone to hit my blog was fun.

Hope you enjoyed it.

<p>Why is it that I have to get an app from the app store to read something I download from here if it is in my computer there should be no problem reading it?</p>
<p>Great project!</p><p>You can can use this free tool for quickly generate schematics and code snippets:</p><p><a href="http://www.circuito.io/" rel="nofollow">www.circuito.io</a></p>
<p>The python script crashes when the counter gets to 10. Any solutions?</p>
<p>Nice project! :---)</p>
Can you change the code so that an LED Blinks when it gets a hit? Thanks. Please reply soon!
If I wanted to connect a Normal DC Motor to the Arduino which only has two connector pins, how would i do it??
I wouldn't recommend doing this. There are motor controllers for the Arduino that can handle the current requirements of DC motors.
Where is the code that needs to be put into the computer program? <br>
Take a look at step 5.
If I wanted to connect a Normal DC Motor to the Arduino which only has two connector pins, how would i do it??
You can't because the motor needs too much current. You have to use an H-bridge or a motor shield from adafruit or something like that.<br>
If I wanted to use a Piezo and an LED would the coding be much different??
Piezo and LED can be driven directly from the Arduino. Maybe look for an Arduino tutorial to learn how to deal with LEDs and Piezos.
This is such a great idea, and inspired my own interpretation, which is standalone - no computer required. Have a look here:<br><br>https://www.instructables.com/id/Arduino-standalone-web-enabled-bell/
Ring the bell every time someone tweets &quot;Merry Christmas&quot;? Not sure how, though.
Will it work with twitter?
Did you manage to implement this with twitter? and if so would you be willing to share the code?<br><br>Thank you
What do you mean, ring the bell when someone replied to you on twitter?<br>Yes, that should be no problem.
I was looking for the bell and found a bunch of places at google shop - http://bit.ly/aCeJtS
how would i set up this hit counter thing with a google site? would it work at all? im not planning on actually doing this instructable, i might when i get spare time and money, but i would like to actually know if it would work.....
&nbsp;i'd like to implement this with blogger (http://ilictronix.com), but blogger doesn't support php :( &nbsp;is there a way I could write to a file with javascript?<br /> <br /> hearing this every 15 seconds might get annoying :P<br />
So what does the python script do when it sees someone visited your site?
It fetches a small text file from my site. This text file carries the number of hits. If the number of hits is higher than last time, then trigger the bell.
XD Yes i know that part how does it trigger the bell?
It sends a signal via serial port to the Arduino. Do you mean that?
What signal(you are not being descriptive...)
Take a look at the python snippet:<br/>while (True):<br/>_ counter = urllib.urlopen(myUrl).read()<br/>_ delta = int(counter) - int(last_counter)<br/>_ print &quot;counter: %s, delta: %s&quot; % (counter, delta)<br/>_ ser.write(chr(ord(chr(delta))))<br/>_ last_counter = counter<br/>_ time.sleep(10) <br/><br/>It computes the delta between the last counter value and the current counter value. Say, the old value was 112, now it is 115. Next the delta, 3 is send as byte over the serial port to the Arduino. The Arduino reads the byte and rings the bell three times.<br/>
Ah that makes more sense now.
Wow nice Project!
and that thing with the loop (thats a reoccuring problem in alot of skeches)
my arduino barly takes any codes wthout saying error -.- and this one seems to say that... in function ' void loop () ' : error: ' refresh ' is not a member of ' servo '
Hi Akatsuki666, try deleting the line with refresh. If you are using the latest version of the ArduinoIDE, the method "refresh" is no longer available. Cheers, Alex
help?
hahah i love it , 5* and faved!<br/><br/>i have to ask , i didnt see it in your description. but what is your your macbook playing ?? it sounds like you have got the termnal to sing! useing the saay command???<br/>
Hi Luke,<br/>take a look at this: <a rel="nofollow" href="http://en.wikipedia.org/wiki/File:Jingle_Bells_Or_The_One_Horse_Open_Sleigh_Complete.ogg">http://en.wikipedia.org/wiki/File:Jingle_Bells_Or_The_One_Horse_Open_Sleigh_Complete.ogg</a><br/>Cheers,<br/>Alex<br/>
<a rel="nofollow" href="http://www.youtube.com/results?search_query=golfrobot+sigtuna&search_type=&aq=f">www.youtube.com</a>Good work. my son (says proud father) made similar use of the RC servos in a Golf Robot RC. Can be found on youtube.com under this name... <a rel="nofollow" href="http://www.youtube.com/results?search_query=golfrobot+sigtuna&amp;search_type=&amp;aq=f">http://www.youtube.com/results?search_query=golfrobot+sigtuna&amp;search_type=&amp;aq=f</a><br/>
Is it possible to hook it up to anything else? say... when some body talks to u on msn and ur in the next room, cud u hook that up? or instructables comments? Just idea, but this wud be soooo neat to try out for them.
Hi Kryptonite, yes, that would be possible. You would have to modify the python script to fetch an RSS feed for example. Most messaging systems or comments are availble as RSS feed. If a new message or comment is available in the feed, the python script will receive it and notify the Arduino/bell. For the comment feed on instructables, go to your profile and enable your private feed. Cheers, Alex
Sweet. thanks for the quick reply. I'm seriously thinking about making this now, cuz I play this game, and I can't tell if somebody want to talk to me I don't know. Then an hour later I go see, and the person has logged off. thanks, Kryptonite.
wow this is sweet I saw this a while back but I ignored it because I didn't have an arduino but now that I got one this will be my first project :) Thanks!
Added to Arduino Group! ;D
Nice job! Looks like it would get annoying after a while...
This is such a cool project using the Arduino. I'm going to have to order one of these after christmas. Can't wait, and great Instructable.
awesome idea! it's kinda like the digg counter, but if you had this in your house, you could know when people visit your blog.
looks difficult. great instructable!
Hi GorillazMiko, it is not as difficult as it may look. It is definitely easier than programming microcontrollers directly. Arduino is a great way to get involved with micros. Cheers, Alex
Thats great! Nice job!

About This Instructable

79,556views

193favorites

License:

More by alex_weber:64pixels Arduino XMAS hitcounter Synchronizing Fireflies 
Add instructable to: