Twitter Counter : LittleBits and CloudBits

Hi Everyone! I’m just getting started with CloudBits and love it! My current challenge is to make a twitter counter, listening to a specific hashtag.

My goal is to do this :
If there are 10 hashtags, light up 1 light.
If there 20 hashtags, light up 2 lights.

My current code is using IFTTT - if there’s a tweet with specified hashtag, ping CloudBits @ 100% for 1 second.

I’m having trouble though getting the CloudBits to tell Arduino if there are than 2 tweets.

My question, in short :smiley:
Any tips for reliably sending a signal from CloudBits to Arduino, and then incrementally add to a counter?

1 Like

Here’s a related thread : Getting Arduino to talk to CloudBit?

1 Like

I made some headway and got my cloudBits to talk to my arduino :smile:

But I’m not quite sure how to upload .ino code up here…

Still having issues incrementing the counter though. With CloudBits + IFTTT working together, there is a 1 second minimum of “reading tweets” - so how would I increment the counter variable just once, while cloudBits == HIGH.

@JackANDJude - thought you’d appreciate taking a look at this :smile:

Hi, @jakilevy! Thanks for starting this new topic! :slight_smile:

Let’s talk specifics…

What IFTTT twitter trigger are you using? The options I see are:

  1. New tweet by you with hashtag - This Trigger fires every time you post a new tweet with a specific hashtag
  2. New tweet from search - This Trigger fires every time a new tweet matches your search query. NOTE: limited to 15 tweets per check.

If you are unsure if your IFTTT recipe is actually firing when there are multiple tweets, try putting an led or buzzer between the cloudBit and Arduino.

If you’re not sure about what is happening with the Arduino, try using another input to simulate the cloudBit while you are coding. What happens when you put a light sensor or a pressure sensor in one of the Arduino’s inputs and hold it down for one second?

Please share your code thus far and results of this little experiment. :slight_smile:

Hi Hi!

Thanks for the reply!

I’m using New Tweet from search. It’s definitely hitting arduino (I’m using the Serial thingy to read values coming out).

This is my code :

What I’m not sure about is how to “count” how many tweets are coming in. My idea is the following –

  1. Wait for a tweet
  2. IFTTT hits CloudBits when a new tweet comes in
  3. CloudBits goes “On” at 50% for 1 second
  4. When CloudBits goes “On” , my cloudBitsValue variable is in the range of 490 - 501. Call it a range of 490 - 510.
  5. When the CloudBits is “On” at 50%, increment a variable (tweetsCount) just once (representing a new tweet)

For this Arduino code, I’m not quite sure whether to use a while loop, an if statement, a delay, or…well, just quite not sure how to handle that logic.

BTW @Thingfully told me to ping @sean_littleBits & @Patrick_littleBits for some eyes on this :slight_smile:

OK, when I test your code with a pressure sensor at 0 and a reset button at A0, I get these results on the bargraph when ButtonCount equals the following…

1 = no lights
2 = 1st led flickers
3 = no lights
4 = 2 led’s
5 = no lights
6 = 3 led’s
7 = no lights
8 = 4 led’s
9 = no lights
10 = 5 led’s and d1 lights

Do you get the same results?

Exact-o-mundo! The button was there just to test things out, in case the CloudBits piece didn’t work :slight_smile:

With only a few changes to the beginning of your void loop, I think it does roughly what you want. If so, the next thing is to get rid of some double code, replacing count with tweetCounter. :slight_smile:

void loop() {

  resetButtonState = digitalRead(resetButton); // get the state of the reset button
  //JB countButtonState = digitalRead(countButton); // get the state of the counter button

  // barGraphValue = analogRead(cloudBitsValue); ??? sets the value of the BarGraph to the TweetCount
  cloudBitsValue = analogRead(cloudBitsPin); // --> THIS IS FOR TESTING JUST ONE TWEET COMING IN
  if (cloudBitsValue >229) countButtonState = HIGH; //JB
  else if (cloudBitsValue <=229) countButtonState = LOW; //JB

1 Like

@JackANDJude You are a bitSTAR. I hope @jakilevy gets this going. We are working together on this project and it’s larger than life and due tomorrow. :hourglass_flowing_sand:

Oh my gosh, you’re welcome! The code does need some cleaning up, as it is heavily modified from it’s original purpose (@RichB). If you still need help, feel free to post changes to the code as you go. :slight_smile:

sweet! so the idea here is to basically make the CloudBits a button. I’ll give this a go and start a new arduino sketch

1 Like

Hi @JackANDJude! Excellent! I got it working with CloudBits! Hoorah! However - now my physical button doesn’t work anymore. Only the cloudBits piece does.

Since this is for an event, I was hoping to use the button (in case wiFi craps out) AND CloudBits together.

Is there an emoji for “Scratching my head” :scream:

Here’s the updated code -

AHA! I was treating the button as a test for the cloudBit. I did not realize you wanted both a button and a cloudBit for live demonstrations. Great idea! OK, replace these two lines with these two lines of code:

  //if (cloudBitsValue >950) countButtonState = HIGH; //JB
  //else if (cloudBitsValue <=950) countButtonState = LOW; //JB

  if ((cloudBitsValue >950) || (digitalRead (countButton))) countButtonState = HIGH; //JB
  else if (cloudBitsValue <=950)  countButtonState = LOW; //JB

Thanks so much for your help! I posted the final (Working) code here :

You’re welcome! How did it go? Can you tell us more about it on the project page with pic(s) and a demo video? : ?

The project will go public in Barcelona on Monday. @jakilevy and I will post pictures of the process after that. Alas, he is not here but I am and have connected with @Iva — officially my new BFF. :heart_eyes:


Bridget, you are so adorable! :see_no_evil: Spreading our friendship through the web hahahaha :grimacing: @jakilevy code works great! thank you so much! I’m sure it will be hackable during the conference. And @JackANDJude Thank for all the help :wink: we really appreciate it!
Cheers from Barcelona!