{"id":145748,"date":"2024-08-07T18:03:03","date_gmt":"2024-08-07T12:33:03","guid":{"rendered":"https:\/\/www.electronicsforu.com\/?p=145748"},"modified":"2025-03-18T11:49:10","modified_gmt":"2025-03-18T06:19:10","slug":"blink-led-using-random-number-generator","status":"publish","type":"post","link":"https:\/\/www.electronicsforu.com\/electronics-projects\/blink-led-using-random-number-generator","title":{"rendered":"Blink LED Using Random Number Generator"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"alignright size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"152\" src=\"https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2016\/12\/Screen-Shot-2016-12-24-at-15.19.33-e1644389186872.png\" alt=\"\" class=\"wp-image-28226\"\/><figcaption class=\"wp-element-caption\">Comment errors or corrections found for this circuit, and get the chance to win big!<\/figcaption><\/figure><\/div>\n\n\n<p>A random number generation is very important in computing devices which helps them to do task in random manner. <\/p>\n\n\n\n<p>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. <\/p>\n\n\n\n<p>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). <\/p>\n\n\n\n<p>This process is essential for applications requiring unpredictability, such as games, simulations, and randomizing actions or intervals. Using analogue noise for seeding enhances the randomness and reliability of the generated numbers.<\/p>\n\n\n\n<p><strong>The applications of random number generators are:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Generating random events, positions, and outcomes to create unpredictability.<\/li>\n\n\n\n<li>Creating random passwords, encryption keys, and secure tokens for authentication.<\/li>\n\n\n\n<li>Generating random test cases and inputs to ensure robust software testing and identify edge cases.<\/li>\n\n\n\n<li>Creating random blink patterns for lights and introducing random delays in processes to avoid synchronization issues.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Bill of Materials (BoM)<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Components  <\/strong><\/td><td><strong>Description<\/strong><\/td><td><strong>Quantity<\/strong><\/td><\/tr><tr><td><a href=\"https:\/\/shop.electronicsforu.com\/product\/indusboard-iot-development-board\/\" target=\"_blank\" rel=\"noreferrer noopener\">IndusBoard<\/a><\/td><td>3cm sized dev board<\/td><td>1<\/td><\/tr><tr><td>LED<\/td><td>5mm LED<\/td><td>4<\/td><\/tr><tr><td>Resistor<\/td><td>1k ohm resistor<\/td><td>4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Coding<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/random numbers\n\/\/declare and initialize the led pin numbers\nint LED_1=2;\nint LED_2=3;\nint LED_3=4;\nint LED_4=5;\n\/\/ a variable to hold a number\nlong randomNumber;\nvoid setup() {\n\/\/ put your setup code here, to run once:\n\/\/start serial communication\nSerial.begin(9600);\n\/\/send at start messages to the serial monitor\nSerial.println(\"Start a new sequence of Random Number\");\n\/\/set the mode 0f the LED pins as output\npinMode(LED_1, OUTPUT);\npinMode(LED_2, OUTPUT);\npinMode(LED_3, OUTPUT);\npinMode(LED_4, OUTPUT);\n\/\/generate a random seed\nrandomSeed( analogRead(A0) );\n}\nvoid loop() {\n\/\/ asign a random number to our variable\nrandomNumber = random(2,6);\/\/always use +1 number\n\/\/print the output to the serial monitor window\nSerial.print(\"The Random Number is = \");\nSerial.println(randomNumber);\n\/\/turn on a \"Random LED\"\ndigitalWrite(randomNumber, HIGH);\ndelay(100);\ndigitalWrite(randomNumber, LOW);\ndelay(100);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Connection<\/strong><\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"868\" height=\"616\" src=\"https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/conn_1.jpg\" alt=\"Random LED Blink Circuit\" class=\"wp-image-145761\" style=\"width:560px;height:auto\" srcset=\"https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/conn_1.jpg 868w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/conn_1-500x355.jpg 500w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/conn_1-592x420.jpg 592w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/conn_1-696x494.jpg 696w\" sizes=\"auto, (max-width: 868px) 100vw, 868px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\"><strong>Testing<\/strong><\/h2>\n\n\n\n<p>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.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/bread-board-1024x1024.jpg\" alt=\"Random LED Blink Project\" class=\"wp-image-145763\" style=\"width:493px;height:auto\" srcset=\"https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/bread-board-1024x1024.jpg 1024w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/bread-board-500x500.jpg 500w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/bread-board-150x150.jpg 150w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/bread-board-420x420.jpg 420w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/bread-board-696x696.jpg 696w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/bread-board.jpg 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"1024\" src=\"https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/code-732x1024.jpg\" alt=\"Blink LED Using Random Number Generator\" class=\"wp-image-145760\" style=\"width:500px;height:auto\" srcset=\"https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/code-732x1024.jpg 732w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/code-357x500.jpg 357w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/code-300x420.jpg 300w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/code-696x974.jpg 696w, https:\/\/www.electronicsforu.com\/wp-contents\/uploads\/2024\/08\/code.jpg 772w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/figure><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><em>Author(s): Manjeet Vishwakarma, &nbsp;Abhay Verma and Satywanti Kundu are B.Tech ECE students at GJUS&amp;T HISAR<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":55758,"featured_media":145759,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,23,776,11851],"tags":[1985,1911,110],"class_list":{"0":"post-145748","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-electronics-projects","8":"category-hardware-diy","9":"category-prototypes","10":"category-super-innovative-projects","11":"tag-diy-projects","12":"tag-do-it-yourself","13":"tag-electronics-projects"},"_links":{"self":[{"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/posts\/145748","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/users\/55758"}],"replies":[{"embeddable":true,"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/comments?post=145748"}],"version-history":[{"count":2,"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/posts\/145748\/revisions"}],"predecessor-version":[{"id":159633,"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/posts\/145748\/revisions\/159633"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/media\/145759"}],"wp:attachment":[{"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/media?parent=145748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/categories?post=145748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.electronicsforu.com\/wp-json\/wp\/v2\/tags?post=145748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}