Arduino Magic 8 Ball

The Magic 8 Ball is a toy used for fortune-telling or seeking advice, developed in the 1950s and manufactured by Mattel. It is often used in fiction, often for humor related to its giving very accurate, very inaccurate, or otherwise statistically improbable answers.
The 20 answers inside a standard Magic 8 Ball are:

It is certain
It is decidedly so
Without a doubt
Yes, definitely
You may rely on it
As I see it, yes
Most likely
Outlook good
Yes
Signs point to yes
Reply hazy try again
Ask again later
Better not tell you now
Cannot predict now
Concentrate and ask again
Don’t count on it
My reply is no
My sources say no
Outlook not so good
Very doubtful

 

In this example we will create a Magic 8-ball using an Arduino Uno and an LCD keypad shield, when one of the buttons is pressed a random message will be displayed.

Parts

Arduino Uno
LCD keypad Shield (mine was made by SainSmart)

 

Code

[codesyntax lang=”cpp”]

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

String phrases[] = {"It is certain", "Certainly", "Without a doubt", "You may rely on it", "As I see it, yes", "Most likely", "Outlook good", "Yes", "My reply is no", "Very doubtful", "No", "No chance", "No way", "Cannot predictt",
"I doubt it", "Ask again", "Not sure"};
String output;
int numberofphrases = 17;  //match this with the number of phrases
int key  = 0;

void setup() 
{
  // set up the LCD's number of columns and rows:
  randomSeed(analogRead(5)); 
  lcd.begin(16, 2);
  lcd.print("MAGIC 8 BALL");
}

void loop() 
{
  lcd.setCursor(0, 0);
  key = analogRead(0); 
  if(key < 1000)
  {
    lcd.clear();
    output = phrases[random(numberofphrases)]; //Chooses phrase
    lcd.print(output);
  }
  delay(300);
}

[/codesyntax]

Related posts

Arduino and GY-21P readings on a web page

MPL3115A2 sensor readings displayed on a web page

Adafruit Neopixel shield examples