Twitter Mood Light - the World's Mood in a Box

Powered by: an Arduino, a WiFly wireless module, an RGB LED, Twitter.com and a 9v battery.

I’m a news junkie. I want to know everything that is going on in the world as soon as it happens. I want to wake up and know immediately if something big has happened overnight.

However, I’m an extraordinarily busy man; I don’t have time to read news feeds; reading that headline that I already knew about or don’t care about is time that I’m never getting back!

No. What I need is some way to be constantly in touch with the world's events as they unfold, alerted when something big happens, and to be made aware of it all faster than awareness itself!

...A way to get a glimpse of the collective human consciousness as an extension of my own. Something that I don't have to continually check or poll, but instead, like a part of my body, it will tell me when it's feeling pain or generally in need of my attention ...leaving me time to get on with other things.

And so, I present: The World Mood in a Box!

The Arduino connects directly to any wireless network via the WiFly module, continually searches Twitter for tweets with emotional content, collates the tweets for each emotion, does some math, and then fades the color of the LED to reflect the current World Mood; Red for Anger, Yellow for Happy, Pink for Love, White for Fear, Green for Envy, Orange for Surprise, and Blue for Sadness.

If an unexpectedly high number of tweets of a particular emotion are found, then the LED will flash to alert us to the possibility of a world event that has caused this unusually strong emotional reaction.

For example, a world disaster and it may flash Blue or Red (sadness or anger), if the strong favourite loses a big football game it may fade to Orange (surprise), …and If it flashes White, the collective human mind is feeling extreme fear, and it's probably best to go hide in a cupboard and sit it out, waiting for sunnier skies and a return to Yellow or Pink. ...OK, I'm not that busy.

Step 1: How It Works

An Arduino connects directly (no computer required!) to any wireless network via the WiFly module, repeatedly searches Twitter for tweets with emotional content (aka sentiment extraction or tapping into the moodosphere), collates the tweets for each emotion, analyzes the data, and fades the color of an LED to reflect the current World Mood:

Red for Anger

Yellow for Happy

Pink for Love

White for Fear

Green for Envy

Orange for Surprise

Blue for Sadness

Example search terms to find tweets that may express surprise:

"wow"

"can't believe"

"unbelievable"

"O_o"

If an unexpectedly high number of tweets of a particular emotion are found, then the LED will flash to alert anyone nearby to the possibility of a big world event that has caused this unusually strong emotional reaction.

Example signals:

A world disaster and it may flash Blue or Red indicating it best to check a news site to see why everyone is so sad and/or angry.

If the strong favourite loses a big football game, it may flash Orange to express the surprise at this unlikely event.

If there is a heat wave in London it might turn Yellow to reflect how much happier people now are.

If it flashes White, the collective human consciousness is feeling extreme fear and something terrifyingly bad is probably about to happen. Time to hide and/or panic.

Uses

You could put it on your desk to get an early warning of something big happening somewhere in the world

A literal 'mood light' at a party or a game whereby you guess what colour it will change to next and for what reason

A world mood barometer perhaps next to your bed to decide if it is best to hit snooze until it's less angry outside

A gauge of public sentiment to help you decide when to sell all your stocks and shares, and head to the hills.

In a foyer or waiting area or other public space for people to look at and contemplate.

Set it to connect to any wireless network and carry it around in the streets, stopping strangers to explain to them that you have managed to capture the world's mood and have it locked in this here box.

Step 2: All You Need Is...

I ordered most of the electronics from Sparkfun, and picked up the rest from the local Radioshack. The acrylic I got from a local plastic shop(!) - they cut it and drilled a hole free of charge.

Step 3: Connect the Arduino and WiFly to a Computer

Firstly, the Wifly breakout board needs to be stacked on top of the arduino and the RX, TX, Vin, Gnd, pin 10, pin 11, pin 12 and pin 13 needed to be connected. I used breakaway headers and soldered the required pins.

I used the pliers to bend the legs of the LED, and mounted it on the circuit board. Each resistor is then mounted next to each of the RGB legs, and the wires are twisted together. Then I added the 4 connecting wires and twisted them. Finally, I soldered all the connections.

Note: The pictures illustrate using the same resistor for each colour channel, but I should have used the resistance levels in the data sheet:

180 Ohm for Red
100 Ohm for Green
100 Ohm for Blue

Also note, I covered the back with insulating tape to stop any shorts when putting it all into the box.
Also, from the datasheet, "the Sensor inputs SENS0-7 are extremely sensitive to over voltage. Under no conditions should these pins be driven above 1.2VDC. Placing any voltage above
this will permanently damage the radio module and render it useless."

Step 5: Choosing Good Search Terms

Twitter allows you to search for recent tweets that contain particular words or phrases.

You can search for tweets that contain any of a list of phrases by using the "+OR+" conjunction.

For example, here is a search request that might find tweets that express Fear:

GET /search.json?q="i'm+so+scared"+OR+"i'm+really+scared"+OR+"i'm+terrified"+OR+"i'm+really+afraid"+OR+"so+scared+i"&rpp=30&result_type=recent

I spent a long time finding good search phrases.

The search phrases needed to produce tweets that:

very often express the desired emotion.

very rarely express the opposite emotion or no emotion.

Many search phrases that I thought would work, turned out to not work that well when I searched with them.

Smileys have been used with some success to extract whether the sentence is positive or negative, but I didn't find them useful for extracting anything more.

The trouble with smileys is that a smile can mean so many things ;D

It is often used, it seems, as a kind of qualifier for the whole sentence; since people have to compress their thoughts into 140 characters, the meaning can become ambiguous.

The smiley often then acts as a qualifier that:

'this is a friendly comment'

'don't take this the wrong way'

'i am saying hello/goodbye with a smile'

'this is almost a joke'

'I know I'm being cheeky'

'I don't really mean this'

Phrases using adverbs seemed to produce better results.
"so scared" or "really scared" is better than just "scared" which returns bad results: for example, "not scared".

Phrases in the first person seemed to produce better results.
Some search phrases give tweets that suggest the author feels the emotion: for example, "i really hate...", often sounds like they really are full of hate or angry, whereas other phrases containing the word "hate" give tweets that do not seem to express much emotion, like "why do you hate..."

Hyperbole is your best friend, ever:
Using phrases with hyperbole produced good results. Tweets with "I'm terrified" or "I'm petrified" in them were generally more fearful sounding than "I'm scared"

Regardless, the approach is still naive, but statistically, from my tests, it does seem to work well.

While testing the code, I did at one point get the horribly ominous "Flashing White" that signifies the world is feeling intense fear, but since I was still testing it all, I did not hide under the table straight away, but instead, threw caution to the winds, and went on to Twitter to see what people were suddenly so fearful about.

The recent tweets containing the Fear search string (see top of page) were largely relating to a large thunderstorm that had just started somewhere near Florida.

Attachments

Step 7: Programming Step 1: SPI UART

The WiFly Shield equips your Arduino with the ability to connect to 802.11b/g wireless networks.
The featured components of the shield are:

a Roving Network's RN-131G wireless module

SC16IS750 SPI-to-UART chip.

Serial Peripheral Interface Bus (or SPI) is a "four wire" serial bus capable of high rates of data transmission. A serial bus allows data to be sent serially (synchronously), i.e. one bit at a time, rather than in parallel (asynchronous)

The Universal asynchronous receiver/transmitter (or UART) is a type of asynchronous receiver/transmitter, a piece of computer hardware that translates data between parallel and serial forms.

to desiredColorID with a time delay, fadeDelay, measured in ms, between

each step. No effort is made to scale the step size for each rgb

channel so each may not complete at the same time.

*/

voidLED::FadeTo(intdesiredColorID)

{

// check for valid colorID

if (desiredColorID >= NUM_COLORS ||

desiredColorID < 0)

{

//logger.log("invalid Color id")

return;

}

// get a local copy of the colors

ColorcurrentColor;

currentColor.r = Colors[m_currentColorID].r;

currentColor.g = Colors[m_currentColorID].g;

currentColor.b = Colors[m_currentColorID].b;

ColordesiredColor;

desiredColor.r = Colors[desiredColorID].r;

desiredColor.g = Colors[desiredColorID].g;

desiredColor.b = Colors[desiredColorID].b;

booldone = false;

while (!done)

{

// move each of r,g,b a step closer to the desiredColor value

if (currentColor.r < desiredColor.r)

{

currentColor.r++;

}

elseif (currentColor.r > desiredColor.r)

{

currentColor.r--;

}

if (currentColor.g < desiredColor.g)

{

currentColor.g++;

}

elseif (currentColor.g > desiredColor.g)

{

currentColor.g--;

}

if (currentColor.b < desiredColor.b)

{

currentColor.b++;

}

elseif (currentColor.b > desiredColor.b)

{

currentColor.b--;

}

// write the new rgb values to the correct pins

analogWrite(m_redPin, 255 - currentColor.r);

analogWrite(m_greenPin, 255 - currentColor.g);

analogWrite(m_bluePin, 255 - currentColor.b);

// hold at this color for this many ms

delay(m_fadeDelay);

// done when we have reach desiredColor

done = (currentColor.r == desiredColor.r &&

currentColor.g == desiredColor.g &&

currentColor.b == desiredColor.b);

} // while (!done)

m_currentColorID = desiredColorID;

}

Step 11: Programming 5: Computing the World Mood

The mood light should be responsive enough to reflect what has just happened in the world, but it must not be so overly sensitive as to be susceptible to noise, and also not be too sluggish to be late in informing you of a big world event.

The important thing is to carefully normalize and smooth the data, and to adjust the thresholds to give the right level of responsiveness and alarm. (i.e. it should flash when a headline news story
happens and not when a TV show starts, GMT)

Emotion, mood, and temperament

Firstly, the "world's emotion" is calculated by searching twitter for tweets with each of the 7 mood types (love, joy, surprise, anger, fear, envy, sad) .

A measure of "tweets per minute" is used to calculate the current emotion. A higher number of tweets per minute suggests more people are currently feeling that emotion.

Each mood ratio is then compared to a base line, a "slow exponential moving average", that I call the "world temperament".

The mood that has deviated furthest from its baseline temperament value is considered to be the current world mood.

The deviation is measured as a percentage, so, for example, if fear changes from accounting for 5% of tweets to 10% then this is more significant than joy changing from 40% to 45% (They are both a +5% in additive terms, but fear increased by 100% in multiplicative terms.)

Finally, the world temperament values are tweaked slightly in light of this new result. This gives the system a self adjusting property so that the world temperament can very slowly change over time.

These values in WorldMood.pde are used to adjust how sensitive the system is to information.

Do you want it to pick up when people are happy about a sport result or scared about the weather?

Or would you prefer to only track big events like natural disasters or terrorist attacks?

Big and Small Contest

PCB Contest

Make it Glow Contest 2018

118 Discussions

The world has changed a bit since this program was first posted. I finally have my mood light working, but it wasn't always easy.

First, make sure you buy an Arduino Duemilanove. Yes, there are newer devices out there. No, you do not want them. They are all supposed to use the same code, but this code is sensitive to the timing on the Duemilanove. Use another board and you'll be fighting issues all the way. After over a year of this, I just switched and I'm glad I did.

Second, the Twitter world moves much faster than it did. 30 tweets of the original terms go by in less than a second. Since everything is computed in tweets per minute, this obviously won't do. Everything registers off the scale.

You'll have to substitute this code in TwitterParser.cpp to compensate.

I also had to modify my LED.cpp file to make sure colors showed up properly. In particular, I had to adjust the array values in the beginning to accurately show colors with my LED -- apparently my red isn't as bright as the blue and green and so full value on all three skews the colors. I added the following text to the WorldMood.cpe to make it easy to test light colors -- right after the device starts up, it triggers the light to the values specified. Value range goes from 0 to 255.

Hey, the new API requires OATH and this project no longer works. It's a little beyond my ability to fix it, but would you like to work with me to provide updated code? This seems to be a fairly popular project and it's really cool when it works.

Is there anyone out there who has an idea of making code for aduinos? I'm having a hard time doing my project. I have no idea of what code to use. My project is about a gh-718c mini PIR motion sensor detecting my arm or hand. If the motion sensor detects that my hand is low, the light or LED will dim, and if it detects my hand on a high position, the LED will bright up. Please please. Help please. Thanks for the reply!

I am not even sure where to start with this comment! Bottom line, I got this running on newer hardware with a newer IDE.

Long story short: I started working on this using the 1.01 Arduino IDE, an Arduino Uno and an LED "ball" which I found referenced here: http://hackaday.com/2012/09/08/hacking-a-floating-rgb-led-decorative-ball/

I liked the look of that ball, and thought to myself "what can I do with it that is cool". I bought one, and then decided to see where I could take this instructable.

Like many of you, I ran into all sorts of errors when trying to load up the sketch and libraries to make it work.

After hacking away at it for about 8 hours over the last week, I've gotten it compiling and running on the new version of Arduino, with an Uno and not the Duemilanove. Once I get things a bit cleaner, and I document what changes I actually made,

I will post the full code somewhere and add it to this comment thread.

The quick overview:

1) Wired up my LED. I am using the LED array that came inside the ball. I also wired up a Sparkfun RGB LED Breakout to see if it would work across both. (https://www.sparkfun.com/products/10111). It does. I had to make the code change referenced in the comments and on this blog to make the colors match best with the Sparkfun LED kit. (http://www.stephenhobley.com/blog/2010/06/11/arduino-world-mood-light-using-twitter-and-wishield/)

2) In each of the libraries that were included, I had to update the code to replace: #include "WProgram.h" with #include

3) The timing and error handling are still pretty screwed up, and not where they should be. I am going to work on that next. The code will execute, and throw some errors, but in true arduino fashion, if you let it run, it will power through things and get to the next step.

4) Pay attention to the comments in "step 6", download the code: I HAD to do this. If you have a newer board then you may need to change this struct SPI_UART_cfg SPI_Uart_config = {0x50,0x00,0x03,0x10}; to this: struct SPI_UART_cfg SPI_Uart_config = {0x60,0x00,0x03,0x10};

5) Once I did those things, I got it to compile and pushed to the Arduino.

It would go out and attempt to make a request to twitter, but I'd get a 404 from twitter. This caused me to scratch my head for a day, contemplate rewriting the entire WIFLY library and then it hit me...

The http request had something wrong with it. In the worldmood sketch, you must look at the lines where you define the search request and make a small change, appending HTTP 1.0 to the end of each.