You are on page 1of 3

Laboratory Activity No.

1
Basic Code
Activity Objective:
In this activity the student should be able to learn the bare minimum of code needed for
an Arduino sketch to compile: the setup() method, loop() method and pinMode(pin, mode)
function.
Topics:

setup() method
loop() method
pinMode(pin, mode) function

Hardware Required

Gizduino Board / Arduino Board

Schematic

None

setup()
The setup() function is called when your program starts. Use it to initialize your
variables, pin modes, start using libraries, etc. The setup function will only run once, after each
power up or reset of the Arduino/Gizduino board.
loop()
After creating a setup() function, which initializes and sets the initial values, the loop()
function does precisely what its name suggests, and loops consecutively, allowing your program
to change and respond. Use it to actively control the Arduino/Gizduino board.
setup() is preparation, and loop() is execution. In the setup section, always at the top of
your program, you would set pinModes, initialize serial communication, etc. The loop section is
the code to be executed reading inputs, triggering outputs, etc.

Example:
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
Note:
The analog input pins can be used as digital pins, referred to as numbers 14 (analog input 0) to
19 (analog input 5).
Activity:

Compile and load the example code on the Arduino/Gizduino board. You should see a
blinking LED if the loading is successful.

Remarks

You might also like