Introduction: Arduino Excuse Generator

Picture of Arduino Excuse Generator

Need an excuse in a hurry?

Look no further than the Excuse Generator.

Step 1: What You Need / Wire It Up

Picture of What You Need / Wire It Up

We are using:

        Arduino Uno
        LCD Module (HD44780 compatible)
        Potentiometer
        Tilt Switch
        220 Ohm Resistor (Red-Red-Black-Black)  / (Red-Red-Brown) or 470 Ohm or 560 Ohm is fine too


Wire up the LCD module to the Arduino as listed below and illustrated in the Diagrams.
Don't forget to wire in the Pot and the Tilt Switch too as shown.


Wire up the LCD Module as follows:

    LCD pin (1)   / Vss      -> Gnd
    LCD pin (2)   / Vdd    -> 5V
    LCD pin (4)   / RS      -> 12
    LCD pin (5)   /  R/W  -> Gnd
    LCD pin (6)   / E         -> 11
    LCD pin (11)  / D4      -> 5
    LCD pin (12)  / D5      -> 4
    LCD pin (13)  / D6      -> 3
    LCD pin (14)  / D7      -> 2

In addition you need to wire 5V/Gnd to the A/K of the backlight LED (pins 15/16); and wire in a potentiometer to adjust the contrast (pin 3).

Without the contrast adjustment and the backlight the LCD will not Display anything visible.

Step 2: Here's the Code

Picture of Here's the Code

(Apparently Instructables now Require All Steps to have a picture. So please enjoy this picture of the code on my screen :-)  )

Please double check the =5V/Gnd Wiring. You can PERMANENTLY DAMAGE your board if this is wrong.

Once wired up, try the Hello World! Example to check everything is OK. You may need to adjust the potentiometer to see the Hello World! message.

(File -> Examples -> LiquidCrystal -> HelloWorld)

OK, so let’s proceed.

We’ve attached a tilt sensor to Arduino pin d10 so whenever you tap the sensor it activates an Excuse to be generated.

Here’s the code:

/*
Excuse Generator
by Anthony Kelly

Adapted from Arduino Starter Kit example
Project 11  - Crystal Ball

Parts required:
Arduino UNO
SainSmart LCD (HD44780 compatible)
Tilt Sensor

http://arduino.cc/starterKit

This example code is part of the public domain
*/

// include the library code:
#include <LiquidCrystal.h>
#include <string.h>


// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// set up a constant for the tilt switchPin
const int switchPin = 10;

// variable to hold the value of the switchPin
int switchState = 0;

// variable to hold previous value of the switchpin
int prevSwitchState = 0;

// a variable to choose which reply from the crystal ball
int reply;

int i;


// Define your excuses
char *start []= {"I'm sorry but ","Don't blame me ", "Not my fault ","Guess what happened "};
char *middle []= {"Godzilla ","Chuck Norris ", "Scrooge McDuck ","Soap McTavish"};
char *ends []= {"tried to kill me. ","ate my homework.","came after me.","stole my head."};

int length = 4;


void setup() {
  // set up the number of columns and rows on the LCD
  lcd.begin(16, 2);
  // Set the pullup on the switch pin
  pinMode(switchPin, INPUT);
  digitalWrite(switchPin, HIGH);
}

void loop() {

    // clean up the screen before printing a new reply
  lcd.clear();
    // Print a message to the LCD.
  lcd.print("Need an");
  // set the cursor to column 0, line 1
  // line 1 is the second row, since counting begins with 0
  lcd.setCursor(0, 1);
  // print to the second line
  lcd.print("Excuse?");

  for (i=0; i<4; i++) {


    // loop until the switch has changed from LOW to HIGH
    while (!(switchState ==  HIGH && prevSwitchState == LOW)) {
      // the switch did not change from LOW to HIGH last time
      // Remember the previous switch state from the last iteration
      prevSwitchState = switchState;
      // Read the present state
      switchState = digitalRead(switchPin);
      // delay as a simple debounce
      delay(100);
    }
    // the while loop exited wthout updating
    // the previous switch state so do it now
    prevSwitchState = switchState;

    if (switchState == HIGH) {

      // randomly choose a reply index
      reply = random(length);
      // clean up the screen before printing a new reply
      lcd.clear();
      // set the cursor to column 0, line 0
      lcd.setCursor(0, 0);
      // print some text
      // A different part of the excuse for each for-loop iteration
      switch(i) {
        case 0:lcd.print(start[reply]); break;
        case 1:lcd.print(middle[reply]); break;
        case 2:lcd.print(ends[reply]); break;
      }
    }
  }
}

Step 3: Enjoy

Every time you tap the tilt Sensor a part of an Excuse will be generated.

Don't blame me
Chuck Norris
stole my head


Running out of excuses?

Change these lines to add more:

// Define your excuses
char *start []= {"I'm sorry but ","Don't blame me ", "Not my fault ","Guess what happened "};
char *middle []= {"Godzilla ","Chuck Norris ", "Scrooge McDuck ","Soap McTavish"};
char *ends []= {"tried to kill me. ","ate my homework.","came after me.","stole my head."};

int length = 4;

Comments

us241098 (author)2013-06-19

hi buddy nice instructable!!!! i just tried it . using your idea i want to print maths formulaes on the lcd . and also i dont want to make it that random formulaes are printed when button is pressed. i am a newbie plzz help me

THANKS

akellyirl (author)us2410982013-06-19

1. You need to put your formulae into an Array, replacing the existing definitions.
2. change the array index when printing from 'reply' which is a random number to 'i' that counts from 0 to 3 (actually length-1).

Give this a try:

// Define your Formulae and the number of them in the array
char *start []= {"area = pi*r^2 ","y=mx+c ", "area=wh/2 ","r^2=x^2+y^2 "};

int length = 4;
..
...
...
REPLACE:
switch(i) {
case 0:lcd.print(start[reply]); break;
case 1:lcd.print(middle[reply]); break;
case 2:lcd.print(ends[reply]); break;
}

WITH:
lcd.print(start[i]);

much funnier with lambdas, when start[] is an array of pointers to functions :-)

us241098 (author)2013-06-20

IT WORKED !!!!!!!! Thanks sir you are awesome. Sir could you give me one more favour. i want different formula to print when 2 different switches are pressed . for e.g if switch 1 is pressed then pi r^2 is printed when switch 2 is pressed then vol. of cube.
THANKS

About This Instructable

5,337views

17favorites

License:

Bio: Technologist, Electronic Engineer, sometime Coderdojo mentor.
More by akellyirl:Arduino Guitar Tuner Using DSP TechniquesSmart Home ThermostatArduino Yun Messager
Add instructable to: