Dec 08th, 2019 | by: ELECTRONOOBS | Views 1930
Views 1930
In this tutorial we will see how to make a Magic 8 ball with the Arduino. This is based on the real magic ball which is based on liquid and floating principle with a plastic dice with 20 answers inside. Once you shake the ball, a random side of the dice will get on top of the black liquid and a random answer will be shown.

In our case, we will do that digitally. The project will use a gyro module to detect when the ball is upside down. Then it will give a random answer to the OLED display. At the same time using a DFplayer it will play sounds with the answers. It also has a battery inside that we could charge and the case is made out of 3D printed parts.

PART 1 - What we need

This project is easy and the part list is quite straightforward. The Arduino will control everything. To detect the angle of rotation and by that know when the ball is upside down we will use the MPU6050 gyro module. To print the text we need an OLED display and to play sounds we will use the DFplayer with the SD card and a small speaker. We need a 18650 battery and a charging module and to get 5V we need a small boost converter. We will also need glue and small wires.


We need:

Parts we need
PART 2 - Schematic

See the schematic below. It is very simple. All we have to do is to connect the i2c pins (SDA and SCL) to the A4 adn A5 pins of the arduino. For 5V supply, first connect the charging module to the 3.7V battery. Then the output of the module, connect the positive side to the sliding switch and the negative output to GND. GND is the same for all parts. From the switch, connect it to the boost converter adn before you connect it to anything else, make sure you set it at 5V. You could glue the boost converter potentiometer so it will stay at 5V. Connect the Rx and Rx pins from the Arduino to some 1K resistors and from there to the Tx and Rx pins of the DF player.  As you can see, for the DFplayer, we connect Tx to Rx and Rx to Tx. Connect the speaker at the DFplayer spk outputs and that's it. The IMU and the OLED display are using the same i2c pins because they have different slave address. All is there to do is to mount this inside the 3D case and upload the code.

PART 3 - Mount it all

First we need the 3D case. For that go below and get the files. Print them using 0.4mm nozzle, PLA material, 0.3mm layer height, 2 perimeters and 20% infill. You don't need to use support for the parts of this case. Now is time to glue the circuit inside the case. But I recommend you to test the circuit on a breadboard first and then glue it inside the case. Get the code from next part.

PART 3.2


I've connected everything on the breadboard and uplaoded the code from next part. Also, you will need the mp3 files from below. Download those and copy the entire mp3 folder to an empty SD micro card. It has to be the entire mp3 folder with taht name, not only the files. Insert the SD cart into the DFplayer and test the code. Rotate the IMU module and watch the screen and listen the sounds.

PART 3.3

Ok, the first step of mounting the ball is to glue the OLED display on the bottom hole as you can see below. Then connect the Bat+ and Bat- pins to the battery and from the module output to the sliding switch. Glue the switch below the OLED display and make sure it won't stick out of the case too much so the ball could sit flat on the table.

PART 3.4

The next step is to solder wires to the IMU module for GND, power, data and clock. Make sure the wires are a bit long because this component will go on the other side of the ball. Then, glue the IMU module on the top part of the ball, paralel with the 8 shape on top and with the chip facing the exterior of the ball. Is important to be paralel with the 8 shape on top because we will only detect the X axis rotation.

PART 3.5


Next step is important. Connect the battery output to the boost converter. Then rotate the potentiometer till you get 5V. Then glue the potentiometer so it will stay at that voltage and we won't burn the Arduino. Now tje output from the boost converter will be our main 5V supply and we can connect this to the rest of the modules: Arduino, DFplayer and the IMU module.

PART 3.6

Next part is to connect the DFplayer. But first make sure you download the mp3 files form the previous part and copy those to the SD card. Then insert the SD card into the DFplayer. Solder the speaker to the player and wires for 5V, GND, TX and RX to the DFplayer. Remember to add those 1K resistors for Tx and Rx pins. Then you can glue the speaker on the top part of the ball, just on top of the IMU module. And the DFplayer with the PCB on the side of that. Now we have to merge both parts.

PART 3.7

Make all the connections to the Arduino. Then go below and download the code and uplaod it to the Arduino. Then you can glue the Arduino inside the case as well. Now we can close the case but give it a tes one more time. If it works, add some glue to both parts and join the parts together. make sure the 8 shape on top os paralel with the OLED screen below, otherwise that would be strange... Is time to paint the ball.

PART 3.8

Add tape on all the parts can't be painted. Then I use some matte black spray paint and cover the entire ball. Let it a few hours for the paint to dry. Then remove the tape and we have our magic 8 ball. Use a black permanent sharpy to correct small errors.

PART 3.9

Go to the next part and downlaod the code. Uplaod it to the Arduino. See the example video below. I hope you like it. That's pretty much all with this tutorial. If you wnat any other detail, leave a comment on our forum.

PART 4 - Code

Ok, the code is not that difficult. Download it from the link below. You will also need the library for the OLED screen adn the DF player. So downlaod that from the links below as well and install them to the Arduino IDE. We read the angle adn if is around 180 degrees we send a random answer and audio. If we get back to around 360 degrees we reset the code and wait for a new question. Download the code from below.

if(the_answer == 4)
    display.println("  AS I");
    display.println(" SEE IT");
    display.println("  YES!"); 




    about 4 years ago

    I am in a nice SETUP. well done noobs

    Noob 19129

    about 3 months ago

    Please try a hrefhttpswwwgooglecomGooglea before asking about a hrefhttpsforumoffroadwebitviewtopicphpf11t7117p304312p304312Recommended Product Guidea c5f79e0

    Noob 19129

    about 2 months ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttpsblackstoneactorgforumphpmodviewthreadtid688919pid835418page1extrapid835418Useful Product Siteurl c5f79e0

    Noob 19129

    about 2 months ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttpswwwforumvuwpgsaacnzviewtopicphpp205886p205886Useful Product Tipsurl 579875

    Noob 19129

    about 9 days ago

    Please try urlhttpswwwgooglecomGoogleurl before asking about urlhttpcos258comforumphpmodviewthreadtid774pid922675page13416extrapid922675Excellent Product Guideurl 5f79e0b


    about 4 years ago

    I am in a nice SETUP. well done noobs

Login or Sign Up to post comments on this tutorial.