Tarik 12 December 2022 Javascript, API, Electronics, MIT

Utilizing live data to display the world's emotions

Blog image

Social media has become unavoidable in our society. The advent of such technology was met with a rush by millions to post or “tweet” their opinion on an issue. This zeal to share one’s thoughts on social media has not decreased since social media began; in fact, there are more accounts on these platforms than ever!

With what feels like the whole world constantly blabbering on these platforms, I hatched the idea to observe the net feelings of our “digital society.” As a way to quantify our society’s feelings, I decided to stream the posts of individuals in real-time from the platform Twitter, due to its popularity and code-friendly structure.

Once I had captured and evaluated the sentiment of our society at an instant in time, I needed a means of projecting this information to lots of people at once, and I had the perfect medium... In my first-year seminar at MIT, our final project was to create a light show for MIT’s Welcome Center, which has a beautiful LED-light installation boasting hundreds of lights. This light installation is open-source, allowing anyone to upload their code into the main computer, and marvel at their work on a massive wall!

The behind-the-scenes code that allows for MIT’s Welcome Center to be customized is a Javascript library called p5.js, allowing users to draw, animate, and create just about anything with user-friendly functions. These animations and colors are then sampled at hundreds of points. These samples each carry an RGB color value that tells each LED on the massive wall what color to change to, and when.

With an idea and a plan on how to share the finished product with thousands, I could get to work on implementing the project.

The first challenge was live-streaming Tweets in real-time, using Twitter’s API. This proved to be much more difficult than I thought. It seemed like all of the tutorials online did not utilize aspects of the API that I needed to use. In the end, I had to read through the API’s documentation and cherry-pick the syntax/code that applied to my use case.

Running my first version of the live-Tweet code, it worked! However, there was a large problem that remained to be solved: the code used two files. One file contained the requests to the API, and the other had the dependencies that the code needed in order to work. However, the software that tells the MIT Welcome Center lights how to behave, only allows for one file to be uploaded.

The solution to this problem involved using a server. A server is basically code that always runs, allowing users to query it for data. I wrote code that set up a server that makes requests to the Twitter API, returning the tweet in a string format to the person making a request to the server.

With live tweets obtained in one neat file, all that was left to do was create a p5.js that represented how the tweets were feeling.

First, I wrote a Javascript function that takes in a string and returns the overall sentiment using lists of positive and negative words.

With the output of this function, I then wrote p5.js code that had lots of rectangles bounce back and forth on the screen, updating colors depending on the current sentiment of the digital society (green for positive, red for negative, gray for neutral).

The installation is now able to be viewed at MIT’s Welcome Center. Visit and see how the world around you feels!