"Hello World"
You must be aware of "Hello World" programs from computer science, where you write a piece of code which will display "Hello World". In electronics hardware board space, "Hello World" refers to blinking an LED by writing a simple program.
The resistor will block the flow of current in both directions. A diode is a two-terminal electronics component that has low resistance in one direction and high resistance in the other direction. Diodes are mostly made up of silicon. LEDs are the most commonly used diodes in any electronics circuit. LED stands for light emitting diode, so it emits light when sufficient voltage is provided across the LED anode and cathode.
The longer lead of the LED is the anode and the other end is the cathode. The color of the light depends on the semiconductor material used in the LED, as shown in the following diagram:
Connect the longer lead of the LED to pin 13 and shorter lead of the LED to GND (ground pin) and write the following code in a new editor window:
// the setup function runs once when you press reset or power the board void setup() { // initialize digital pin 13 as an output. pinMode(13, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second(1000 millisecond) digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second(1000 millisecond) }
You will notice from the preceding code that there are two important functions in each program. The first one is setup
, which runs only once when you power up the board or press the reset button. The second function is loop
, which runs over and over forever.
In the setup
function, you should write a code that needs to be executed once, like defining a variable, initializing a port as INPUT
or OUTPUT
. In the preceding code, digital pin 13 is defined as OUTPUT
. In the loop
function, the first line will put the HIGH
voltage on pin 13, which will turn on the LED connected to pin 13.
The "Hello World" program will turn the LED on for one second and turn off the LED for one second. The delay(1000)
function will induce a delay of one second and after that, digitalWrite(13, LOW)
will put the low voltage on pin 13, which will turn off the LED. Again, before you turn the LED on, you need to wait for one second by putting delay(1000)
at the end of the code.