Arduino Basics Lesson 2-3: (Liquid) Crystal Ball

Arduino Basics Lesson 2-3: (Liquid) Crystal Ball

For the “Arduino For Kooks” course, I recommend you get the Arduino Starter Kit available here.

The Arduino, despite its simplicity, is a very powerful electronics platform and it can do so much more than blink LEDs or make noises with a buzzer. In this project, we’re going to connect a simple character LCD to the Arduino and use it to display some randomly selected custom text.

The Circuit:

Start by connecting +5V and GND to their respective busses on the breadboard. Use a jumpers to connect one side of a tactile switch to +5V and the other side to D8. Also connect a 10KR resistor to GND to act as a pull-down and prevent the pin from floating.

Connect a 10KR rotary potentiometer’s + and – pins to +5V and GND respectively while connecting the drain pin to pin 3 on the LCD. Finally, connect the LCD pins as shown in the schematic below:

The Sketch:

#include

LiquidCrystal lcd(12,11,5,4,3,2); // generates an instance in the lcd

const int switchPin = 6;
int switchState = 0;
int prevSwitchState = 0;
int reply;

void setup() {
lcd.begin(16,2);

pinMode(switchPin, INPUT);
lcd.print("I AM THE GREAT");
lcd.setCursor(0,1); // changes the Cursor to continue writing in the second row
lcd.print("ZOLDUINO");
}

void loop() {
switchState=digitalRead(switchPin);

if (switchState != prevSwitchState) {
if (switchState == LOW) {
reply = random(8);
lcd.clear(); // clears the screen
lcd.setCursor(0,1);

switch(reply){ // the program will enter the case
assigned to the switch
case 0:
lcd.print("Si");
break;
case 1:
lcd.print("It's probable");
break;
case 2:
lcd.print("It is certain");
break;
case 3:
lcd.print("Outlook good");
break;
case 4:
lcd.print("It is unclear");
break;
case 5:
lcd.print("Ask again");
break;
case 6:
lcd.print("I have no idea");
break;
case 7:
lcd.print("No");
break;
}
}
}

}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.