Arduino Fortune Teller

 by Paulys
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.
 
Remove these adsRemove these ads by Signing Up
rconnell says: Oct 16, 2012. 6:07 AM
this looks like a cool project but when i tried to program the arduino i got 'LCD4Bit' does not name a type so can you help me
Paulys (author) in reply to rconnellOct 16, 2012. 8:47 AM
Hi,
I have not used this in a while.
Try using the code below
You should include the Liquid Crystal library and maybe the Wire library.
If you are missing either of these , look at http://arduino.cc/en/Reference/Libraries .
Also make sure you wire up the pins correctly to (12, 11, 5, 4, 3, 2);

Hope this helps.

#include
#define countof(array) ( sizeof(array) / sizeof(*(array)) )
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//
int ledPin = 1; // choose the pin for the LED
int inPin = 6; // 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 z=0;
int custom_0[] = {0x0e, 0x0e, 0x04, 0x0e, 0x1b, 0x0a, 0x0e, 0x11};
long previousMillis = 0; // will store last time LED was updated
long interval = 1100; // interval at which to blink (milliseconds)
char *msgs1[] = {"Live long and","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","You will", "Flattery will","The world is", "Little and often", "Trust your", "Wall-e is", "Trust", "Time to start", "May the force"};
char *msgs2[] = {"prosper","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.","prosper.", "get you far.", "your oyster.", "makes much.", "intuition.", "your friend.", "the collective.","something new.", "be with you."};
//("You will", "Flattery will", "The world is", "Little and often", "Trust your", " Wall-e is", "Trust", "Time to start", "May the force");
//("prosper.", "get you far.", "your oyster." "makes much.", "intuition.", "your friend.", "the collective.","something new.", "be with 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[100];

// Define a custom char in lcd
int defineCharacter(int ascii, int *data) {
int baseAddress = (ascii * 8) + 64;
// baseAddress = 64 | (ascii << 3);
lcd.command(baseAddress);
for (int i = 0; i < 8; i++)
lcd.write(data[i]);
lcd.command(128);
return ascii;
}

void setup() {
defineCharacter(0, custom_0);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
pinMode(0,INPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
randomSeed(analogRead(0));

}

void loop() {
digitalWrite(13, HIGH);
delay(1000);
lcd.begin(16,2);
lcd.setCursor(0, 0);
lcd.print("Fortune Teller");
Serial.print("Fortune Teller ");
lcd.setCursor(0,1);
lcd.print("Robot 3000");
lcd.print(" ");
lcd.write(0);
Serial.print("Robot 3000");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Thinking");
for (int i=0; i<4; i++)
{
lcd.print('.');
delay(200);
}
lcd.setCursor(0, 1);

lcd.print((char)229);
lcd.print(" ");
delay(200);
lcd.print((char)224);
lcd.print(" ");
delay(200);
lcd.print((char)225);
lcd.print(" ");
delay(200);
lcd.print((char)226);
lcd.print(" ");
delay(200);
lcd.print((char)227);
lcd.print(" ");
delay(200);
lcd.print((char)218);
lcd.print(" ");
delay(200);
lcd.print((char)216);

animation();

lcd.setCursor(0, 0);
delay(200);
for (int i=0; i<9; i++)
{
// pos2=pos2+1;
// pos1=pos1+i;
// int pick = random(NUM_MSGS);
// int randy = random(1,20);
// char* msg3 = msgs3[randy];
// lcd.print(msg3);
delay(100);
// if (pos2>= 2) pos2=0;
animation();

}

lcd.clear();
lcd.setCursor(0,0);
lcd.print("Your");
lcd.setCursor(0, 1);
lcd.print("fortune is");
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
delay(200);

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

delay(2000);
lcd.clear();

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

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

delay(1200);
for (int i=0; i<3; i++){
lcd.print('.');
delay(100);
}
delay(100);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);

val = digitalRead(inPin); // read input value
animation4 ();
b=0;
// animation2();
}
void animation()
{
if (i = 1) digitalWrite(7, HIGH); //light the firstLED
if (i = 1 ) digitalWrite(8, LOW); //light the firstLED
if (i = 1 ) digitalWrite(9, LOW); //light the firstLED

delay(100);
if (i = 2 ) digitalWrite(7, LOW); //light the firstLED
if (i = 2 ) digitalWrite(8, HIGH); //light the firstLED
if (i = 2 ) digitalWrite(9, LOW); //light the firstLED

delay(100);
if (i = 3 ) digitalWrite(7, LOW); //light the firstLED
if (i = 3 ) digitalWrite(8, LOW); //light the firstLED
if (i = 3 ) digitalWrite(9, HIGH); //light the firstLED

delay(100);
if (i = 9 ) digitalWrite(7, LOW); //light the firstLED
if (i = 9 ) digitalWrite(8, LOW); //light the firstLED
if (i = 9 ) digitalWrite(9, LOW); //light the firstLED
}

void animation4 ()
{
Serial.print(" b = ");
Serial.println(b);

delay(25);
do{
val = digitalRead(inPin); // read input value
if (val == HIGH)
{
b=1;
}
if (x!=300){
lcd.setCursor(0,0);
lcd.print("Push the button");
lcd.setCursor(0,1);
val = digitalRead(inPin);
lcd.print("for a fortune!");
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
x++;
}
if(x>=300)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Button needs");
lcd.setCursor(0,1);

digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
val = digitalRead(inPin);
delay(1250);

lcd.print("pushing!");
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
val = digitalRead(inPin);
delay(2000);
x=0;
lcd.clear();
Serial.print(x);
Serial.print(" z ");
Serial.println(z);
val = digitalRead(inPin);
z++;
if (z>=2)
{
lcd.setCursor(0,0);
lcd.print("Push the");
lcd.setCursor(0,1);
val = digitalRead(inPin);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
delay(1250);
lcd.print("button please!");
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
val = digitalRead(inPin);
delay(2000);
z=0;
}
}
}
while (b==0);
}
fmoser says: Sep 19, 2011. 8:53 AM
I want to take that a step further, with several buttons to get random entries from different fortune files. (fortune database)
I'm probably going to use a 40x4 display, and an SD card.
Paulys (author) in reply to fmoserSep 20, 2011. 4:08 AM
Cool. Let us know how it turns out fmoser.
kimbo84 says: Dec 2, 2010. 9:58 AM
Hii new to instructables and programming... I have compiled the code you provided for the fortune teller only i receive and error in the first instance!

**line of code highlighted**
LCD4Bit lcd = LCD4Bit(2);

**Error message**
LCD4Bit DOES NOT NAME A TYPE

Can you please explain why and how to fix this please :)

Thanks

Paulys (author) in reply to kimbo84Dec 2, 2010. 5:58 PM
Hi,
I have not used this in a while.
Try using the code below
You should include the Liquid Crystal library and maybe the Wire library.
If you are missing either of these , look at http://arduino.cc/en/Reference/Libraries .
Also make sure you wire up the pins correctly to (12, 11, 5, 4, 3, 2);

Hope this helps.

#include
#define countof(array) ( sizeof(array) / sizeof(*(array)) )
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Todd Miller 2008
int ledPin = 1; // choose the pin for the LED
int inPin = 6; // 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 z=0;
int custom_0[] = {0x0e, 0x0e, 0x04, 0x0e, 0x1b, 0x0a, 0x0e, 0x11};
long previousMillis = 0; // will store last time LED was updated
long interval = 1100; // interval at which to blink (milliseconds)
char *msgs1[] = {"Live long and","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","You will", "Flattery will","The world is", "Little and often", "Trust your", "Wall-e is", "Trust", "Time to start", "May the force"};
char *msgs2[] = {"prosper","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.","prosper.", "get you far.", "your oyster.", "makes much.", "intuition.", "your friend.", "the collective.","something new.", "be with you."};
//("You will", "Flattery will", "The world is", "Little and often", "Trust your", " Wall-e is", "Trust", "Time to start", "May the force");
//("prosper.", "get you far.", "your oyster." "makes much.", "intuition.", "your friend.", "the collective.","something new.", "be with 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[100];

// Define a custom char in lcd
int defineCharacter(int ascii, int *data) {
int baseAddress = (ascii * 8) + 64;
// baseAddress = 64 | (ascii << 3);
lcd.command(baseAddress);
for (int i = 0; i < 8; i++)
lcd.write(data[i]);
lcd.command(128);
return ascii;
}

void setup() {
defineCharacter(0, custom_0);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
pinMode(0,INPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
randomSeed(analogRead(0));

}

void loop() {
digitalWrite(13, HIGH);
delay(1000);
lcd.begin(16,2);
lcd.setCursor(0, 0);
lcd.print("Fortune Teller");
Serial.print("Fortune Teller ");
lcd.setCursor(0,1);
lcd.print("Robot 3000");
lcd.print(" ");
lcd.write(0);
Serial.print("Robot 3000");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Thinking");
for (int i=0; i<4; i++)
{
lcd.print('.');
delay(200);
}
lcd.setCursor(0, 1);

lcd.print((char)229);
lcd.print(" ");
delay(200);
lcd.print((char)224);
lcd.print(" ");
delay(200);
lcd.print((char)225);
lcd.print(" ");
delay(200);
lcd.print((char)226);
lcd.print(" ");
delay(200);
lcd.print((char)227);
lcd.print(" ");
delay(200);
lcd.print((char)218);
lcd.print(" ");
delay(200);
lcd.print((char)216);

animation();

lcd.setCursor(0, 0);
delay(200);
for (int i=0; i<9; i++)
{
// pos2=pos2+1;
// pos1=pos1+i;
// int pick = random(NUM_MSGS);
// int randy = random(1,20);
// char* msg3 = msgs3[randy];
// lcd.print(msg3);
delay(100);
// if (pos2>= 2) pos2=0;
animation();

}

lcd.clear();
lcd.setCursor(0,0);
lcd.print("Your");
lcd.setCursor(0, 1);
lcd.print("fortune is");
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
delay(200);

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

delay(2000);
lcd.clear();

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

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

delay(1200);
for (int i=0; i<3; i++){
lcd.print('.');
delay(100);
}
delay(100);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);

val = digitalRead(inPin); // read input value
animation4 ();
b=0;
// animation2();
}
void animation()
{
if (i = 1) digitalWrite(7, HIGH); //light the firstLED
if (i = 1 ) digitalWrite(8, LOW); //light the firstLED
if (i = 1 ) digitalWrite(9, LOW); //light the firstLED

delay(100);
if (i = 2 ) digitalWrite(7, LOW); //light the firstLED
if (i = 2 ) digitalWrite(8, HIGH); //light the firstLED
if (i = 2 ) digitalWrite(9, LOW); //light the firstLED

delay(100);
if (i = 3 ) digitalWrite(7, LOW); //light the firstLED
if (i = 3 ) digitalWrite(8, LOW); //light the firstLED
if (i = 3 ) digitalWrite(9, HIGH); //light the firstLED

delay(100);
if (i = 9 ) digitalWrite(7, LOW); //light the firstLED
if (i = 9 ) digitalWrite(8, LOW); //light the firstLED
if (i = 9 ) digitalWrite(9, LOW); //light the firstLED
}



void animation4 ()
{
Serial.print(" b = ");
Serial.println(b);

delay(25);
do{
val = digitalRead(inPin); // read input value
if (val == HIGH)
{
b=1;
}
if (x!=300){
lcd.setCursor(0,0);
lcd.print("Push the button");
lcd.setCursor(0,1);
val = digitalRead(inPin);
lcd.print("for a fortune!");
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
x++;
}
if(x>=300)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Button needs");
lcd.setCursor(0,1);

digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
val = digitalRead(inPin);
delay(1250);

lcd.print("pushing!");
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
val = digitalRead(inPin);
delay(2000);
x=0;
lcd.clear();
Serial.print(x);
Serial.print(" z ");
Serial.println(z);
val = digitalRead(inPin);
z++;
if (z>=2)
{
lcd.setCursor(0,0);
lcd.print("Push the");
lcd.setCursor(0,1);
val = digitalRead(inPin);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
delay(1250);
lcd.print("button please!");
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
val = digitalRead(inPin);
delay(2000);
z=0;
}
}
}
while (b==0);
}
jman 31 says: Jan 10, 2010. 7:31 AM
Hi Paulys,

This is a really neat project. Do you have a schematic for it, or a wiring diagram? I am trying to understand how to make an LCD interactive project and yours seems like a good place to learn. I don't have a grasp on how the momentary button interacts with the LCD menu.

Thanks for any advice,
Jeremy
Paulys (author) in reply to jman 31Jan 10, 2010. 11:24 AM
Sorry Jman, no diagram.  I did this over a year ago.  I would start with the LiquidCrystal tutorial if you haven't already.  http://www.arduino.cc/en/Tutorial/LiquidCrystal.
For the button, basically I' m suing a do while loop.  I animate the LEDS while b=0.  If b<>0, then I go grab a new fortune.

Good luck.
Mario1 says: Oct 4, 2009. 4:15 PM
there is no tutorial ..?
sweenes says: Jun 15, 2009. 7:55 PM
thanks, great instructable...you inspired me to make a similar arduino/lcd project with a temp sensor-
Paulys (author) in reply to sweenesJun 20, 2009. 6:14 PM
Did you use an LM35 temp sensor? I had good success with that one. What was your project?
sweenes in reply to PaulysJun 22, 2009. 6:27 PM
Yup I used an LM35..fried the first one when I connected it wrong so I was glad I bought two! The project was a cigar box with lcd with temp sensor poking out. Every 10 secs the arduino will refresh the reading and print to the lcd...thinking about adding more sensors, maybe humidity or something-
chilll2009 says: Jun 21, 2009. 7:48 AM
Looks fun and easy. You can also find other ways to program it!
amando96 says: Feb 7, 2009. 8:30 AM
thats nice! i think i'm gonna suck at programming :(
chilll2009 in reply to amando96Jun 20, 2009. 3:25 PM
just copy and paste-duh '=' !!!!!
amando96 in reply to chilll2009Jun 20, 2009. 4:11 PM
i wasnt refering to this just programming in general, and btw i can do almost anything in C by now...
dnhoshor says: Mar 22, 2009. 8:31 PM
I'm just getting into the arduino stuff, and this looks like a fun, do-able project. I think I'd add a coin slot so that when a coin is inserted, it closed the circuit to start the fortune teller.
tornadoboy in reply to dnhoshorMay 30, 2009. 7:11 PM
Try finding a Nintendo arcade game coin mech on Ebay (Mario Bros, Player's Choice 10, etc), they're compact, don't require a full size coin door to mount to and turn up on there for next to nothing sometimes.
diaz says: Feb 4, 2009. 4:51 AM
Great project! I'd like to see a parts list and sources for the parts.
Paulys (author) in reply to diazFeb 5, 2009. 3:45 AM
Thanks Diaz.
I used a 16 x 2 LCD from Sparkfun, 4 LEDs, an Arduino from Sparkfun, 2 2.2 resisitors to connect the backlight on the LCD, a pushbutton switch and a small slider type switch to turn it on and off. I also used male headers to solder to the LCD and corresponding female headers to connect the wires to the breadboard. You can also buy some of thes parts at Adafruit as well, although they don't sell the LCDs.
Bongmaster says: Jan 11, 2009. 1:11 PM
u seem to have "link is invalid" throughout the code. the project looks nice tho :)
Paulys (author) in reply to BongmasterJan 11, 2009. 3:23 PM
Thanks, I fixed it. for some reason Instructables doesn't like square brackets. If you need the actual code, download the .PDE file in step 5 and convert it to a .TXT file.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!