1 Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Basic programming to interface LEDs and switches
sensor interfacing (01CT1103)
Date: 31 Aug
Experiment No: 01 Enrollment No: 132261
2024
Name: Prem Joshi, MU SEM1, Roll No. 090
The Document Contains:
Lab 1 Class Explanation
Lab 1 Completed Class work (Circuit + Code)
Lab 1 Completed Post-Lab exercise (Circuit + Code)
2 Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Basic programming to interface LEDs and switches
sensor interfacing (01CT1103)
Date: 31 Aug
Experiment No: 01 Enrollment No: 132261
2024
Aim: Basic programming to interface LEDs and switches
IDE:
Arduino Hardware
Understanding Arduino Essentials
Let's first grasp the foundational concepts of Arduino. At its core, Arduino is a microcontroller-based platform
designed to facilitate the development of electronic projects. Like the popular Arduino Uno boasting an
atmega328p microchip, a microcontroller is a compact computing device specifically engineered to perform
dedicated tasks.
1. Microcontroller - this is the brain of an Arduino, and is the component that we load programs into.
Think of it as a tiny computer, designed to execute only a specific number of things.
2. USB port - used to connect your Arduino board to a computer.
3. USB to Serial chip - the USB to Serial is an important component, as it helps translating data that
comes from e.g. a computer to the on-board microcontroller. This is what makes it possible to program
the Arduino board fr
3 Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Basic programming to interface LEDs and switches
sensor interfacing (01CT1103)
Date: 31 Aug
Experiment No: 01 Enrollment No: 132261
2024
om your computer.
4. Digital pins - pins that use digital logic (0,1 or LOW/HIGH). Commonly used for switches and to turn
on/off an LED.
5. Analog pins - pins that can read analog values in a 10 bit resolution (0-1023).
6. 5V / 3.3V pins- these pins are used to power external components.
7. GND - also known as ground, negative or simply -, is used to complete a circuit, where the electrical
level is at 0 volt.
8. VIN - stands for Voltage In, where you can connect external power supplies.
The Arduino IDE
The Arduino IDE, or Integrated Development Environment, is your primary workspace for crafting Arduino code.
This environment offers a user-friendly interface that streamlines the process of writing, verifying, and uploading
code to your Arduino board. Let's dissect the core components of the Arduino IDE:
Key Components of the Arduino IDE
1. Sketch: Tshe Sketch component holds your code. It is the blank canvas upon which you paint your
programming masterpiece. Here, you write, edit, and save your code.
2. Serial Monitor: The Serial Monitor is your communication lifeline to the Arduino board. This tool
facilitates real-time communication, assisting you in debugging and monitoring data. When your code is
running on the Arduino board, the Serial Monitor offers insight into its operation, aiding you in identifying
and rectifying any issues that may arise.
3. Tools: Under the Tools menu, you will discover a treasure trove of options to fine-tune your Arduino
environment. This is where you configure critical aspects of your Arduino setup. When tailoring your
development environment, be aware of the following tools at your disposal:
Board Type: Arduino offers an array of boards, each with its unique capabilities. Whether you're working
with the classic Arduino Uno or a more advanced board like the Arduino Mega, selecting the appropriate
board type ensures compatibility and unlocks advanced features.
Port Configuration: Port selection is a crucial step in ensuring your code reaches the correct destination.
It's where your Arduino IDE communicates with the physical Arduino board. Pay attention to port
selection, especially if you have multiple devices connected.
Programmer Settings: For advanced users, the Programmer Settings enable you to work with different
programming methods and tools, adding flexibility to your coding endeavors.
Serial Plotter: Visualize Your Data This tool is a visual delight for anyone working with sensors and
data visualization. The Serial Plotter provides real-time graphing capabilities, making it simple to observe
4 Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Basic programming to interface LEDs and switches
sensor interfacing (01CT1103)
Date: 31 Aug
Experiment No: 01 Enrollment No: 132261
2024
changing values. It's perfect for tracking sensor data or any dynamic information that needs to be visually
represented. Whether you're monitoring distance measurements, temperature changes, or any other data,
the Serial Plotter transforms raw numbers into meaningful visual insights.
First Arduino Code and Project
Blinking LED
The quintessential "Blink" project is Arduino's equivalent to "Hello, World!" in the programming universe. It's a
basic exercise involving the toggling of an LED. In this project, an LED connected to digital pin 13 blinks on and
off at one-second intervals.
Components Required
Arduino board (e.g., Arduino Uno)
LED (any color)
220-ohm resistor
Breadboard
Jumper wires
Connect the components as follows:
1. Arduino Board: Connect your Arduino board to your computer using a USB cable. This provides power
to the board and allows for code upload.
2. LED (Light-Emitting Diode): Take an LED of any color and note that it has two legs, a longer one and
a shorter one. The longer leg is the anode (positive), and the shorter leg is the cathode (negative).
3. 220-ohm Resistor: Place the 220-ohm resistor (red-red-brown) between the cathode (shorter leg) of the
LED and the ground (GND) on the Arduino board. One end of the resistor connects to the cathode, and
the other connects to the Arduino board's GND.
4. Breadboard: Place the LED's cathode connected to the resistor into the breadboard. This step is crucial
for stability.
5. Jumper Wires: Use jumper wires to connect the anode (longer leg) of the LED to digital pin 13 on the
Arduino board. This allows you to control the LED using your Arduino code.
With your components interconnected, apply and upload the code written above to set the LED blinking!
5 Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Basic programming to interface LEDs and switches
sensor interfacing (01CT1103)
Date: 31 Aug
Experiment No: 01 Enrollment No: 132261
2024
A simple example of a circuit, is an LED circuit. A wire is connected from a pin on the Arduino, to an LED via a
resistor (to protect the LED from high current), and finally to the ground pin (GND). When the pin is set to a
HIGH state, the microcontroller on the Arduino board will allow an electric current to flow through the circuit,
which turns on the LED. When the pin is set to a LOW state, the LED will turn off, as an electric current is not
flowing through the circuit.
Arduino Code
6 Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Basic programming to interface LEDs and switches
sensor interfacing (01CT1103)
Date: 31 Aug
Experiment No: 01 Enrollment No: 132261
2024
int switchPin = 12;
int ledPin = 13;
int switchState = LOW;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT);
}
void loop() {
switchState = digitalRead(switchPin);
Serial.println(switchState);
if (switchState == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
Post Lab Exercise:
1. Adding more LEDs and generate pattern.
Reference Material:
https://www.oreilly.com/library/view/arduino-a-
technical/9781491934319/ch01.htmlhttps://www.instructables.com/Blink-an-LED-With-Digital-Output/
7 Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Basic programming to interface LEDs and switches
sensor interfacing (01CT1103)
Date: 31 Aug
Experiment No: 01 Enrollment No: 132261
2024
Lab 1 – Completed Class work
Fig 1: Class Work Circuit Diagram
// Lab 1 Class Work Code - FSSI - MU-ICT-SEM1-EK1A-090
int switchPin = 12;
int ledPin = 13;
int switchState = LOW;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT);
}
void loop()
{
switchState = digitalRead(switchPin);
Serial.println(switchState);
if (switchState == HIGH)
{
digitalWrite(ledPin, HIGH);
8 Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Basic programming to interface LEDs and switches
sensor interfacing (01CT1103)
Date: 31 Aug
Experiment No: 01 Enrollment No: 132261
2024
}
else
{
digitalWrite(ledPin, LOW);
}
}
9 Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Basic programming to interface LEDs and switches
sensor interfacing (01CT1103)
Date: 31 Aug
Experiment No: 01 Enrollment No: 132261
2024
Lab 1 – Completed Post Lab Exercise
Fig 2: Post Lab Exercise Circuit Diagram
//Post Lab Exercise 1 Code MU-ICT-SEM1-EK1-090
int switchPin = 10;
int LedPin1 = 13;
int LedPin2 = 12;
int LedPin3 = 11;
int switchState = LOW;
/*Declaring all variables. A total of 5 variables, 3 LEDs
and their connections to the digital pins on Arduino, followed
by 1 for the digital pin connection to the push switch and the
last variable for the initial state of the switch (which is supposed to be off, hence
'LOW')
*/
void setup()
{
Serial.begin(9600);
pinMode(LedPin1, OUTPUT);
pinMode(LedPin2, OUTPUT);
pinMode(LedPin3, OUTPUT);
pinMode(switchPin, INPUT);
}
/*Setting up the functions of each component with respect to the arduino board,
whether the component is supposed to act as an input to the board or
10 Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Basic programming to interface LEDs and switches
sensor interfacing (01CT1103)
Date: 31 Aug
Experiment No: 01 Enrollment No: 132261
2024
display an output from the board. The switch will act as an input, hence 'INPUT' in
the pin mode,
while the LEDs will turn on or off depending on the input from the switch, hence
'OUTPUT' in the pin mode.
*/
void loop()
{
switchState = digitalRead(switchPin);
//setting the switchstate variable to a value based on the input from the switchpin
variable (Whether On/High or Off/Low).
Serial.println(switchState);
//sends the value of the switch state (0/Off or 1/On) to the processor)
if (switchState == HIGH)
{
digitalWrite(LedPin1, HIGH);
delay (1000);
digitalWrite(LedPin1, LOW);
delay (1000);
digitalWrite(LedPin2, HIGH);
delay (1000);
digitalWrite(LedPin2, LOW);
delay (1000);
digitalWrite(LedPin3, HIGH);
delay (1000);
digitalWrite(LedPin3, LOW);
}
else
{
digitalWrite(LedPin1, LOW);
digitalWrite(LedPin2, LOW);
digitalWrite(LedPin3, LOW);
}
}
/*The above is an if statement. Depending on the state of the switch the LEDs remain
off
if the switch is not pushed/off OR the LEDs turn on and off for 1 second in sequence
(Red<Yellow<Green) with
a 1 second delay between each of them if the switch is pushed/turned on.*/
11 Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Basic programming to interface LEDs and switches
sensor interfacing (01CT1103)
Date: 31 Aug
Experiment No: 01 Enrollment No: 132261
2024