PUBG Theme Song+Animation With Arduino!

by Utsav_25 in Circuits > Arduino

2388 Views, 14 Favorites, 0 Comments

PUBG Theme Song+Animation With Arduino!

Fun with OLED Displays! - Part 2 || Arduino's tribute to PUBG!
IMG20200517121823.jpg

Hello there and welcome to this fun instructable! I hope all of you are well and staying healthy. This small but amazing project is about playing the PUBG theme song and even creating some game animations using arduino.

The components used are very easily available and very easy to assemble on a piece of breadboard. I will be sharing the entire building and coding process in this instructable, stick around till the end!

I would highly suggest you watch the video to get an idea of the project :) If you like it then like and share the video. Consider subscribing to my channel if you enjoy my build.Thanks!

So, without any further delay, let's get started!

Gathering All the Parts..

IMG20200517112904.jpg
IMG20200517112932.jpg

The build mainly consists of an Arduino Nano which is the main core for this project. You can use any other Arduino variants like the popular Arduino Uno, Arduino Pro Mini, Arduino Mega etc. To display the animations and the images, I decided to go with a 0.96 inch OLED display with a resolution of 128 by 64 pixels. This display can be interfaces with the arduino with the I2C protocol that requires just two wires for data and clock,thus reducing the number of connections and making the project more compact. For playing the PUBG theme melody I used a 5V buzzer of which I connected the positive pin with digital pin 6 of arduino and ground goes to ground of Arduino.

These are the list of parts needed for the project :

  1. Arduino Nano (or any other arduino board of your choice)
  2. 0.96 Inch OLED display module
  3. 5V buzzer
  4. Jumper wires
  5. Breadboard
  6. Arduino programming cable

Connecting Up the OLED Display

IMG20200517113316.jpg
IMG20200517113327.jpg
IMG20200517113340.jpg

A total of 4 connections are needed for the OLED display to be connected from arduino:

Vcc --> 5V of Arduino

Gnd --> Gnd of Arduino

SDA --> A4 of Arduino

SCK --> A5 of Arduino

Pins A4 and A5 of the arduino serves multiple purpose of analog inputs as well as pins for I2C communication. Here we have utilized the pins for the I2C protocol for interfacing with the display module.

The link to the Adafruit library used in this project : https://github.com/adafruit/Adafruit_SSD1306

Connecting the Buzzer

IMG20200517113409.jpg
IMG20200517113448.jpg

The 5V buzzer has a positive and negative supply terminal.

Positive pin--> D6 of Arduino (digital pin 6)(you can use any digital pin of the arduino)

Negative pin--> Gnd of Arduino

We are going to create the desired tone on digital pin D6 to which the buzzer will play the melody.

All Hardware Connections Complete..

IMG20200517113517.jpg
IMG20200517113526.jpg

All the necessary connections of OLED display and the buzzer are complete. Now let's go ahead to understand the programming aspect of the project..

Including the Library and Initializing Display Protocols

Importing the library and headers.JPG

The entire program has been segregated into 3 components:

  1. The main program consisting the initialization and the sequences of image display and melody
  2. "pitches.h" file consisting of the list of musical notes and the associated frequency
  3. "pictures.h" file consisting of bitmaps of the images to be displayed.

The process of how to convert an image into a bitmap array for OLED display is discussed in the upcoming steps.

I will also attach the entire code along with this instructable for you to use:)

The Theme Song Melody..

3. melody notes and durations.JPG
pitches defines.JPG

I looked up on the internet for the basic notes that comprises the PUBG theme song and then added them to the melody array.

By spending a considerable amount of time playing and replaying the melody sequence, I then created the time duration array that is concerned with how long each note needs to be played. The combination of the melody array and the duration array comprises the complete information to play the song.

Playing the Song During Startup..

4 void setup an playing the tone.JPG

There are a total of 63 notes that I used to make up the melody sequence.Using a for loop and iterating through the notes and duration array with a predetermined pause between each note, the entire sequence is played once, since this piece of code lies in the void setup(). Interestingly, none of the code for this project utilizes the void loop() of the arduino code as I intend to play and display images only once. Of course if you want a repeating sequence then that has to be put in the void loop() function.

Converting the Images to Bitmaps..

8.Website ..choose image.JPG

Now, the interesting part of the project is the process to convert an image to a bitmap array for the OLED display according to it's pixel density. For this I found the prefect online tool that allows us to generate the custom bitmaps.

The link for this online application is : https://diyusthad.com/image2cpp

Thanks to the amazing creators of this application, this makes my work much easier.

Upon going to the link you first have to upload the image you want to create the bitmap of. One thing to note here is you should try to select images that do not have a lot of color contrast in it, try sticking to images with a few solid colors,without any gradients to get better results

Adjusting the Resolution According to Your Display

9. Website image rezise.JPG

In the next step, we have to resize the image according to out display resolution. For our OLED display, it is 28 pixels wide and 64 pixels in height, which I have adjusted as shown in the image. Adjust the brightness threshold to make sure the image is considerably clear (this is where the advantage of using images with solid colors comes into play, the more the color gradients, the image quality in monochrome display will degrade as it messes up with the brightness threshold).

Next step is to fit the image on the screen keeping the proportions intact and adjusting for symmetry for which the options are already there. You can explore these options to get the desired image output. For reference you also get the amazing preview option!

Generating the Bitmap Array..

10. Bitmap array creation.JPG

After adjusting the image parameters, in the next step just select Arduino code as output format and click generate to get the desired bitmap array!

There! you have successfully converted your image to desired bitmap array. I have done this process for a total of 7 images and saved them.

Displaying the Images As Sequence

5. dear using millis.JPG
6.calling draw functions.JPG
7. bitmap arrray.JPG

For displaying the images I have used the Arduino millis() function to call the draw() function which is basically a set of commands to clear the display,plot the bitmap array to the OLED and initialize the display. The main logic being that after every 3.5 seconds, the image is changed and the next image is displayed. Well, 3.5 seconds is not a unique number, I just figured out that if I divide the entire melody duration by 7 images I got roughly 3.5 seconds for each display. You can add more images to this and reduce the display time for each image if you wish.

The code snippets explain how the functions are called based upon millis() function.

The entire bitmap arrays of the images are stored in the "pictures.h" file

The Entire Code:

Here I am sharing the entire code for all of you to play around and experiment with!

Once everything seems fine it's time to upload it to the board :)

Downloads

The Results:

IMG20200517121835.jpg
IMG20200517121839.jpg
IMG20200517121830.jpg
_Playing around with OLED Displays-2.png

As you can see the images turned out to be great! And so did the melody! I hope you have watched the video in which the entire demonstration is present.

I hope this Arduino's version of PUBG is an exciting project for all the game and electronic enthusiasts out there.

Please feel free to share your feedback in the comments and share any suggestions.Also, consider subscribing t my channel for more such content as this is a part of the OLED series I am working on. Do let me know if you build this fun project :)

Until next time.