There are varieties of electronic display system display systems in this world from simple LED display to high end laser display systems. Most of them are a using some predefined pattern of display which is then repeated again and again. There is also another kind of display systems which use a random pattern of display and hence differ from other kind in terms of working and attractiveness. This particular project explains how to display smileys in a 16x2 LCD in a random manner with the help of an Arduino board. The Arduino is referred to as an easy prototyping platform which has been popular among both hobbyist and experts and widely used in industries as well. Any AVR microcontroller based board which follows the standard Arduino schematic and is flashed with the Arduino bootloader can be called an Arduino board. All the Arduino boards are compatible with the Arduino IDE which helps to compile the code and program the Arduino boards.
The Arduino IDE is very simple to use and anyone having the basic knowledge of C programming can easily start with it. The Arduino IDE provides lot of built-in functions and among them there are functions for accessing LCD modules and generating random numbers also.
There are different varieties of Arduino boards available among which one can find a board which suits the particular application. In this project the Arduino pro-mini board is used since it comes in very small in size and any kind of connectors can be soldered on its periphery according to our requirements. It is very breadboard friendly and occupies very less space of a typical breadboard.
The image of the arduino pro-mini board and the arduino IDE are shown below;
Fig. 2: Typical Arduino Pro-Mini Board
Fig. 3: Arduino IDE Software Window
Since the arduino pro-mini board has no circuitary for interfacing it with the serial port or the USB port of the PC, an external USB to TTL converter board is required to connect it with the PC. This hardware helps in programming the arduino board and also helps in the serial communication with the USB port of the PC.
Fig. 4: External USB to TTL converter board for programming Arduino and serial communication
It is assumed that the reader has gone through the project how to get started with the arduino and tried out all the things discussed there.
randomSeed()
randomSeed() initializes the pseudo-random number generator, causing it to start at an arbitrary point in its random sequence. This function has a parameter which decides from which point in the sequence should the random number generation starts. To initialize the pseudo-random number generator with a new sequence each and every time, the value provided as the parameter should also be different.
This particular code reads a random value from the analog input pin A0 which is left unconnected so that each and every time the code runs it can generate different set of random numbers.
random()
The function random() is used to generate pseudo-random number which falls in a specified range. The function is always called after calling the randomSeed() function. This function has two parameters of which the first one is the lowest required value and the second one is the largest required value.
To get a different set of random numbers the function randomSeed() is provided with a random value which can be read from the unconnected analog pin A0. The analog value is read with the help of the function analogRead() which is already used in the previous projects on how to use analog input and analog output of Arduino board, how to use Arduino to display sensor values, how to make dynamic sensor display using Arduino, how to save sensor values in the EEPROM of the Arduino.
The Arduino IDE provides a library called <LiquidCrystal.h> which can be used to interface an external LCD module with the Arduino board. The functions which can be used to access the LCD are already discussed in previous projects on how to interface an LCD , how to display sensor value on LCD, how to connect the LCD with the PC and how to make an LCD scrolling display.
In this project two different smileys are generated which are then displayed in a random manner across the LCD screen. The previous projects on how to generate smileys in an LCD and how to create animation in an LCD discuss about the method of generating smileys.The code also blinks an LED connected to the pin number 6 of the Arduino board using the functions pinMode(),digitalWrite() and delay() which are explained in the previous projects on how to get started with the Arduino board and how to use the digital input and output of the Arduino board.
The code simply generates a random number and displays the smileys in the first and second line of the 16*2 LCD with an offset given by the random number generated within the range 0 to 16.
Project Source Code
### /*============================ EG LABS ===================================// Demonstration on how to make a random smiley display in an LCD * LED anode attached to digital output 6 * LED cathode attached to ground through a 1K resistor //============================ EG LABS ===================================*/ // include the library code: #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //----------------- store the custom characters in arrays ---------------------// byte heart[8] = { 0b00000, 0b01010, 0b11111, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000 }; byte smile[8] = { 0b00000, 0b00000, 0b01010, 0b00000, 0b10001, 0b01110, 0b00000, 0b00000 }; //----------------- store the custom characters in arrays ---------------------// long randNumber; // the variable which is supposed to hold the random value const int ledPin = 6; // the number of the pin at which the LED is connected void setup() { pinMode(ledPin, OUTPUT); //---- create custom characters ----// lcd.createChar(1, heart); lcd.createChar(2, smile); //---- create custom characters ----// // set up the lcd's number of columns and rows: lcd.begin(16, 2); lcd.print("ENGINEERS GARAGE"); lcd.setCursor(0, 1); lcd.print(" RANDOM SMILEYS "); delay(3000); Serial.begin(9600); // initialize the serial port randomSeed(analogRead(0)); // initialize the pseudo-random number generator } void loop() { digitalWrite(ledPin, HIGH); // LED ON randNumber = random(0, 16); // generate a random number lcd.setCursor(randNumber, 0); // set the cursor at the cursor position given by the random number at first line lcd.write(1); // display snmiley 1 lcd.setCursor(randNumber, 1); // set the cursor at the cursor position given by the random number at second line lcd.write(2); // display snmiley 1 randNumber = random(0, 16); // generate a random number lcd.setCursor(randNumber, 0); // set the cursor at the cursor position given by the random number at first line lcd.write(2); // display snmiley 2 lcd.setCursor(randNumber, 1); // set the cursor at the cursor position given by the random number at second line lcd.write(1); // display snmiley 1 delay(250); // wait for a while digitalWrite(ledPin, LOW); // LED OFF delay(250); // wait for a while lcd.clear(); // clear the LCD } ###
Circuit Diagrams
Project Components
Project Video
Filed Under: Arduino Projects
Filed Under: Arduino Projects
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.