Facebook counter – How many Likes to your facebook fanpage?

By on May 13, 2013
Pin It

 FB counter

Whether it’s a personal, store or product page, popularity at today is measured in Likes: the number of users who liked your page, photo or any other content you posted on

Facebook is a key metric of customer engagement and potential success for your venture.

That’s why we decided to put together some clever ideas (and few circuits) to create a giant sized display, based on Arduino, that is able to display the number Like collected for a specific page, without being connected on a computer.


Just try a little search

When it comes to applications with Arduino, the chance that someone already created something similar (at least related) to what you want to create is quite high.

After few simple web searches we discovered an interesting piece of work, posted on SkoltiLab blog dubbed “Facebook Like Box” (http://www.skolti.com/lab/exp8/).

The program – written by David Alcubierre – uses Facebook APIs. Among many other features, these APIs allow developers to send queries and get XML responses – one of the calls actually returns the information about the number of likes related to a specified page.

David’s project outputs on an LCD display with two lines of 20 characters: the classic LCD screen mounted on display shield available from various suppliers; unfortunately, we wanted something more impressive and visible and this was far too small and discreet.

With this in mind, we created a display in which each single digit has its own printed circuit board and is connected to the others in a series. This setup communicates with Arduino using the I2C protocol: the chip used in the display is a PCF8574, an I/O expander that is controllable via I2C and addressable thanks to three bits. This setup is ideal for connecting to an Arduino board.

Furthermore, we decided to add a beep playing a short tune at any time the like number increases.



The hardware ingredients

While you probably don’t need information about Arduino and the ethernet board, few words are worth spending on the I/O expander and the I2C communication protocol used to manage a significant number of lines of two-way communication.

The internal block diagram of PCF8574 taken from its datasheet shows a very straightforward and easy to understand structure, where the serial input data on the SDA are converted in parallel data by a shift register and vice versa.

The I/O ports have some special features and, when on high level don’t support more than one milliampere, while at low level they can support up to 25 mA. The operating range of the chip ranges from 2.5 to 6 V.

Schematics Display

With these characteristics, the use of this integrated circuit for our display inevitably requires a transistor for each of the seven segments we want to create with the 4 red LEDs. Moreover, using a single integrated for each digit is only an ingenious solution that transforms the eight bits available in seven segments plus a dot. Through the definition of a bitmap for each specific integer number we have the transformation of a byte sent to the circuit into a displayed digit with the ignition of the relevant segments.



The definition of each chip address is made via the appropriate three-way dip switch available in each display base: simply check the appropriate address in the sketch to correctly identify each digit.


The entire circuit is 12 volts powered: Arduino supplies the power to the PCF8574 through its own regulator which converts the 12V input to the 5V required; the Ethernet shield is powered through the Arduino board as well.

Refer to the wiring diagram for all the information on the various links between the boards.



The sketch


Given that all starts from Tom Igoe’s Twitter Client plus the Facebook query API tweak made by David, we still need to code to add the display replacement and the counter increase jingle tone.

With regards to the library, the Ethernet functions and facebook APIs query code, plu XML parsing, you can refer to the “Twitter Client with Strings” example provided with the core installation of Arduino1.0.x.

But, let’s see he parts we added to existing material.

First we must necessarily include the SPI and Ethernet libraries, plus the Wire library for I2C communication.

At the beginning of the sketch we find the defines that combine the five panels with the relative addresses through the “EXPANDER_n” constants with “n” ranging from 0 to 4; use of integrated PCF8574A is assumed in the sketch, then the bit mask is “0B0011xxx”. In case of PCF8574 type integrated circuits we should have used “0B0000xxx”.

The chosen jingle is “Twinkle Twinkle Little Star” with a usual “PlayNote” procedure found towards the end the sketch. In this first part we define the vectors with the notes and their duration, along with the time and length. The pin to connect the audio circuitry is D5.

For networking we chosen the fixed IP configuration through IPAddress ip (192,168,0,99), but you can also use a method based on DHCP.

Following lines instantiate the Ethernet client and create the variables that we will use during execution.

The setup () part is used it to place numbers the bitmap array – the one containing the segments to be lighted to represent each digit – the appropriate values: let’s remember  that the “0” bits holds the segment off and that when the PCF8574 is reset this activates all their outputs with the high level.

Before finishing setup() we turn on all segments for two seconds, then we display simultaneously on each display the digits from 0 to 9. At the end of this cycle, we turn all digits off by sending to all 5 displays a 0 value.

The main loop checks that the client is connected to the server declared as a string at the beginning of the sketch with


char serverName[] = “api-read.facebook.com”;


and begins to parse the xml received, searching for the Like value with this simple routine


if ( currentLine.endsWith(“<fan_count>”)) {

       readingFbcount = true;

       fbcount = “”;



     if (readingFbcount) {

       if (inChar != ‘<‘)  {

         if (inChar != ‘>’){

           fbcount += inChar;




The data is loaded character by character into the fbcount variable is used by subsequent statements that, for five times, read a character and transfer it on the corresponding display with the function defined at the end of PCFwrite scketch.


Before displaying the fbcount value a comparison is also made with the numerical value that was previously read, so that, in case of increase the jingle is played. This routine makes reference to the two additional routines playTone and playNote allowing for the generation of the frequency corresponding to the letter representing the note in the array, for the period specified in the vector beats.

The server connection is performed by the code that is outside the main loop containing the call to the server as defined in the initial part of the sketch. The call sends a http GET with the query string.


To ensure the data are those related to the right page you need to insert the correct ID (check our XML and see our site and our ID). The string is very long so we abbreviated it in order to highlight the place where you enter the ID.


client.println(“GET /restserver .…  %20IN%20(169319619774700)%22}&sdk=joey HTTP/1.1”);


The ID is in brackets and is located near the end of the string.


To recover your ID can be done by accessing your page and then editing the URL replacing “www” with “graph”. For clarity:


http://www.facebook.com/OpenElectronics -> displays the Facebook page


http://graph.facebook.com/OpenElectronics -> Show the card with various information including the ID, as shown:


You must use the ID that before the “name” field while ignoring other ids that may be found within the data displayed. You can test the data that you retrieved by putting in your browser the string that we reported, replacing >>ID<< with the number you just retrieved.

For open-electronics.org:


Here the answer is a little shorter, since we simplified the query string.


The other routines contained in the sketch are used for displaying and for converting from strings to numbers, followed by the parts that are related to the jingle, already described.


Compiling the sketch

Before compiling and loading the code on the board, you need to change the IP according to the one assigned to your Arduino on your LAN and set the addresses of the display according to their actual configuration. The ID is inserted into the sketch before compiling and after having “tested” it through the browser. If you do not take care of all this, before loading the firmware on your Arduino, you’ll have a good chance of having a non-working system or simply a system displaying Likes from someone else’s page.

Once the firmware is compiled and loaded you can do a first test: the debug strings print instructions on the serial port allow you to check the software without connecting the LED display, but only by mounting the Ethernet shield and making the connection to your LAN. For each server query you’ll have the current Likes output on the IDE console – which of course you must activate -if there is an increase, you will also see the new Likes number.

Final testing

Even in the absence of a network connection, the firmware has a display initialization routine that first turns on all segments in sequence and then composes numbers from 0 to 9 simultaneously on the digits. During this step keeping the IDE console open can be useful (check that the once the network cable is connected, after resetting the Arduino, you receive the message My address: <IP of address of the board> that should be followed by the Like count)


If you have a particularly successful website and five digits for Likes are not enough, this is not a problem: just physically add one or more digits to the series and proportionally adapt the defines and the code blocks writing one digit after another for each display.




About Boris Landoni

Boris Landoni is the technical manager of Open-Electronics.org. Skilled in the GSM field, embraces the Open Source philosophy and its projects are available to the community.


  1. Pingback: Facebook counter – How many Likes to your...

  2. William Main

    September 12, 2013 at 12:33 PM

    A very nice project. I’d love to do this but make the data being displayed programmable using a simple language to define the web page and item from that page. You could then use the hardware as a more generic web page data display. I am working on a similar project myself but I am using an LCD graphics display.

    Good job.

  3. Jarno

    December 17, 2013 at 8:47 PM

    Nice. I don’t have the skill to build this, but my friend might. Is there some kind part list / electric list?

  4. Pingback: Facebook counter – How many Likes to your...

Leave a Reply