Wednesday, November 13, 2024

More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Search in posts
Search in pages

Blink LED Using Random Number Generator

Comment errors or corrections found for this circuit, and get the chance to win big!

A random number generation is very important in computing devices which helps them to do task in random manner. In the Arduino IDE with the IndusBoard, generating random numbers involves seeding the random number generator with the `randomSeed()` function to ensure randomness across resets, typically using an unconnected analog pin to read random noise. The `random()` function is then used to generate random numbers, either within a specified range (`random(max)` for 0 to max-1 or `random(min, max)` for min to max-1). This process is essential for applications requiring unpredictability, such as games, simulations, and randomizing actions or intervals. Using analog noise for seeding enhances the randomness and reliability of the generated numbers.

The applications of random number generator is:

  • Generating random events, positions, and outcomes to create unpredictability.
  • Creating random passwords, encryption keys, and secure tokens for authentication.
  • Generating random test cases and inputs to ensure robust software testing and identify edge cases.
  • Creating random blink patterns for lights and introducing random delays in processes to avoid synchronization issues.

Bill of Materials (BoM)

Components DescriptionQuantity
IndusBoard3cm sized dev board1
LED5mm LED4
Resistor1k ohm resistor4

Coding

//random numbers
//declare and initialize the led pin numbers
int LED_1=2;
int LED_2=3;
int LED_3=4;
int LED_4=5;
// a variable to hold a number
long randomNumber;
void setup() {
// put your setup code here, to run once:
//start serial communication
Serial.begin(9600);
//send at start messages to the serial monitor
Serial.println("Start a new sequence of Random Number");
//set the mode 0f the LED pins as output
pinMode(LED_1, OUTPUT);
pinMode(LED_2, OUTPUT);
pinMode(LED_3, OUTPUT);
pinMode(LED_4, OUTPUT);
//generate a random seed
randomSeed( analogRead(A0) );
}
void loop() {
// asign a random number to our variable
randomNumber = random(2,6);//always use +1 number
//print the output to the serial monitor window
Serial.print("The Random Number is = ");
Serial.println(randomNumber);
//turn on a "Random LED"
digitalWrite(randomNumber, HIGH);
delay(100);
digitalWrite(randomNumber, LOW);
delay(100);
}

Connection

Testing

Now we connect the board with the USB and upload the code in the indusBoard and check output on serial monitor. When the random numbers are generated then led start blinking according to the numbers generated.

- Advertisement -

Author(s): Manjeet Vishwakarma,  Abhay Verma and Satywanti Kundu are B.Tech ECE students at GJUS&T HISAR

SHARE YOUR THOUGHTS & COMMENTS

EFY Prime

Unique DIY Projects

Electronics News

Truly Innovative Electronics

Latest DIY Videos

Electronics Components

Electronics Jobs

Calculators For Electronics