WorskShop Lab 5

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

Sukkur Institute of Business Administration University

Department of Computer Systems Engineering


ELE-111: Computer Engineering Workshop, fall 2021

Lab # 04:
Introduction to Arduino
Instructor: Engr. Irfan Ali

Submission Profile

Name: Manav Dev Submission Date: 06/10/2023

Enrolment ID: 133-23-0040 Receiving Authority Name and Signature:

Comments: ______________________________________________________________________

1
Objectives:

 To learn how use and program Arduino


 To learn how to interface LED and Potentiometer with Arduino
 To learn how to control devices using switch and Arduino
 To learn how to interface Light Dependent Resistor (LDR) with Arduino

INTRODUCTION TO ARDUINO – PROCESSING SYSTEM:

Arduino is an open-source prototyping platform based on easy-to-use hardware and software.


Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter
message - and turn it into an output - activating a motor, turning on an LED, publishing
something online. You can tell your board what to do by sending a set of instructions to the
microcontroller on the board. To do so you have to program Arduino using Arduino Software
(IDE).
Over the years Arduino has been the brain of thousands of projects, from everyday objects to
complex scientific instruments. A worldwide community of makers - students, hobbyists, artists,
programmers, and professionals - has gathered around this open-source platform, their
contributions have added up to an incredible amount of accessible knowledge that can be of great
help to novices and experts alike. Arduino was developed at the Ivrea Interaction Design
Institute as an easy tool for fast prototyping, aimed for students without a background in
electronics and programming. As soon as it reached a wider community, the Arduino board
started changing to adapt to new needs and challenges, differentiating its offer from simple 8-bit
boards to products for IoT applications, wearable, 3D printing, and embedded environments.

All Arduino boards are completely open-source, empowering users to build them independently
and eventually adapt them to their particular needs. The software, too, is open-source, and it is
growing through the contributions of users worldwide.

2
Figure 1: Arduino Hardware and Software

Why Arduino – Advantages Compared to Other Development Environments:

Thanks to its simple and accessible user experience, Arduino has been used in thousands of
different projects and applications. The Arduino software is easy-to-use for beginners, yet
flexible enough for advanced users. It runs on Mac, Windows, and Linux.
 Inexpensive - Arduino boards are relatively inexpensive compared to other development
platforms.
 Cross-platform - The Arduino Software (IDE) runs on Windows, Macintosh OSX, and
Linux operating systems. Most microcontroller systems are limited to Windows.
 User friendly programming environment - The Arduino Software (IDE) is easy-to-use
for beginners, yet flexible enough for advanced users to take advantage of as well. For
teachers, it's conveniently based on the Processing programming environment, so
students learning to program in that environment will be familiar with how the Arduino
IDE works.
 Open source and extensible software - The Arduino software is published as open
source tools, available for extension by experienced programmers. The language can be
expanded through C++ libraries, and people wanting to understand the technical details
can make the leap from Arduino to the AVR C programming language on which it's
based. Similarly, you can add AVR-C code directly into your Arduino programs if you
want to.
 Open source and extensible hardware - The plans of the Arduino boards are published
under a Creative Commons license, so experienced circuit designers can make their own
version of the module, extending it and improving it.
Arduino Boards – Arduino UNO:

3
There many different variants of Arduino Boards having different capabilities and are
designed for specific applications. We are going to discuss very commonly used board that is
Arduino UNO. Apart from minor variations all boards have similar architecture / Structure.

Figure 2: Arduino UNO

Reset Button: Pushing it will temporarily connect the reset pin to ground and restart any code
that is loaded on the Arduino.
Power LED Indicator: Just beneath and to the right of the word “UNO” on your circuit board,
there’s a tiny LED next to the word ‘ON’. This LED should light up whenever you plug your
Arduino into a power source. If this light doesn’t turn on, there’s a good chance something is
wrong. Time to re-check your circuit!
TX RX LEDs: TX is short for transmit; RX is short for receive. These markings appear quite a
bit in electronics to indicate the pins responsible for serial communication. In our case, there are
two places on the Arduino UNO where TX and RX appear – once by digital pins 0 and 1, and a
second time next to the TX and RX indicator LEDs. These LEDs will give us some nice visual
indications whenever our Arduino is receiving or transmitting data (like when we’re loading a
new program onto the board).

4
Voltage Regulator: It controls the amount of voltage that is let into the Arduino board. Think of
it as a kind of gatekeeper; it will turn away an extra voltage that might harm the circuit. Of
course, it has its limits, so don’t hook up your Arduino to anything greater than 20 volts.
Main IC – Microcontroller: The black thing with all the metal legs is an IC, or Integrated
Circuit. Think of it as the brains of our Arduino. The main IC on the Arduino is ATMEGA328P.
Different Arduino boards have different ICs but is usually from the ATMEGA line of IC’s from
the ATMEL Company. This can be important, as you may need to know the IC type (along with
your board type) before loading up a new program from the Arduino software.
Digital pins: Use these pins with digitalRead(), digitalWrite(), and analogWrite(). analogWrite()
works only on the pins with the PWM symbol.
Analog in: Use these pins with analogRead().
GND and 5V pins: Use these pins to provide +5V power and ground to your circuits.
Power connector: This is how you power your Arduino when it’s not plugged into a USB port
for power. Can accept voltages between 7-12V.
USB port: Used for powering your Arduino Uno, uploading your sketches to your Arduino, and
for communicating with your Arduino sketch (via Serial. println() etc.).

Table 1: Description of ATMEGA328P


PARAMETER VALUE
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limit) 6-20V
Digital I/O Pins 14 (of which 6 provide PWM output)
PWM Digital I/O Pins 6
Analog Input Pins 6
DC Current per I/O Pin 20 Ma
DC Current for 3.3V Pin 50 mA
32 KB (ATmega328P)
Flash Memory
of which 0.5 KB used by bootloader
SRAM 2 KB (ATmega328P)
EEPROM 1 KB (ATmega328P)
Clock Speed 16 MHz
Length 68.6 mm
Width 53.4 mm
Weight 25 g

5
Arduino Software (IDE):

The Arduino Integrated Development Environment - or Arduino Software (IDE) - contains a text
editor for writing code, a message area, a text console, a toolbar with buttons for common
functions and a series of menus. It connects to the Arduino and hardware to upload programs and
communicate with them.

Writing Sketches:

Programs written using Arduino Software (IDE) are called sketches. These sketches are written
in the text editor and are saved with the file extension. ino. The editor has features for
cutting/pasting and for searching/replacing text. The message area gives feedback while saving
and exporting and displays errors. The console displays text output by the Arduino Software
(IDE), including complete error messages and other information. The bottom right-hand corner
of the window displays the configured board and serial port. The toolbar buttons allow you to
verify and upload programs, create, open, and save sketches, and open the serial monitor.

Figure 3: Arduino Software (IDE)

6
Verify - Checks your code for errors compiling it.

Upload - Compiles your code and uploads it to the configured board. See uploading
below
for details.
Note: If you are using an external programmer with your board, you can hold down the
"shift" key on your computer when using this icon. The text will change to "Upload using
Programmer".

New - Creates a new sketch.

Open - Presents a menu of all the sketches in your sketchbook. Clicking one will open it
within the current window overwriting its content.

Save - Saves your sketch.

Serial Monitor - Opens the serial monitor.

Task No. 1: Interface LED with Arduino UNO

The first task is to understand the code and create a circuit needed to blink an LED. You will be
using digital input and output to write your first Arduino program.
To complete this task following components will be required:
 Arduino UNO
 LED
 Resistor
 Connecting wires & Breadboard

Below you can find the code for "Blink" of LED with comments. Comments are notes in your
code that explain what the code is doing without changing the program. The Arduino language
uses C/C++, so to make a one-line comment, type "//" before a line. If your comment is more
than one line, you can use "/* ... */", for example:

7
/* This is a comment! */
/* So
is this
*/

Code:
// the setup function runs once when you press reset or power the board
// Code for blinking the LED connected at pin 13
/*

The statements in the "setup()" function are executed once when the

program starts.

*/

void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
// The statements in "loop()" are executed sequentially forever.

void loop() {
digitalWrite(13, HIGH); // turn the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off
delay(1000); // wait for a second
}

Make the hardware connections as shown in figure 4.

Figure 4: Circuit Diagram

8
Figure 5: Hardware Results

Task No. 2: Controlling LED with pushbutton and Arduino

Pushbuttons or switches connect two points in a circuit when you press them. This example turns
on the LED connected on pin 8 when you press the button.
To complete this task following components will be required:
 Arduino UNO
 LED
 Resistor
 Switch/Button
 Connecting wires & Breadboard

9
Code:
const int buttonPin = 2; // the number of the pushbutton pin const int
ledPin = 8; // the number of the LED pin

// variables will change:


int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:


if (buttonState == HIGH)
{
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else
{
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

10
Make the hardware connections as shown in figure 6.

Figure 6: Circuit Diagram

Light Dependent Resistor (LDR):

Photoresistor (light-dependent resistor, LDR,) is a light-controlled variable resistor. The


resistance of a LDR changes with changing incident light intensity; in other words, it exhibits
photoconductivity. A LDR can be applied in light-sensitive detector circuits, and light-activated
and dark-activated switching circuits.

Figure 7: LDR and Its Symbol

In this task, we are going to use a Light Dependent Resistor (LDR) which turns on light
automatically when it gets dark and turns off when it gets light. An LDR's resistance changes
depending upon the amount of light hitting the sensor. Used in conjunction with a 4.7K resistor,

11
this forms a simple voltage divider where the voltage across the LDR changes depending upon
the light.
We can then input this into one of the Analog to Digital inputs in the Arduino Uno to measure
the voltage. Then it’s a simple matter of checking whether the value is above or below a
threshold value and to turn one of the outputs on or off.
The circuit diagram is shown below. As the light increases, the LDR's resistance drops and hence
the voltage across it drops. Thus, the voltage across the resistor increases, and the voltage into
the Arduino ADC increases. The opposite is true as it gets darker.

Figure 8: LDR Connections and Resistance Variation with Intensity

Task No. 3: Interfacing LDR with Arduino

To complete this task following components will be required:


 Arduino UNO
 LED
 Resistor
 LDR
 Connecting wires & Breadboard

Code:

int sensorPin = A2;


int ledPin = 11;
int sensorValue = 0; // variable to store the value coming from the sensor
12
Make the hardware connections as shown in figure 9.

Figure 9: Circuit Diagram

Lab Tasks

1. Design a circuit to create emergency Light - Police /Ambulance, Use 3 LEDs.


2. Design a circuit to control intensity of lights using potentiometer also display the
readings on serial monitor.
3. Design a circuit to control the blinking rate of lights with potentiometer.
4. Design a circuit to create Automatic Visitor Counter, it should count number of people
visiting in the room. Use LDR and seven segment display to detect and count up to 9
visitors.
5. Design circuit to control the lights (LEDs) by special combination of switches/ buttons.
The circuit must contain 3 inputs (Switches) and 3 outputs (LEDs).

Input (Switches Pressed) Output


Combination
101 Red LED Should Turn on

110 Green LED Should Turn on

111 Blue LED Should Turn on

13
Attachments:
 Tasks Code
 Results

14
15
16
17
18
19
20
21
22

You might also like