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.
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.
- 1 x 3D files case: 3D STL files
- 1 x Arduino NANO: LINK eBay
- 1 x OLED display: LINK eBay
- 1 x MPU6050 IMU: LINK eBay
- 1 x DFplayer LINK eBay
- 1 x microSD 1GB card: LINK eBay
- 1 x 6 ohms Speaker: LINK eBay
- 1 x TP4056 charger: LINK eBay
- 1 x sliding switch: LINK eBay
- 1 x boost converter: LINK eBay
- 1 x 18650 battery: LINK eBay
- 1 x 32AWG wires: LINK eBay
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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");