In this project, I will explain the circuit and working of a Random Number Generator using 8051 Microcontroller i.e. I will show you how to generate a random number using 8051 microcontrollers.

This project generates a random number between 0 to 100 when a push button is pressed. This is a simple project and you may not find any serious applications in embedded projects. The project work is just a demonstration.

### Circuit Principle of Random Number Generator using 8051

Random number generator is a physical device which generates a number randomly in a certain limit when a button is pressed. In this project LCD (liquid crystal display) displays the number randomly when push button (which is connected P3.0) is pressed.

In this, the counter is incremented from 0 to 99 at a high speed. If you press the button, then the LCD displays the current count value. As the count is incrementing at a high speed, the 8051 Microcontroller selects a random number when the button is pressed.

### Circuit Diagram Random Number Generator using 8051 Microcontroller ### Components Required

• AT89C51 (8051 Microcontroller)
• 8051 Programmer
• Programming cable
• 5V Power Supply
• 16×2 Alphanumeric LCD
• 2 Ceramic Capacitors – 33pF
• 11.0592 MHz Crystal
• Push Button – 3
• Electrolytic Capacitor – 10μF, 16V
• 10KΩ Resistor (1/4 watt) – 2
• 330Ω Resistor (1/4 watt) – 2
• POT – 10KΩ
• 1KΩ X 8 Resistor Pack
• Connecting Wires

### Circuit Design of Random Number Generator using 8051

The circuit is used 8051 microcontrollers, 16×2 alphanumeric LCD display, push buttons and a few passive components. The main component in this circuit is the AT89C51 Microcontroller.

In the above circuit, two push buttons are connected to P3.0 and P3.1, where one push button (Random – P3.0) will generate the random number while the other push button (RST – P3.1) will reset the count.

The LCD data pins are connected PORT2 of the microcontroller and control pins RS, RW, En are connected to P2.0, GND, and P2.1 respectively. Here, the LCD is connected in 8-bit mode and that is why we need to use all the data pins of LCD.

A 10KΩ Resistor, a 10μF capacitor, and a push button will provide the reset circuit to the 8051 microcontrollers. Two 33pF Capacitors along with an 11.0592 MHz Quarts Crystal are used to provide the oscillator to the 8051 microcontrollers.

Here, a 10KΩ potentiometer, which is connected to the VEE pin of LCD, is used to control the contrast of LCD. By adjusting the resistance of pot we can vary the contrast or brightness.

NOTE: If you want to reduce the data lines of LCD, you can use 4-bit mode.

### How to Write the Program?

Now let us see how to write the program for Random number generator using 8051 microcontrollers. Initially, take a count variable of type integer and initialize the LCD in 8-bit mode. Now take an infinite while loop to repeat the program forever. Within this infinite WHILE loop take, increment the value of the integer until the button is pressed (by using another while loop).

Increment the count up to 99 and when the count reaches 100 (the upper limit), make the count to 0 and repeat the process. If you want to extend the upper limit of random number generator, change the value in the loop. Once the button is pressed, the count stops and the current count value is displayed on the LCD.

In this program, if you want to extend the upper limit of random number generator you can make little changes in the program. As we are using LCD it is possible to extend the upper limit of random number generator, whereas it is not possible to extend the upper limit if you use 2 seven segment displays (you have to increase the number of 7-Segment displays as well).

### How to Operate Random Number Generator Circuit using 8051?

1. First, write the program for Random number generator in Keil μVision Software and generate the hex file.
2. Now burn this hex file to the AT89C51 microcontroller with the help of 8051 Programmer.
3. Make the connections as per the circuit diagram.
4. Make sure that the power supply to the circuit is 5V DC.
5. Now switch on the Power supply to the circuit.
6. You can observe the “Random Number Generator” string on the LCD.
7. Then, it will ask you to push the button to generate a random number.
8. Press the push button and you can see a random number on LCD. This will be displayed until you press the RST button (connected to P3.1).
9. Once you press the RST button, you will be again asked to press the button to generate a random number.
10. This process continues until you switch off the power supply.

### Random Number Generator using 8051 Circuit Applications

• This project is used in the applications where we need to generate Random number
• Used in noise generators
• The project is used as an alternative for the traditional dice while playing the games like monopoly, snake ladder.