Search
Close this search box.

Home

Random Number Generator using 8051

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 microcontroller.

This project generates a random number in 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 button is pressed.

Related Post: 8 Channel Quiz Buzzer Circuit using 8051 Microcontroller

Circuit Diagram Random Number Generator using 8051 Microcontroller

Random Number Generator using 8051 Circuit Diagram

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 uses 8051 microcontroller, 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 pusg 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 microcontroller. Two 33pF Capacitors along with a 11.0592 MHz Quarts Crystal are used to provide the oscillator to the 8051 microcontroller.

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.

Random Number Generator using 8051 Image 1
Random Number Generator using 8051 Image 2
Random Number Generator using 8051 Image 3

How to Write the Program?

Now let us see how to write the program for Random number generator using 8051 microcontroller. 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 extend the upper limit of random number generator, change the value in 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 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). 

Also read the post – Electronic Dice using LEDs

CODE

Random Number Generator using 8051 – Circuit Simulation Video

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 “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
  • Project is used as an alternative for the traditional dice while playing the games like monopoly, snake ladder.

Random Number Generator using 8051 Project Output Video

 

24 Responses

    1. i would like to get the code of this random number generator why because i just developed it in AT89s51 using 7-segment display and i would like to get this code and develop a miniproject and finally add to my lab based project for microprocessors and microcontroller

  1. I need this project code because i don’t have much time to create the code for this project and yes i will make some changes in this project with the help of my teacher this project seems to be very interested and i think i will got good grade in my subject thanks

  2. a) I need this project code to look how the coding for random number generator is done.
    b) I’m working on vhdl, so as an assignment I’m asked to generate a random number generator using FPGA
    c) I would like to see the logic so that I will get an idea on how to proceed in vhdl.

  3. I am working on VHDL, so as an assignment I’m asked to generate random number using FPGA. I would like to see the coding in microprocessor so that I can get an idea on how to proceed in FPGA

  4. Kindly send me the code of this project please. I will be very thankful to you for your this act of kindness. Please Help!

  5. Its an interesting project. It helps to get an experience of doing practically with the micro controller 8051 which is there in the curriculum in 4th semester in ECE stream.

  6. i am doing this project for my 3rd year engineering
    and i will be doing it as ‘random nuber generation without repetiton of numbers’
    so it is not same and i will be doing changes..
    but i wil be thankful if you can send me basic code of your this project….so that it can help me to do modifications and do my own ..thank you

    1. this code of random number generator isn,t working …. the lcd is on but nothing is displayed….
      the circuit in the diagram and the other one in the stimulation are not the same….
      my project deadline is nearby please help me

  7. we are working on a small mini project in which we require to generate random numbers between 0-9 and display it on a seven segment display,,,,so please send me the respective code to the below mail;

    eninthala5@gmail.com

  8. Why you need this project code?
    Are you trying to make the same project or different one?
    Give us more details about your project.

    I need code for this project as I am doing this project for my college, I tried to write code but its not working. If you can help me out then I will be thankful.

    I am trying to make same project

    I tried with LCD and 7 segment display. This is my mini project which i have to submit in my college before 4th april 2016 and today is 26th march 2016. So I need the code as soon as possible so that i can work on it further.

    Kindly, provide me the code Sir.

  9. My teacher has suggest me this project to make it in a limited time. And this is the best one i think. Sir i will bring some changes in this project.plz send me the code of the project.

  10. a) I need this project code to look how the coding for random number generator is done.
    b) I’m working on vhdl, so as an assignment I’m asked to generate a random number generator using FPGA
    c) I would like to see the logic so that I will get an idea on how to proceed in vhdl.

  11. I am getting error in the code
    error C267: ‘str_lcd’ requires ANSI_style prototype
    can u tell me how to fix it??

  12. can you explain the code in detail or if possible please share the code with the comments i have faced some problem in understanding the code help me please!!!!!!!!!!!!!!!

Leave a Reply

Your email address will not be published. Required fields are marked *