This particular project uses the Arduino pro-mini board which has a very small size and can be connected with bread board compatible connectors. The board comes with either ATMEGA128 or ATMEGA328 controller inside it which operates with a crystal frequency of 8MHz or 16MHz. The Arduino pro-mini board has digital pins marked as 2, 3, 4 up to 13. In an Arduino board some of the digital pins can be configured as analog output pins and there are also dedicated analog input pins which can be used for voltage sensing applications.
(check the images above)
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.
For basic understanding of Arduino, you can go to this project and check how to get started with the arduino and try out all the things discussed there.The Arduino pro-mini board has 8 analog input pins marked as A0, A1 up to A7. They are actually the input channels to the built-in ADC of the ATMEGA328 which can read the analog value and convert them to the digital equivalent. In normal analog voltage sensing applications the required analog input pin will be connected to a voltage which needs to be read. Suppose the situation in which the analog pin is left unconnected. The voltage at the pin is undefined and hence when read using the ADC the digital output will also be an undefined random value. This is the basic method by which a random number is obtained.
The first random number obtained from the hardware is called a ‘random seed’. This random seed is then applied to algorithms called random number generating algorithm which can generate a random number which inside a specified range. There are built-in functions in the Arduino IDE which helps in generating random numbers. This particular project makes use of two functions namely randomSeed() and random() and the details of the function are discussed below;
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.
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.
The code written for this project initializes pseudo-random number generator with a random value read from the analog input pin A0 and uses the function randomSeed(). The function used to read the value from A0 is analogRead() function which is already discussed 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 function random() is then used to generate a pseudo-random number and is send to the Serial monitor window with the help of the functions Serial.begin() and Serial.write() which are already discussed in previous projects on how to do serial communication with the Arduino, how to send and receive serial data using arduino, how to do serial debugging with the Arduino. The code also glows an LED using the same random number to vary its brightness by writing the same value to the analog output pin where the LED is connected.
When the coding is finished one can verify and upload the code to the Arduino board as explained in the project how to get started with the Arduino. The code will continuously generate random numbers and one can observe them with the help of Serial monitor as explained in the project on how to do serial debugging with the Arduino.