Crystal Ball: Making a magic 8 ball from a LCD display and a tilt sensor
The basis of this project was having a Liquid Crystal Display (LCD) print messages (just as a magic 8 ball would) on its screen after you would have flipped it. LCD's work by magnetizing crystals in the liquid, and they create shadows that appear as the text in the display.
The parts needed are the LCD, tilt sensor, and a variety of resistors, as well as a ton of wire. The LCD has 16 inputs, for a variety of reasons (which I am still learning), but some of the main ones are: Pin 1 being negative, pin 16 being negative for backlight, pin 15 being positive for backlight, and pin 5, which determines if it is read or write mode based on a HIGH or LOW input.The code works by using a switch case and a random number generator to change the text prompt every time the tilt switch detects movement. The prevSwitchState is there so that you cannot get the same case twice in a row, and multiples are impossible. The lcd.begin tell the LCD how much we are going to use (16 characters wide, 2 deep), and the set cursor tells the LCD the starting writing point.
This project was fun and easy to complete. I had on slight setback where I forgot to attach the tilt sensor into the board so it didn't read, but besides that operator error, the code and Arduino went off without a hitch. This project would be a real fun one to show off, as getting people to ask questions and give them their answer is a neat trick to explain and show how it works.






Comments
Post a Comment