Project showcase
Magic 8 Arduino

Magic 8 Arduino

A fortune-telling device similar to a Magic 8 Ball

  • 1,993 views
  • 0 comments
  • 3 respects

Components and supplies

About this project

I made this project because I wanted to refresh my Arduino skills. It has been a while since I've used the Arduino, so I decided to come back to it.

Code

Magic 8 ArduinoC/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
}

Schematics

Magic 8 Arduino
Wiring for Magic 8 Arduino
magic_8_arduino_jaqRNknXqZ.fzz

Comments

Similar projects you might like

Ask the Magic 8 Ball!

Project tutorial by Team College Bound

  • 1,714 views
  • 0 comments
  • 7 respects

Magic Arduino Ball

Project showcase by Ruben Zilzer

  • 2,087 views
  • 1 comment
  • 6 respects

Magic Cauldron

Project showcase by Ian McKay

  • 5,801 views
  • 3 comments
  • 21 respects

Ultrasonic Sensor with Alarm, LCD and Temperature

Project tutorial by MichDragstar

  • 4,645 views
  • 7 comments
  • 19 respects

RFID Based Automatic Door System

Project showcase by Robodia Technology

  • 35,854 views
  • 20 comments
  • 97 respects

The Magnetic Field and RGB Tester

Project tutorial by Kutluhan Aktar

  • 3,530 views
  • 0 comments
  • 14 respects
Add projectSign up / Login