090-Lab1Final
090-Lab1Final
IDE:
Arduino Hardware
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, 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:
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.
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
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
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);
}
}
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
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
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