jsheng
Published

Magic 8 Arduino

A fortune-telling device similar to a Magic 8 Ball

IntermediateShowcase (no instructions)4,193
Magic 8 Arduino

Things used in this project

Hardware components

Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
Assuming you soldered the header pins in
×1
Arduino UNO
Arduino UNO
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Buzzer
Buzzer
×1
1M Ohm Resistor
×1
Resistor 221 ohm
Resistor 221 ohm
I used 220 Ohm
×1

Story

Read more

Schematics

Magic 8 Arduino

Wiring for Magic 8 Arduino

Code

Magic 8 Arduino

C/C++
Detects knock on piezo buzzer and displays lcd messages
#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

const int knockSensor = A0;
const int threshold = 7;

int sensorReading = 0;

String messages[] = {"Yes", "No", "Try again", "Maybe", "Definitely", "Most likely", "Probably not"};

void setup() {
  lcd.begin(16,2);
  lcd.print("Knock to begin!");
}

void loop() {
  lcd.setCursor(0, 0);   //column 0, line 0
  
  sensorReading = analogRead(knockSensor);
  
  if (sensorReading >= threshold) { 
    for (int i = 0; i < 5 ; i++) { 
      String randomMessage = messages[random (0, 6)];
      lcd.clear();
      lcd.print(randomMessage);
      delay(i*170);
    }
    String randomMessage = messages[random (0, 6)];
    lcd.clear();
    lcd.print(randomMessage);
  }
  delay(0);
  //to avoid overloading Serial Port
}

Credits

jsheng

jsheng

0 projects • 14 followers

Comments