Professional Documents
Culture Documents
Experiment: 1.1
SEMESTER –02
Step 1: #define LED 2
As a best practice, we use some defines to keep the pin number for the LED- The
Pin the LED is connected to. Also, in the future if we want to change the LED from
pin 2 to another pin, we can modify this line without touching anything else in the
code.
University Institute of Engineering
Department of Computer Science & Engineering
Step 2: void setup()
Every Arduino sketch includes void setup() and void loop(). Without them, your
program won’t run!
The code that you put inside void setup() will only run once, and that will be
at the beginning of your program. One example is when you want to turn
your robot on — that does not happen multiple times!
As the void setup function is called only once at the very beginning of the program,
this will be the place to:
· Etc.
The void setup, as its name suggest, is made for you to do any setup required at
the beginning of the program.
Step 3: pinMode(LED, OUTPUT);
Syntax
pinMode(pin, mode)
Step 4: void loop()
In void loop(), your code will repeat over and over again.
The loop() function will run over-and-over-and-over until the Arduino is reset.
Step 5:
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.println("HIGH");
delay(500); // wait for half a second
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
Serial.println("LOW");
delay(500);
Syntax
digitalWrite(pin, value)
4. CIRCUIT DIAGRAM:
University Institute of Engineering
Department of Computer Science & Engineering
5. CODE:
University Institute of Engineering
Department of Computer Science & Engineering