Arduino Fortune Teller

by Paulys in Circuits > Arduino

23693 Views, 58 Favorites, 0 Comments

Arduino Fortune Teller

Cigar Box Complete.JPG
This project gives the user a fortune and lucky number like from a fortune cookie. This was made as a Christmas present.

Step 1

Innards.JPG
Solder header pins onto LCD. Solder wires to female header pins and hookup to Arduino. Here we used the LCD 4 bit Library and hooked it up accordingly. This is slightly different the using the 8 bit library.

Step 2

Message.JPG
Check that the code and screen work.

Step 3

Cigar Box 1.JPG
Cigar Box 2.JPG
Using an old cigar box I created a shell for this project. I had to cut 4 holes for the LEDS, 1 hole for the LCD, 1 hole for the on/off switch and 1 for the button.

Step 4

Cigar Box 4.JPG
Now for the tricky part, stuff all the wires into the box!
Here we hookup the battery by itself to the on/off switch, stuff everything inside and hookup all the LEDs.

Step 5

Cigar Box Complete.JPG
Fortune.JPG
Work is complete - get a fortune!

Fortune Teller Code

#include <LCD4Bit.h>
#define countof(array) ( sizeof(array) / sizeof(*(array)) )
LCD4Bit lcd = LCD4Bit(2);
// Todd Miller 2008
int ledPin = 13; // choose the pin for the LED
int inPin = 4; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int pos1 = 1;
int pos2 = 0;
int x=0;
int b = 0;
int y = 0;
int tv = 0;
int tv2 = 0;
long previousMillis = 0; // will store last time LED was updated
long interval = 1100; // interval at which to blink (milliseconds)
char *msgs1= {"A promotion is","You will soon","Laughter is the","Live long and", "Laugh hard and", "Eat well and", "A creative ","Someone", "A merry heart","Seize the day.","You are","Wealth is","Happy times","I see robots","Smile and you","Luck will soon"};
char *msgs2 = {"coming soon.","be happy.","best medicine.","prosper.", "laugh often.", "make merry.", "mind is yours.","loves you.","is good.", " ","very lucky!", "soon yours.", "are ahead.", "in your future.","will be rich.","follow you."};
char *msgs3 = {"!","@","#","$", "%", "&", "* ","@", "?","="};
char *msgs4= {"1","2","3","4", "5", "6", "7","8", "9","10","11","12","14","15","16","17","18","19","20"};
int NUM_MSGS = 11;
int NUM_MSGS2 = 19;
int i=0;
char my_str ;

void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
pinMode(0,INPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(3, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
Serial.begin(9600);
randomSeed(analogRead(0));

}

void loop() {
digitalWrite(13, HIGH);
lcd.init();
lcd.printIn("Fortune Teller");
lcd.cursorTo(2, 0);
lcd.printIn("Robot 3000");
delay(2000);
lcd.clear();
lcd.cursorTo(1, 0);
lcd.printIn("Thinking");
for (int i=0; i<3; i++)
{
lcd.print('.');
delay(400);
animation();
}
lcd.cursorTo(1, 0);
lcd.clear();
for (int i=0; i<9; i++)
{
pos2=pos2+1;
pos1=pos1+i;
int pick = random(NUM_MSGS);
int randy = random(1,10);
char* msg3 = msgs3;
lcd.printIn(msg3);
delay(300);
if (pos2>= 2) pos2=0;
animation();

}

lcd.clear();
lcd.cursorTo(1, 0);
lcd.printIn("Your");
lcd.cursorTo(2, 0);
lcd.printIn("fortune is");
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
digitalWrite(3, HIGH);
delay(1200);

for (int i=0; i<3; i++)
{
lcd.print('.');
delay(300);
}

lcd.leftScroll(20, 50);
lcd.clear();

//pick a random message from the array
int rind= random(1,21)-10;
if (rind == x)
{
rind=rind+1;
}
else
{
rind= random(rind);
}

x=rind;
int randNumber= random(1, countof(msgs1));
char* msg1 = msgs1;
char* msg2 = msgs2;
lcd.printIn(msg1);
lcd.cursorTo(2, 0);
lcd.printIn(msg2);
delay(2500);
lcd.clear();
int pick2 = random(NUM_MSGS2);
char* msg4 = msgs4;
lcd.cursorTo(1, 0);
strcpy(my_str, "number is ");
strcat(my_str, msg4);
strcat(my_str, ".");
lcd.printIn("Your lucky");
lcd.cursorTo(2, 0);
lcd.printIn(my_str);

delay(1200);
for (int i=0; i<3; i++){
lcd.print('.');
delay(300);
}
delay(300);
lcd.leftScroll(20, 50);
lcd.clear();
lcd.cursorTo(1, 0);

val = digitalRead(inPin); // read input value

animation2();
}
void animation()
{
if (i = 1) digitalWrite(6, HIGH); //light the firstLED
if (i = 1 ) digitalWrite(5, LOW); //light the firstLED
if (i = 1 ) digitalWrite(3, LOW); //light the firstLED
delay(70);
if (i = 2 ) digitalWrite(6, LOW); //light the firstLED
if (i = 2 ) digitalWrite(5, HIGH); //light the firstLED
if (i = 2 ) digitalWrite(3, LOW); //light the firstLED
delay(70);
if (i = 3 ) digitalWrite(6, LOW); //light the firstLED
if (i = 3 ) digitalWrite(5, LOW); //light the firstLED
if (i = 3 ) digitalWrite(3, HIGH); //light the firstLED
delay(70);
if (i = 9 ) digitalWrite(6, LOW); //light the firstLED
if (i = 9 ) digitalWrite(5, LOW); //light the firstLED
if (i = 9 ) digitalWrite(3, LOW); //light the firstLED

}

void animation2()
{
digitalWrite(13, HIGH);
do {
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
b = 0;

} else {
b = 1;
y=0;
tv=0;
tv2=0;
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(3, LOW);// turn LED ON
}

if (millis() - previousMillis > interval) {
previousMillis = millis(); // remember the last time we printed
tv = tv +1;
tv2=tv2+1;
if (tv == 1)
{
lcd.clear();
lcd.printIn("Fortune Teller");
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(3, LOW);
}
if (tv == 2)
{

lcd.cursorTo(2,0);
lcd.printIn("Robot 3000");
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(3, LOW);
}

if (tv == 3 && tv2 !=9 && tv2 !=10)
{
lcd.clear();
lcd.cursorTo(1,0);
lcd.printIn("Push the button");
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
digitalWrite(3, LOW);

}
if (tv == 4 && tv2 !=9 && tv2 !=10)
{
lcd.cursorTo(2,0);
lcd.printIn("for a fortune!");
digitalWrite(6, LOW);
digitalWrite(5, LOW);
digitalWrite(3, HIGH);

}

if (tv2==7)
{
lcd.clear();
lcd.cursorTo(1,0);
lcd.printIn("Your fortune");
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(3, LOW);

}
if (tv2==8)
{
lcd.cursorTo(2,0);
lcd.printIn("awaits you.");
digitalWrite(6, LOW);
digitalWrite(5, HIGH);
digitalWrite(3, LOW);
tv=0;
tv2=0;

}

}
} while (b==0);
}