Project tutorial
Ask the Magic 8 Ball!

Ask the Magic 8 Ball! © LGPL

This tutorial will enable you to create your own spin on the traditional Magic 8 Ball.

  • 2,500 views
  • 0 comments
  • 10 respects

Components and supplies

Necessary tools and machines

Apps and online services

About this project

Purpose

The purpose of this project was to create a Magic 8 Ball - Arduino style. We were able to do so by modifying the Crystal Ball project in the Arduino starter kit. The goal was to create a micro controller that generates 20 random responses to the user's statement and then switches to another response when a switch button is pressed.

Why

Magic 8 Balls are one of the many fortune telling toys that are popular with children. It was originally developed in 1950. It returns 20 different statements like "It is certain" in response to questions that individuals ask. Magic 8 Balls are unique because can be used by anyone, not just a fortune teller.

How It Works

The LCD display originally shows "Ask the Magic 8 ball!". The user then asks a question and presses the button switch. The display then shifts to one of the 20 responses and then displays "Ask another question!". The user can continue pressing the switch until all of their questions are answered.

How to Make It

Follow the Arduino Project 11 - Crystal Ball in the Arduino starter kit in order to construct the initial circuit. Replace the tilt sensor with a button switch and add a 220 ohm resistor two spaces in front of the button switch. Alter the code so that when the button is pressed, the Magic 8 ball returns one of the 20 responses and then displays "Ask another question!". This alteration includes removing the code about the tilt sensor and replacing it with an if statement (if the switch is being pressed then return the statement + "Ask another question!"). Change the code to reflect what you want the magic 8 ball's response to be. During this step you can utilize the delay function to keep a message on the LCD display for a certain amount of time. In between each of the 20 cases make sure to include a break to differentiate between each case.

Code

Magic 8 Ball CodeArduino
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int switchPin = 6; 
int switchState = 0; 
//declaring the variable for the switch 
int reply; 
void setup() {
pinMode(0, INPUT); 
//power source for switch
lcd.begin(16, 2);
pinMode(switchPin, INPUT); 
lcd.print("Ask the Magic");
lcd.setCursor(0,1); 
lcd.print("8 ball!"); 
//welcome message 
}
void loop(){
  switchState = digitalRead(switchPin); 
  {
    if(switchState == HIGH){
      //when the switch is pressed 
      reply = random(8); 
      //return a random case 
      lcd.clear();
      lcd.setCursor(0, 0); 
      lcd.print(""); 
      lcd.setCursor(0,1); 
      switch(reply){
        case 0:
        lcd.begin(16, 2);
        lcd.print("It is");
        lcd.setCursor(0,1); 
        lcd.print("certain :)"); 
        delay (2500); 
        //maintain the first message 
        lcd.clear();
        //clear the first message
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        //print the second message 
        break;
        //next case 
        case 1: 
        lcd.begin(16, 2);
        lcd.print("As I see it,");
        lcd.setCursor(0,1); 
        lcd.print("yes :)");
       delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!");  
        break; 
        case 2:
        lcd.begin(16, 2);
        lcd.print("Reply hazy"); 
        lcd.setCursor(0,1); 
        lcd.print("try again :/");
       delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!");  
        break;
        case 3:
        lcd.begin(16, 2);
        lcd.print("Don't count"); 
        lcd.setCursor(0,1); 
        lcd.print("on it :(");
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break; 
        case 4:
        lcd.begin(16, 2);
        lcd.print("It is"); 
        lcd.setCursor(0,1); 
        lcd.print("decidedly so :)");
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break; 
        case 5:
        lcd.begin(16, 2);
        lcd.print("Most"); 
        lcd.setCursor(0,1);
        lcd.print("likely :)"); 
       delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break; 
        case 6: 
        lcd.begin(16, 2);
        lcd.print("Ask again"); 
        lcd.setCursor(0,1);
        lcd.print("later :/");
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break;
        case 7:
        lcd.begin(16, 2);
        lcd.print("My reply is"); 
        lcd.setCursor(0,1); 
        lcd.print("no :(");
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break;   
        case 8:
        lcd.begin(16, 2);
        lcd.print("Without a"); 
        lcd.setCursor(0,1);
        lcd.print("doubt :)");
       delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break;
        case 9:
        lcd.begin(16, 2);
        lcd.print("Outlook good :)"); 
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break;
        case 10:
        lcd.begin(16, 2);
        lcd.print("Better not tell"); 
        lcd.setCursor(0,1); 
        lcd.print("you now :/");
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break;
        case 11:
        lcd.begin(16, 2);
        lcd.print("My sources"); 
        lcd.setCursor(0,1);
        lcd.print("say no :(");
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break;
        case 12: 
        lcd.begin(16, 2);
        lcd.print("Yes"); 
        lcd.setCursor(0,1); 
        lcd.print("definitely :)");
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break;
        case 13: 
        lcd.begin(16, 2);
        lcd.print("Yes :)");
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break;
        case 14:
        lcd.begin(16, 2);
        lcd.print("Cannot"); 
        lcd.setCursor(0,1); 
        lcd.print("predict now :/");
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break;
        case 15: 
        lcd.begin(16, 2);
        lcd.print("Outlook not"); 
        lcd.setCursor(0,1);
        lcd.print("so good :(");
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break;
        case 16: 
        lcd.begin(16, 2);
        lcd.print("You may rely"); 
        lcd.setCursor(0,1);
        lcd.print("on it :)");
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break; 
        case 17:
        lcd.begin(16, 2);
        lcd.print("Signs point"); 
        lcd.setCursor(0,1);
        lcd.print("to yes :)");
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break;
        case 18:
        lcd.begin(16, 2);
        lcd.print("Concentrate and"); 
        lcd.setCursor(0,1);
        lcd.print("ask again :/");
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break;
        case 19:
        lcd.begin(16, 2);
        lcd.print("Very"); 
        lcd.setCursor(0,1);
        lcd.print("doubtful :(");
        delay (2500); 
        lcd.clear();
        lcd.print("Ask another"); 
        lcd.setCursor(0,1); 
        lcd.print("question!"); 
        break;
      } 
    } 
  }
}
 

Schematics

Fritz Diagram
magic_8_ball_code_hVlpjwIMvt.ino
Fritz Diagram
thing_1uuarSF3Pq.fzz

Comments

Similar projects you might like

Magic Arduino Ball

Project showcase by Ruben Zilzer

  • 2,221 views
  • 1 comment
  • 6 respects

Simple Programmable Robotic Arm

Project showcase by Ryan Chan

  • 49,118 views
  • 63 comments
  • 145 respects

Sigfox kWh Meter

Project tutorial by jassak

  • 6,115 views
  • 7 comments
  • 15 respects

Arduino RGB Color Mixer

Project tutorial by FIELDING

  • 3,199 views
  • 1 comment
  • 11 respects

GameBox - The Arduino LCD Console

Project tutorial by Team Mattia Colasanto

  • 2,432 views
  • 0 comments
  • 6 respects

Sigfox-Enabled Parking Lot

Project tutorial by jassak

  • 1,069 views
  • 0 comments
  • 8 respects
Add projectSign up / Login