Arduino Fortune Teller

20,762

55

28

Intro: Arduino Fortune Teller

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

Step 1: Step 1

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: Step 2

Check that the code and screen work.

Step 3: Step 3

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: Step 4

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: Step 5

Work is complete - get a fortune!

Step 6: 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);
}

Share

    Recommendations

    • Electronics Tips & Tricks Challenge

      Electronics Tips & Tricks Challenge
    • Plastics Contest

      Plastics Contest
    • Optics Contest

      Optics Contest

    28 Discussions

    0
    None

    Thank you. I already have the push button switch hooked up in that manner. The switch I was asking about is the standard 4 pin one you have on the white bread board at the top (in your photo). I am wondering what that one is for and what pin you have that one hooked to. I see the one laying off to the side and assumed that is the one you hooked up to pin6. Hmmm... well I suppose I will just keep trying to figure it out. Thanks

    0
    None

    Thank you for your help. I am still having a problem with my switch. I have it hooked up to pin6 and either I have hooked it up improperly or something isn't correct in my code. I have 3 LED's hooked up on a separate breadboard on G, H, I 20-21 connected to pin1 and they are lit but not blinking??? The LCD will give the first fortune automatically and then it reads "push button for fortune" "button needs pushing""push button please" when I push the button I get nothing and then it automatically loops to Fortune Teller Madame Zahara (what we named Robot) thinking.... and it all continues to loop. I see in your photos that you have a separate push button on the main bread board, is this something need to add and if so could you explain connection and what pin#? Again thanks for any help you are able to give to this old learning student.
    I added your code that you gave me like this:
    ********************************************************************************************

    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("Madame Zahara");
    ********************************************************************************************
    lcd.print(" ");
    ********************************************************************************************
    int val = digitalRead(inPin);
    ********************************************************************************************
    if (val == HIGH) // button has been pressed
    {
    ********************************************************************************************
    // 1. go to led animation for "thinking"
    ********************************************************************************************
    // 2. go get fortune and print to screen
    }
    ********************************************************************************************
    Serial.print("Madame Zahara");
    ********************************************************************************************
    delay(2000);
    ********************************************************************************************
    lcd.clear();
    ********************************************************************************************
    lcd.setCursor(0, 0);
    ********************************************************************************************
    lcd.print("Thinking");
    ********************************************************************************************
    for (int i=0; i<4; i++)
    {
    ********************************************************************************************

    2 replies
    0
    None
    PaulysDesignStudent

    Reply 4 years ago on Introduction

    Yes, I have a separate button hooked up to pin 6 like this. On wire from the button goes to +5v. The other wire goes to a 1k resistor. the other side of the resistor goes to ground. Another wire then goes from pin 6 to where the resistor and the wire from the button meet.
    +5V--------------button--------- 1k resistor-------- gnd
    >>>>>>>>>>>>>>>>>>>|
    >>>>>>>>>>>>>>>>>>>|
    Wire to pin 6 goes in here|

    http://arduino.cc/en/Tutorial/Button

    0
    None
    PaulysDesignStudent

    Reply 4 years ago on Introduction

    Yes, I have a separate button hooked up to pin 6 like this.
    http://arduino.cc/en/Tutorial/Button

    +5V--------------button--------- 1k resistor-------- gnd
    |
    |
    pin 6

    0
    None

    This is an awesome project. I am a student at UC Denver and I am doing this as a group project that will be exhibited at CU Boulder next week. My group is new to working with Arduino and we are trying to make the switch and LEDs work. We have a push button switch and do not know quit how to put it in the code so that when power is on and some one walks up to the podium (where our box will be placed) the LCD reads "Push Button for Fortune", Can you help? Currently the LCD continuously loops through ..."push button...Madam...thinking...fortune...lucky #..." Our other issue is wiring the LEDs for the thinking animation. I have the extra breadboard as well to connect the LEDs, could you explain the connection and any code changes (if necessary) to make these work in the thinking animation? Would love to send you pictures of our finished instillation at the Art Center on CU Boulders campus. Truly appreciate any help you can lend. Thank you!

    1 reply
    0
    None
    PaulysDesignStudent

    Reply 4 years ago on Introduction

    It's been a long time since i looked at this code. I believe It gives one fortune automatically on start up then waits for a button press. To avoid that and wait for a pushbutton push try something like this: (Note The pushbutton is defined as pin 6.):
    void loop() {
    int val = digitalRead(inPin);
    if (val == HIGH) // button has been pressed
    {
    // 1. go to led animation for "thinking"
    // 2. go get fortune and print to screen
    }
    Also, here are two good resources to get you going. Good luck making it.
    http://arduino.cc/en/Tutorial/Button
    http://arduino.cc/en/Tutorial/BlinkWithoutDelay

    0
    None
    rconnell

    6 years ago on Introduction

    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

    1 reply
    0
    None
    Paulysrconnell

    Reply 6 years ago on Introduction

    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);
    }

    0
    None
    fmoser

    7 years ago on Introduction

    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.

    1 reply
    0
    None
    kimbo84

    7 years ago on Introduction

    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

    1 reply
    0
    None
    Paulyskimbo84

    Reply 7 years ago on Introduction

    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);
    }

    0
    None
    jman 31

    8 years ago on Introduction

    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

    1 reply
    0
    None
    Paulysjman 31

    Reply 8 years ago on Introduction

    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.

    0
    None
    sweenes

    9 years ago on Introduction

    thanks, great instructable...you inspired me to make a similar arduino/lcd project with a temp sensor-

    2 replies
    0
    None
    Paulyssweenes

    Reply 9 years ago on Introduction

    Did you use an LM35 temp sensor? I had good success with that one. What was your project?

    0
    None
    sweenesPaulys

    Reply 9 years ago on Introduction

    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-

    0
    None
    chilll2009

    9 years ago on Introduction

    Looks fun and easy. You can also find other ways to program it!

    0
    None
    amando96

    9 years ago on Introduction

    thats nice! i think i'm gonna suck at programming :(