You are on page 1of 92

Lab Manual

Arduino laboratory for B.Tech -2nd year

Prepared By

Department of Embedded Systems

1
List of Experiments:
1. Arduino board configuration, pin description and overview on Arduino IDE.
2. LED based projects :
I. Digital input : blinking of an led
II. Magic bulb : Creating a Function to Set the Number of Blinks
3. Printing numbers on 7-segment display
4. Controlling of LED’s by using switches.
5. PWM digital output :Controlling of brightness (fading) of an LED
6. Serial monitor :Printing output:
I. An example to print output on serial monitor
II. Controlling of RGB led by taking input from serial monitor
7. LCD based projects: Printing output:
I. Print input text in scrolling from right to left
II. Print input text in scrolling from left to right
8. Led matrix interfacing with the Arduino and printing different types of shapes on 8x8 led
matrix.
9. Arduino board interfacing with the LDR sensor print output on Serial monitor.
10. Arduino board interfacing with the temperature sensor print output on Serial monitor.
11. Arduino board interfacing with the Humidity sensor print output on
Serial monitor.
12. Arduino board interfacing with the Touch sensor print output on Serial monitor.
13. Arduino board interfacing with the Buzzer sensor print output on Serial monitor.
14. Arduino board interfacing with the Ultrasonic sound sensor print output on Serial monitor.
15. Arduino board interfacing with the Color sensor print output on Serial monitor.
16. Arduino interfacing with motors
I. DC bipolar motor
II. Stepper motor
III. Servo motor

2
Evolution of Arduino Boards

ARDUINO UNO

This is the latest revision of the basic Arduino USB board. It connects to the computer with a
standard USB cable and contains everything else you need to program and use the board. It can
be extended with a variety of shields: custom daughter-boards with specific features. It is similar
to the Duemilanove, but has a different USB-to-serial chip the ATMega8U2, and newly designed
labeling to make inputs and outputs easier to identify.

3
ARDUINO DUEMILANOVE

The Duemilanove automatically selects the appropriate power supply (USB or external power),
eliminating the need for the power selection jumper found on previous boards. It also adds an
easiest to cut trace for disabling the auto-reset, along with a solder jumper for re-enabling it.
Note: around March 1st, 2009, the Duemilanove started to ship with the ATmega328p instead of
the ATmega168. More

ARDUINO DIECIMILA

4
The main change in the Arduino Diecimila is that it can be reset from the computer, without the
need to physically press the reset button on the board. The Diecimila uses a low dropout voltage
regulator which lowers the board's power consumption when powered by an external supply
(AC/DC adapter or battery). A resettable polyfuse protects your computer's USB ports from
shorts and surges. It also provides pin headers for the reset line and for 3.3V. There is a built-in
LED on pin 13. Some blue Diecimila boards say "Prototype - Limited Edition" but are in fact
fully-tested production boards (the actual prototypes are red). More

ARDUINO NG REV. C

Revision C of the Arduino NG does not have a built-in LED on pin 13 - instead you'll see two
small unused solder pads near the labels "GND" and "13". There is, however, about 1000 ohms
of resistance on pin 13, so you can connect an LED without external resistor. Schematic

5
ARDUINO NG 240

The Arduino NG uses the FTDI FT232RL USB-to-Serial converter, which requires fewer
external components that the FT232BM. It also has a built-in LED on pin 13 (which may
interfere with SPI communication). Later NG's shipped with an ATmega168 instead of an
ATmega8, though either chip can be used with any board. Schematic

ARDUINO EXTREME v2

6
Version 2 of the Arduino Extreme uses a gridded ground plane and includes the new
"www.arduino.cc" URL.

ARDUINO EXTREME

The Arduino Extreme uses many more surface mount components than previous USB Arduino
boards and comes with female pin headers. It also has RX and TX LEDs that indicate when data
is being sent to or from the board.

ARDUINO USB v2.0

7
The second version of the Arduino USB corrected the USB connector pinout and updated the
URL to "arduino.berlios.de"; it was labelled "Arduino USB v2.0". (Eagle files, schematic,
assembly instructions, photo of an assembled board). Assembly instructions

ARDUINO USB

The Arduino USB was the first board labelled "Arduino". These were mainly sold unassembled
as kits. The first version had an incorrect pinout for the USB connector and had the URL
"www.potemkin.org".
Arduino Bluetooth

8
ARDUINO BT

The Arduino BT is a microcontroller board originally was based on the ATmega168, but now is
supplied with the 328, and the Bluegiga WT11 bluetooth module. It supports wireless serial
communication over bluetooth (but is not compatible with Bluetooth headsets or other audio
devices).
Arduino Serial

ARDUINO SERIAL v2.0

9
A revised version of the serial board with the URL "arduino.berlios.de".

ARDUINO SERIAL

The original version of the Arduino serial board. Includes the url "www.potemkin.org". More
Arduino Single-Sided Serial

SEVERINO (S3V3)

10
This is the third version of the single-sided board. It has fewer bridges (three) than the original
and includes TX, RX, and pin 13 LEDs. The ICSP and power headers are compatible with the
Diecimila.More

ORIGINAL

The initial design of the single-sided board (labeled version 2 because it was derived from v. 2 of
the serial board). Requires six bridges. Has a 1K resistor (but no LED) on pin 13. The ICSP
header location is not compatible with other boards.
Arduino Mega

11
ARDUINO MEGA

The original Arduino Mega has an ATmega1280 and an FTDI USB-to-serial chip. More
Arduino Lilypad

ARDUINO LILYPAD 03/04

LilyPad Arduino 04

12
This revision uses the ATmega328V instead of the ATmega168V. All other detials are identical
to version 03.
LilyPad Arduino 03
This revision has a 6-pin programming header that's compatible with FTDI USB cables and the
Sparkfun FTDI Basic Breakout. It adds support for automatic reset, allowing sketches to be
uploaded without pressing the reset button on the board. The header is surface mounted, meaning
that the board has no pokey bits sticking out the back.

ARDUINO LILLYPAD 02

The second revision includes an external 8mhz oscillator. The bootloader has also been updated
to Limor Fried's "no wait" bootloader. When the LilyPad is supplied with power, the sketch
starts immediately. The bootloader is triggered only when the reset switch is pressed. Schematic

13
ARDUINO LILYPAD 01

In the first revision of the LilyPad Arduino the 10-pin ICSP header was changed to a 6-pin ICSP
header and a four pin header w/ RX, TX, +5V, and GND was added.

ARDUINO LILLYPAD 00

14
The initial design of the Arduino Lily Pad had a 10-pin ICSP header and used the internal clock
on the ATmega168 rather than an external oscillator. The bootloader on the initial design is the
traditional NG bootloader.
Arduino NANO

ARDUINO NANO 3.0

The Arduino Nano 3.0 has an ATmega328 and a two-layer PCB. The power LED moved to the
top of the board.

ARDUINO NANO 2.X

The Arduino Nano 2.x boards have an ATmega168 and a four-layer PCB.
Arduino Mini

15
ARDUINO MINI 04

On this version of the Arduino Mini, two of the pins changed. The third pin became reset
(instead of ground) and fourth pin became ground (instead of being unconnected). These boards
are labelled "Mini 04".

ARDUINO MINI 03

16
On this board, a solder point for digital pin 7 was added to the edge of the board (next to the
solder points for TX, RX, +5V, and Ground). Each of the pins is numbered and the board is
labelled "Mini 03".

ARDUINO STAMP 02

The initial production version of the Arduino Mini was labelled "Stamp 02".
Mini Usb Adapter

MINI USB ADAPTER 03

17
This version of the Mini USB Adapter breaks out many more pins of the FTDI USB-to-serial
chip. It is labeled "USB Mini 03".

MINI USB ADAPTER

The original Mini USB Adapter was labelled "Arduino Stamp 02".

Required software
You should be able to program your Arduino with just about any computer using a piece
of software called an integrated development environment (IDE). To run this software,
your computer should have one of the following operating systems installed:
 Mac OS X or higher
 Windows XP 32- or 64-bit, or higher
 Linux 32- or 64-bit (Ubuntu or similar)

Now is a good time to download and install the IDE, so jump to the heading that
matches your operating system and follow the instructions. Make sure you have or buy
the matching USB cable for your Arduino from the supplier as well. Even if you don’t
have your Arduino board yet, you can still download and explore the IDE. Because the
IDE version number can change quite rapidly, the number in this book may not match
the current version, but the instructions should still work.

18
Mac OS X
In this section, you’ll find instructions for downloading and configuring the Arduino
IDE in Mac OS X.

Installing the IDE


To install the IDE on your Mac, follow these instructions:

1. Using a web browser such as Safari, visit the software download page located at
http://arduino.cc/en/Main/Software/, as shown in Figure 1-7.

Figure 1-7: The IDE download page in Safari


1. Click the Mac OS X link. The file will start downloading, and it will appear in
the Downloads window shown in Figure 1-8.

Figure 1-8: File download is complete.


2. Once it’s finished downloading, double-click the file to start the instal- lation
process. You will then be presented with the window shown in Figure 1-9.

19
Figure 1-9: Your new Arduino IDE folder

Note: The third file icon shown in Figure 1-9 needs to be installed only if you have
an Arduino board older than the current Uno.
3. Drag the Arduino icon over the Applications folder and release the mouse
button. A temporary status window will appear as the file is copied.
4. Now connect your Arduino to your Mac with the USB cable. After a moment,
the dialog shown in Figure 1-10 will appear.

Figure 1-10: A new Arduino board is detected. Your


dialog may read Uno instead of Eleven.
1. Click Network Preferences..., and then click Apply in the Network box.
You can ignore the “not configured” status message.

20
Setting up the IDE
Once you have downloaded the IDE, use the following instructions to open
and configure the IDE:

1. Open the Applications folder in Finder (shown in Figure 1-11) and double-
click the Arduino icon.

Figure 1-11: Your Applications folder


2. A window may appear warning you about opening a web app. If it does, click
Open to continue. You will then be presented with the IDE, as shown in Figure 1-
12.

Figure 1-12: The IDE in Mac OS X

3. You’re almost there—just two more things to do before your Arduino IDE is
ready to use. First, you need to tell the IDE which type of socket the Arduino is

21
connected to. Select Tools Serial Port and select the

/dev./tty.usbmodem1d11 option, as shown in Figure 1-13.

Figure 1-13: Selecting the USB port


The final step is to tell the IDE which Arduino board you have connected. This is
crucial, since Arduino boards do differ. For example, if you have the most
common board, the Uno, then select Tools Board Arduino Uno, as shown in

Figure 1-14.

Figure 1-14: Selecting the correct Arduino board

Windows XP and Later


In this section, you’ll find instructions for downloading the IDE, installing drivers, and
configuring the IDE in Windows.

22
Installing the IDE
To install the Arduino IDE for Windows, follow these instructions:
1. Using a web browser such as Firefox, visit the software download page located at
http://arduino.cc/en/Main/Software/, as shown in Figure 1-15.

Figure 1-15: The IDE download page in Windows


2. Click the Windows link, and the dialog shown in Figure 1-16 will appear. Select
Open with Windows Explorer, and then click OK. The file will start to
download, as shown in Figure 1-17.

3. Once the download is complete, double-click the file, and the window shown in
Figure 1-18 will appear.

23
Setting Up the IDE
Okay-just two more things to do to finish setting up the IDE.
1. Open the Arduino IDE. You need to tell the IDE which type of socket the
Arduino is connected to by selecting Tools Serial Port and selecting the
COM port number that appeared in the Update Driver Software window.
2. The final step is to tell the IDE which Arduino board we have connected Ubuntu Linux
9.04 and Later

 If you are running Ubuntu Linux, here are instructions for downloading and
setting up the Arduino IDE.

Installing the IDE


Use the following instructions to install the IDE.
1. Using a web browser such as Firefox, visit the software download page located at
http://arduino.cc/en/Main/Software/, as shown in Figure 1-23.

24
Figure 1-23: The IDE download page in Ubuntu Firefox
2. Click the Linux 32-bit or 64-bit link, depending on your system. When the dialog in
Figure 1-24 appears, select Open with Archive Manager and click OK.

Figure 1-24: Downloading the file

3. After the file has downloaded, it will be displayed in the Archive Manager,
as shown in Figure 1-25. Copy the arduino-0022 folder (or something
similar) to your usual application or Home folder.

25
Figure 1-25: The IDE package

Setting Up the IDE


Next, you’ll configure the IDE.

1. Connect your Arduino to your PC with the USB cable. At this


point you want to run the Arduino IDE, so locate the arduino-
0022 folder you copied earlier and double-click the Arduino file
that’s selected in Figure 1-26.

Figure 1-26: Your Arduino IDE folder with the arduino file selected

2. If the dialog shown in Figure 1-27 appears, click Run, and you will be presented
with the IDE, as shown in Figure 1 -28.

26
Figure 1-27: Granting permission to run the IDE

Figure 1-28: The IDE in Ubuntu

3. Now that the IDE is running, we need to tell it which type of socket the Arduino
is connected to. Select Tools Serial Port and select the /dev./ ttyACMx port,
where x is a single digit (there should be only one port with a name like this).
4. Next, tell the IDE which Arduino you have connected. This is crucial, as
Arduino boards do differ. For example, if you have the Uno, select
Tools Board Arduino Uno.

27
1. Arduino board configuration, pin description and
overview on Arduino IDE.

The Arduino Board:


Arduino is an open-source electronics prototyping platform based on flexible, easy-to-
use hardware and software. It’s intended for artists, designers, hobbyists, and anyone
interested in creating inter- active objects or environments.
In simple terms, the Arduino is a tiny computer system that can be programmed with
your instructions to interact with various forms of input and output. The current Arduino
board model, the Uno, is quite small in size compared to the average human hand, as
you can see in Figure 1-1.

Figure 1-1: An Arduino Uno is quite small.


Although it might not look like much to the new observer, the Arduino system allows
you to create devices that can interact with the world around you. By using an almost
unlimited range of input and output devices, sensors, indicators, displays, motors, and
more, you can program the exact interactions required to create a functional device.
For example, artists have created installations with patterns of blinking lights that
respond to the movements of passers-by, high school students have built autonomous

28
robots that can detect an open flame and extinguish it, and geographers have designed
systems that monitor temperature and humidity and transmit this data back to their
offices via text message. In fact, you’ll find an almost infinite number of examples
with a quick search on the Internet.

Now let’s move on and explore our Arduino Uno hardware (in other words, the
“physical part”) in more detail and see what we have. Don’t worry too much about
understanding what you see here, because all these things will be discussed in greater
detail in later chapters.

Let’s take a quick tour of the Uno. Starting at the left side of the board, you’ll see two
connectors, as shown in Figure 1-2.

Figure 1-2: The USB and power connectors

On the far left is the Universal Serial Bus (USB) connector. This connects the board
to your computer for three reasons: to supply power to the board, to upload your
instructions to the Arduino, and to send data to and receive it from a computer. On the
right is the power connector. Through this connector, you can power the Arduino with
a standard mains power adapter.

At the lower middle is the heart of the board: the microcontroller, as shown in Figure
1-3.

29
Figure 1-3: The microcontroller

The microcontroller is the “brains” of the Arduino. It is a tiny computer that contains a
processor to execute instructions, includes various types of memory to hold data and
instructions from our sketches, and provides various avenues of sending and receiving
data. Just below the microcontroller are two rows of small sockets, as shown in Figure
1-4.

Figure 1-4: The power and analog sockets

The first row offers power connections and the ability to use an external RESET
button. The second row offers six analog inputs that are used to measure electrical
signals that vary in voltage. Furthermore, pins A4 and A5 can also be used for
sending data to and receiving it from other devices. Along the top of the board are two
more rows of sockets, as shown in Figure 1-5.

Figure 1-5: The digital input/output pins


Sockets (or pins) numbered 0 to 13 are digital input/output (I/O) pins. They can
either detect whether or not an electrical signal is present or generate a signal on
command. Pins 0 and 1 are also known as the serial port, which is used to send and
receive data to other devices, such as a com- putter via the USB connector circuitry.
The pins labeled with a tilde (~) can
Also generate a varying electrical signal, which can be useful for such things as creating
lighting effects or controlling electric motors.

Next are some very useful devices called light-emitting diodes (LEDs); these very tiny devices

30
light up when a current passes through them. The Arduino board has four LEDs: one on
the far right labeled ON, which indicates when the board has power, and three in another
group, as shown in Figure 1-6.

The LEDs labeled TX and RX light up when data is being transmitted or received
between the Arduino and attached devices via the serial port and USB. The L LED is
for your own use (it is connected to the digital I/O pin number 13). The little black
square part to the left of the LEDs is a tiny microcontroller that controls the USB
interface that allows your Arduino to send data to and receive it from a computer, but
you don’t generally have concern yourself with it.

Figure 1-6: The onboard LEDs

And, finally, the RESET button is shown in Figure 1-7.

Figure 1-7: The RESET button

As with a normal computer, sometimes things can go wrong with the Arduino, and
when all else fails, you might need to reset the system and restart your Arduino. This
simple RESET button on the board (Figure 1-7) is used to restart the system to resolve
these problems.

One of the great advantages of the Arduino system is its ease of expandability—that

31
is, it’s easy to add more hardware functions. The two rows of sockets along each side
of the Arduino allow the connection of a shield, another circuit board with pins that
allow it to plug into the Arduino. For example, the shield shown in Figure 2-8 contains
an Ethernet interface that allows the Arduino to communicate over networks and the
Internet, with plenty of space for custom circuitry.

Notice how the Ethernet shield also has rows of sockets. These enable you to insert one
or more shields on top. For example, Figure 1-9 shows that another shield with a large
numeric display, temperature sensor, extra data storage space, and a large LED has been
inserted.
Note that you do need to remember which shield uses which individual inputs and
outputs to ensure that “clashes” do not occur. You can also purchase completely blank
shields that allow you to add your own circuitry.

Figure 1-8: Arduino Ethernet interface shield

32
Figure 1-9: Numeric display and temperature shield
Pin Description of Arduino Board:

USB Plug: It is used for serial communication between Arduino and your computer to perform
certain tasks like uploading a program, debugging and so on.
Analog reference pin (AREF): Analog reference pin is used for reference voltage for analog to
digital converter i.e., A/D converter.

33
Digital ground: Digital ground is used for grounding the digital inputs.
Digital I/O Pins (2-13): This pins are used for reading and writing digital data. Out of these 12
pins i.e., from pin 2 to pin 13, 6 pins support PWM (Pulse Width Modulation). Note that the pins
prefixed with ‘~’ symbol supports PWM.
Serial Out (Tx): In general ‘Tx’ means transmitter, thus, serial out pin or Tx pin is used for
transmit the data serially.
Serial In (Rx): The function of Rx pin is exactly opposite as that of Tx, i.e., Rx pin is used to
receive data serially as Rx stands for receiver.
Reset Button: This button has a highest priority among all the pins to perform. If you wrote a
program on Arduino and reset it, then Arduino will restarts from initial stage i.e., if you not load
your program then you may have to load it again
In-Circuit Serial Programmer (ICSP): The ICSP is pin is used for mainly two purposes: (a)
For Boot-loading and (b) SPI (Serial Peripheral Interface) communication. Boot-loader is a
program which runs prior when you start your Arduino IDE. On the other hand, SPI is a serial
synchronous serial data protocol used by the microcontrollers for communicating with one or
more peripheral devices quickly over short distances
Atmega328 microcontroller: It is a processor of Atmel Company on which our Arduino Uno is
running.
Analog pins (0-5): This pins are used for taking inputs in analog form.
Voltage in (VIN): This pin is used for giving input voltages.
Ground pins: Ground pins are used for grounding the inputs.
5V power pin: 5V power pin is used for giving 5V to your Arduino Uno Board.
3.3V power pin: 3.3V power pins is used for giving 3.3V to Arduino Uno because some
peripherals may damage if operated above 3.6V. So, generally some peripherals work between
1.8V-3.6V.
Reset pin: The function of reset pin is same as the Reset button. In other words, there is an
alternative way to reset your Arduino Uno by using reset pin.
External power supply pin: This pin is used for giving 9V-12V DC external supply.
Arduino IDE:
The companion to the Arduino hardware is the software, a collection of instructions that
tell the hardware what to do and how to do it. Two types of software can be used: The
first is the integrated development environment (IDE), which is discussed in this
chapter, and the second is the Arduino sketch you create yourself.

The IDE software is installed on your personal computer and is used to compose and
send sketches to the Arduino board.

As shown in Figure 1-10, the Arduino IDE resembles a simple word processor. The IDE is
divided into three main areas: the command area, the text area, and the message
window area.

34
Figure 1-10: The Arduino IDE

The command area: The command area is shown at the top of Figure 1-10 and
includes the title bar, menu items, and icons. The title bar displays the sketch’s filename
(sketch_mar22a), as well as the version of the IDE (Arduino 1.0). Below this is a series of
menu items (File, Edit, Sketch, Tools, and Help) and icons, as described next.

Menu Items: As with any word processor or text editor, you can click one of the menu
items to display its various options.
File Contains options to save, load, and print sketches; a thorough set of example
sketches to open; as well as the Preferences submenu
Edit Contains the usual copy, paste, and search functions common to any word
processor
Sketch Contains the function to verify your sketch before uploading to a board, and

35
some sketch folder and import options
Tools Contains a variety of functions as well as the commands to select the Arduino
board type and USB port
Help Contains links to various topics of interest and the version of the IDE.
The Icons: Below the menu toolbar are six icons. Mouse over each icon to display its
name. The icons, from left to right, are as follows:
Verify Click this to check that the Arduino sketch is valid and doesn’t contain any
programming mistakes.
Upload Click this to verify and then upload your sketch to the Arduino board.
New Click this to open a new blank sketch in a new window.
Open Click this to open a saved sketch.
Save Click this to save the open sketch. If the sketch doesn’t have a name, you will
be prompted to create one.
Serial Monitor Click this to open a new window for use in sending and receiving data
between your Arduino and the IDE.

The Text Area: The text area is shown in the middle of Figure 1-10; this is where you’ll
create your sketches. The name of the current sketch is displayed in the tab at the upper
left of the text area. (The default name is the current date.) You’ll enter the contents
of your sketch here as you would in any text editor.
The Message window Area: The message window area is shown at the bottom of
Figure 1-10. Messages from the IDE appear in the black area. The messages you see will
vary and will include messages about verifying sketches, status updates, and so on At
the bottom right of the message area, you should see the name of your Arduino board
type as well as its connected USB port—Arduino Duemilanove w/ATmega328 on COM6 in
this case.

36
2. a. Blinking of an LED
Aim: To Blink a led using Arduino.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. LED -1
5. Resistor 330 ohms-1
6. Bread Board-1
7. Connecting Wires -Required
Theory: LED: A light-emitting diode (LED) is a semiconductor device that emits visible light
when an electric current passes through it. The light is not particularly bright, but in most LEDs
it is monochromatic, occurring at a single wavelength. The output from an LED can range from
red (at a wavelength of approximately 700 nanometers) to blue-violet (about 400 nanometers).
Some LEDs emit infrared (IR) energy (830 nanometers or longer); such a device is known as an
infrared-emitting diode (IRED).
Advantages of LED’s:
● Low power requirement: Most types can be operated with battery power supplies.
● High efficiency: Most of the power supplied to an LED or IRED is converted into
radiation in the desired form, with minimal heat production.
● Long life: When properly installed, an LED or IRED can function for decades.
Applications:

● Indicator lights: These can be two-state (i.e., on/off), bar-graph, or alphabetic-numeric


readouts.
● LCD panel backlighting: Specialized white LEDs are used in flat-panel computer
displays.
● Fiber optic data transmission: Ease of modulation allows wide communications
bandwidth with minimal noise, resulting in high speed and accuracy.
● Remote control: Most home-entertainment "remotes" use IREDs to transmit data to the
main unit.
● Optoisolator: Stages in an electronic system can be connected together without unwanted
interaction.

37
Circuit diagram:

Procedure:
1. Open Arduino IDE.
2. Write the code in text editor.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window,rectify those errors and
compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a few
seconds. If successful, the message "Done uploading." will appear in the status bar.
Code:

void setup( )
{
pinMode(13,OUTPUT);
}

void loop( )
{
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
}
Result:

LED Blink continuously.

38
2. b. Magic bulb: Creating a Function
TO
Set the Number of Blinks
Aim: To blink a led with given number of times.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. LED -1
5. Resistor 330 ohms-1
6. Bread Board-1
7. Connecting Wires -Required

Theory: LED: A light-emitting diode (LED) is a semiconductor device that emits visible light
when an electric current passes through it. The light is not particularly bright, but in most LEDs
it is monochromatic, occurring at a single wavelength. The output from an LED can range from
red (at a wavelength of approximately 700 nanometers) to blue-violet (about 400 nanometers).
Some LEDs emit infrared (IR) energy (830 nanometers or longer); such a device is known as an
infrared-emitting diode (IRED).
Advantages of LED’s:
● Low power requirement: Most types can be operated with battery power supplies.
● High efficiency: Most of the power supplied to an LED or IRED is converted into
radiation in the desired form, with minimal heat production.
● Long life: When properly installed, an LED or IRED can function for decades.
Applications:

● Indicator lights: These can be two-state (i.e., on/off), bar-graph, or alphabetic-numeric


readouts.
● LCD panel backlighting: Specialized white LEDs are used in flat-panel computer
displays.
● Fiber optic data transmission: Ease of modulation allows wide communications
bandwidth with minimal noise, resulting in high speed and accuracy.
● Remote control: Most home-entertainment "remotes" use IREDs to transmit data to the
main unit.
● Optoisolator: Stages in an electronic system can be connected together without unwanted
interaction.

39
Circuit diagram:

Procedure:
1. Open Arduino IDE.
2. Write the code in text editor.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window,rectify those errors and
compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a few
seconds. If successful, the message "Done uploading." will appear in the status bar.

Code:
// Creating a Function to Set the Number of Blinks
#define LED 13
void setup()
{
pinMode(LED, OUTPUT);
}
void blinkLED(int cycles, int del)
{
for ( int z = 0 ; z < cycles ; z++ )
{
digitalWrite(LED, HIGH); delay(del);
digitalWrite(LED, LOW); delay(del);
}
}

40
void loop()
{
blinkLED(12, 100);
delay(1000);
}

Result:
LED blinks given number of times.

41
3. Printing numbers on 7-segment display
Aim: To display numbers on 7-segment display.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. Seven segment display-1
5. Resistor 330 ohms-1
6. Bread Board-1
7. Connecting Wires –Required
Theory: The 7-segment display, also written as “seven segment display”, consists of seven
LEDs (hence its name) arranged in a rectangular fashion as shown. Each of the seven LEDs is
called a segment because when illuminated the segment forms part of a numerical digit (both
Decimal and Hex) to be displayed. An additional 8th LED is sometimes used within the same
package thus allowing the indication of a decimal point, (DP) when two or more 7-segment
displays are connected together to display numbers greater than ten.
Circuit Diagram:

42
Procedure:
1. Open Arduino IDE.
2. Write the code in text editor.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those errors and
compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a few
seconds. If successful, the message "Done uploading." will appear in the status bar.

Code:
// Pin 2-8 is connected to the 7 segments of the display.

int pinA = 2;
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 7;
int pinG = 8;

// the setup routine runs once when you press reset:


void setup() {
// initialize the digital pins as outputs.
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);
pinMode(pinD, OUTPUT);
pinMode(pinE, OUTPUT);
pinMode(pinF, OUTPUT);
pinMode(pinG, OUTPUT);
}

// the loop routine runs over and over again forever:


void loop() {
//0
digitalWrite(pinA, LOW);

43
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, HIGH);
delay(1000); // wait for a second

//1
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
delay(1000); // wait for a second

//2
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, LOW);
delay(1000); // wait for a second

//3
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, LOW);
delay(1000); // wait for a second

//4
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);

44
delay(1000); // wait for a second

//5
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
delay(1000); // wait for a second

//6
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
delay(1000); // wait for a second

//7
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
delay(1000); // wait for a second

//8
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
delay(1000); // wait for a second

//9
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);

45
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
delay(1000); // wait for a second
}

Result:
Numbers Displayed on Seven segment Display.

46
4. Controlling of LED’s by using switches.

Aim: Our goal in this project is to create a button that turns on an LED for half a second when
pressed.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. LED-1
5. Switch -1
6. Resistor 10kΩ-1
7. Bread Board-1
8. Capacitor 100nF-1
9. Connecting Wires -Required
Theory: A push-button (also spelled pushbutton) or simply button is a simple switch
mechanism for controlling some aspect of a machine or a process. Buttons are typically made out
of hard material, usually plastic or metal. Ceramic capacitors are very small and therefore hold a
small amount of charge. They are not polarized and can be used for current flowing in either
direction. Ceramic capacitors work beautifully in high-frequency circuits because they can
charge and discharge very quickly due to their small capacitance.

Circuit Diagram:

47
Procedure:
10. Open Arduino IDE.
11. Write the code in text editor.
12. Save the sketch with .ino extension.
13. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
14. Select the serial device of the Arduino board from the Tools | Serial Port menu.
15. Compile the file by clicking on verify button.
16. If successful, the message "Done Compiling." will appear in the status bar.
17. If there is any errors it will show them in Transcript window, rectify those errors and
compile it again.
18. Push the reset button on the board then click the Upload button in the IDE. Wait a few
seconds. If successful, the message "Done uploading." will appear in the status bar.

Code:

//Controlling of LED’s by using switches.


#define LED 12
#define BUTTON 7
void setup()
{
pinMode(LED, OUTPUT); // output for the LED
pinMode(BUTTON, INPUT); // input for the button
}
void loop()
{
if ( digitalRead(BUTTON) == HIGH )
{
digitalWrite(LED, HIGH); // turn on the LED
delay(500); // wait for 0.5 seconds
digitalWrite(LED, LOW); // turn off the LED
}
}

Result:
When switch pressed led will be on for 0.5 seconds.

48
5. PWM digital output :Controlling of brightness (fading)
of an LED

Aim: Our goal in this project is to control the brightness of led using PWM pins.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. LED-1
5. Resistor 10kΩ-1
7. Bread Board-1
8. Connecting Wires -Required
Theory: Pulse Width Modulation, or PWM, is a technique for getting analog results with
digital means. Digital control is used to create a square wave, a signal switched between on and
off. This on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by
changing the portion of the time the signal spends on versus the time that the signal spends off.
The duration of "on time" is called the pulse width. To get varying analog values, you change, or
modulate, that pulse width. If you repeat this on-off pattern fast enough with an LED for
example, the result is as if the signal is a steady voltage between 0 and 5v controlling the
brightness of the LED.
Circuit Diagram:

49
Procedure:

1. Open Arduino IDE.


2. Write the code in text editor.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those errors and
compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a few
seconds. If successful, the message "Done uploading." will appear in the status bar.
Code:
int ledPin = 2; // LED connected to digital pin 2

void setup() {

// nothing happens in setup

void loop() {

// fade in from min to max in increments of 5 points:

for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {

// sets the value (range from 0 to 255):

analogWrite(ledPin, fadeValue);

// wait for 30 milliseconds to see the dimming effect

delay(30);

50
// fade out from max to min in increments of 5 points:

for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {

// sets the value (range from 0 to 255):

analogWrite(ledPin, fadeValue);

// wait for 30 milliseconds to see the dimming effect

delay(30);

Result:

Brightness of led will changes with respect to PWM pin output.

51
6. a. An example to print output on serial monitor
Aim: Our goal in this project is to print the status of led in serial monitor.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. LED -1
5. Resistor 330 ohms-1
6. Bread Board-1
7. Connecting Wires -Required
Theory:
Serial Monitor displays serial data being sent from the Arduino or Genuino board (USB or serial
board). To send data to the board, enter text and click on the "send" button or press enter. Choose
the baud rate from the drop-down that matches the rate passed to Serial.begin in your sketch
Circuit diagram:

Procedure:
1. Open Arduino IDE.
2. Write the code in text editor.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those
errors and compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a
few seconds. If successful, the message "Done uploading." will appear
in the status bar.

52
10. Click the serial monitor button in the toolbar and select the same baud rate used in the call to
begin ().
Code:
int ledPin = 13; // LED connected to digital pin 13

void setup( )
{
pinMode(ledPin ,OUTPUT);
Serial.begin(9600);
}

void loop( )
{
digitalWrite(ledPin ,HIGH);
Serial.println(“LED is High”);
delay(1000);
digitalWrite(ledPin ,LOW);
Serial.println(“LED is Low”);
delay(1000);
}
Result:
Status of LED is observed in the serial monitor

53
6.2. Controlling of RGB led by taking input from serial
monitor
Aim: Our goal in this project is to control RGB led by taking input from serial monitor and
display the status of RGB led.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. RGB LED -1
5. Resistor 1KΩ-3
6. Bread Board-1
7. Connecting Wires -Required
Theory: RGB LED means red, blue and green LEDs. RGB LED products combine these three
colors to produce over 16 million hues of light. Note that not all colours are possible. Some
colors are “outside” the triangle formed by the RGB LEDs. Also, pigment colours such as brown
or pink are difficult, or impossible, to achieve.

Circuit Diagram:

54
Procedure:
1. Open Arduino IDE.
2. Write the code in text editor.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those
errors and compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a
few seconds. If successful, the message "Done uploading." will appear
in the status bar.
10. Click the serial monitor button in the toolbar and select the same baud rate used in the call to
begin().
11.To send data to the board, enter text and click on the "send" button or press enter.

Code:

int redpin=11; //Pin

int greenpin=10; //Pin

int bluepin=9; //Pin

int ch;

void setup()

pinMode(redpin,OUTPUT);

pinMode(greenpin,OUTPUT);

pinMode(bluepin,OUTPUT);

Serial.begin(9600);

55
}

void loop()

if(Serial.available()>=0)

ch = Serial.read();

if (ch == 'r'){

digitalWrite(redpin,HIGH); //RED

digitalWrite(greenpin,LOW);

digitalWrite(bluepin,LOW);

delay(1000);

Serial.print("red is on");

else if (ch == 'g'){

digitalWrite(redpin,LOW); //green

digitalWrite(greenpin,HIGH);

digitalWrite(bluepin,LOW);

delay(1000);

Serial.print("green is on");

else if (ch == 'b'){

56
digitalWrite(redpin,LOW); //blue

digitalWrite(greenpin,LOW);

digitalWrite(bluepin,HIGH);

delay(1000);

Serial.print("blue is on");

else if (ch == 's'){

digitalWrite(redpin,LOW); //reset

digitalWrite(greenpin,LOW);

digitalWrite(bluepin,LOW);

delay(1000);

Serial.print("led reset");

Result:

Status of RGB led is displayed on serial monitor by taking inputs r,g,b&s from serial monitor.

57
7. a. Print input text in scrolling from right to left
Aim: Our goal in this project is scroll input text on LCD from right to left.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4.16x2 LCD Screen
5. Potentiometer 10kΩ -1
6. Resistor 220Ω -1
7. Bread Board-1
8. Connecting Wires -Required
Theory: LCD (liquid crystal display) is the technology used for displays in notebook and other
smaller computers. Like light-emitting diode (LED) and gas-plasma technologies, LCDs allow
displays to be much thinner than cathode ray tube (CRT) technology.
Circuit Diagram:

58
Procedure:
1. Open Arduino IDE.
2. Write the code in text editor.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those
errors and compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a
few seconds. If successful, the message "Done uploading." will appear
in the status bar.

Code:

// include the library code:


#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
delay(1000);
}
void loop() {
// scroll 13 positions (string length) to the left
// to move it offscreen left:
for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(150);
}

59
}

Result:
Given input text is scrolled from right to left in LCD.

60
7. b. Print input text in scrolling from left to right

Aim: Our goal in this project is scroll input text on LCD from left to right.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4.16x2 LCD Screen
5. Potentiometer 10kΩ -1
6. Resistor 220Ω -1
7. Bread Board-1
8. Connecting Wires -Required
Theory: LCD (liquid crystal display) is the technology used for displays in notebook and other
smaller computers. Like light-emitting diode (LED) and gas-plasma technologies, LCDs allow
displays to be much thinner than cathode ray tube (CRT) technology.
Circuit Diagram:

61
Procedure:
1. Open Arduino IDE.
2. Write the code in text editor.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those
errors and compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a
few seconds. If successful, the message "Done uploading." will appear
in the status bar.

Code:

// include the library code:


#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
delay(1000);
}
void loop() {
// scroll 29 positions (string length + display length) to the right
// to move it offscreen right:
for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
// scroll one position right:
lcd.scrollDisplayRight();
// wait a bit:
delay(150);
}
}

62
Result:
Given input text is scrolled from left to right in LCD.

63
8. Led matrix interfacing with the Arduino and printing
different types of shapes on 8x8 led matrix
Aim: Our goal in this project is interface led matrix with the Arduino and print different types
of shapes on LED matrix.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. MAX7219 Red Dot Matrix Module-1
5. Connecting Wires-Required
Theory: An LED matrix or LED display is a large, low-resolution form of dot-matrix display,
useful both for industrial and commercial information displays as well as for hobbyist human–
machine interfaces. It consists of a 2-D diode matrix with their cathodes joined in rows and their
anodes joined in columns (or vice versa).
Circuit Diagram:

Procedure:
1. Open Arduino IDE.
2. Write the code in text editor. While writing the code add LEDControlMS library to code.
Download required library for the project from the internet. To install a new library into your
Arduino IDE you can use the Library Manager. Open the IDE and click to the "Sketch" menu

64
and then Include Library > Manage Libraries. Then the library manager will open and you will
find a list of libraries that are already installed or ready for installation.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those
errors and compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a
few seconds. If successful, the message "Done uploading." will appear
in the status bar.
Code:
LedControl lc=LedControl(12,11,10,1);
/* we always wait a bit between updates of the display */
unsigned long delaytime=100;
void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}

/*
This method will display the characters for the
word "Arduino" one after the other on the matrix.
(you need at least 5x7 leds to see the whole chars)
*/
void writeArduinoOnMatrix() {
/* here is the data for the characters */
byte a[5]={B01111110,B10001000,B10001000,B10001000,B01111110};
byte r[5]={B00111110,B00010000,B00100000,B00100000,B00010000};
byte d[5]={B00011100,B00100010,B00100010,B00010010,B11111110};
byte u[5]={B00111100,B00000010,B00000010,B00000100,B00111110};
byte i[5]={B00000000,B00100010,B10111110,B00000010,B00000000};

65
byte n[5]={B00111110,B00010000,B00100000,B00100000,B00011110};
byte o[5]={B00011100,B00100010,B00100010,B00100010,B00011100};

/* now display them one by one with a small delay */


lc.setRow(0,0,a[0]);
lc.setRow(0,1,a[1]);
lc.setRow(0,2,a[2]);
lc.setRow(0,3,a[3]);
lc.setRow(0,4,a[4]);
delay(delaytime);
lc.setRow(0,0,r[0]);
lc.setRow(0,1,r[1]);
lc.setRow(0,2,r[2]);
lc.setRow(0,3,r[3]);
lc.setRow(0,4,r[4]);
delay(delaytime);
lc.setRow(0,0,d[0]);
lc.setRow(0,1,d[1]);
lc.setRow(0,2,d[2]);
lc.setRow(0,3,d[3]);
lc.setRow(0,4,d[4]);
delay(delaytime);
lc.setRow(0,0,u[0]);
lc.setRow(0,1,u[1]);
lc.setRow(0,2,u[2]);
lc.setRow(0,3,u[3]);
lc.setRow(0,4,u[4]);
delay(delaytime);
lc.setRow(0,0,i[0]);
lc.setRow(0,1,i[1]);
lc.setRow(0,2,i[2]);
lc.setRow(0,3,i[3]);
lc.setRow(0,4,i[4]);
delay(delaytime);
lc.setRow(0,0,n[0]);
lc.setRow(0,1,n[1]);
lc.setRow(0,2,n[2]);
lc.setRow(0,3,n[3]);
lc.setRow(0,4,n[4]);
delay(delaytime);
lc.setRow(0,0,o[0]);

66
lc.setRow(0,1,o[1]);
lc.setRow(0,2,o[2]);
lc.setRow(0,3,o[3]);
lc.setRow(0,4,o[4]);
delay(delaytime);
lc.setRow(0,0,0);
lc.setRow(0,1,0);
lc.setRow(0,2,0);
lc.setRow(0,3,0);
lc.setRow(0,4,0);
delay(delaytime);
}

/*
This function lights up a some Leds in a row.
The pattern will be repeated on every row.
The pattern will blink along with the row-number.
row number 4 (index==3) will blink 4 times etc.
*/
void rows() {
for(int row=0;row<8;row++) {
delay(delaytime);
lc.setRow(0,row,B10100000);
delay(delaytime);
lc.setRow(0,row,(byte)0);
for(int i=0;i<row;i++) {
delay(delaytime);
lc.setRow(0,row,B10100000);
delay(delaytime);
lc.setRow(0,row,(byte)0);
}
}
}

/*
This function lights up a some Leds in a column.
The pattern will be repeated on every column.
The pattern will blink along with the column-number.
column number 4 (index==3) will blink 4 times etc.
*/
void columns() {

67
for(int col=0;col<8;col++) {
delay(delaytime);
lc.setColumn(0,col,B10100000);
delay(delaytime);
lc.setColumn(0,col,(byte)0);
for(int i=0;i<col;i++) {
delay(delaytime);
lc.setColumn(0,col,B10100000);
delay(delaytime);
lc.setColumn(0,col,(byte)0);
}
}
}

/*
This function will light up every Led on the matrix.
The led will blink along with the row-number.
row number 4 (index==3) will blink 4 times etc.
*/
void single() {
for(int row=0;row<8;row++) {
for(int col=0;col<8;col++) {
delay(delaytime);
lc.setLed(0,row,col,true);
delay(delaytime);
for(int i=0;i<col;i++) {
lc.setLed(0,row,col,false);
delay(delaytime);
lc.setLed(0,row,col,true);
delay(delaytime);
}
}
}
}

void loop() {
writeArduinoOnMatrix();
rows();
columns();
single();

68
}

Result:
LED matrix is interfaced with Arduino and different types of shapes are displayed on LED
Matrix.

69
9. Arduino board interfacing with the LDR sensor print
output on Serial monitor
Aim: Our goal in this project is to interface LDR with Arduino and print output on serial
monitor.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. LDR-1
5. Resistor 1KΩ -1
7. Bread Board-1
8. Connecting Wires -Required
Theory: A Light Dependent Resistor (LDR) or a photo resistor is a device whose resistivity is
a function of the incident electromagnetic radiation. Hence, they are light sensitive devices. They
are also called as photoconductors, photoconductive cells or simply photocells. They are made
up of semiconductor materials having high resistance. LDR’s are light dependent devices whose
resistance is decreased when light falls on them and that is increased in the dark. When a light
dependent resistor is kept in dark, its resistance is very high. This resistance is called as dark
resistance. It can be as high as 1012 Ω and if the device is allowed to absorb light its resistance
will be decreased drastically. If a constant voltage is applied to it and intensity of light is
increased the current starts increasing.

70
Circuit Diagram:

Procedure:
1. Open Arduino IDE.
2. Write the code in text editor.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.

71
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those
errors and compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a
few seconds. If successful, the message "Done uploading." will appear
in the status bar.

Code:

int LDR_Pin = A0; //analog pin 0


void setup(){
Serial.begin(9600);
}
void loop(){
int LDRReading = analogRead(LDR_Pin);
Serial.println(LDRReading);
delay(250); //just here to slow down the output for easier reading
}

Result:
We can observe LDR readings in serial monitor.

72
10. Arduino board interfacing with the temperature
sensor print output on Serial monitor
Aim: Our goal in this project is to interface temperature sensor with Arduino and print output
on serial monitor.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. Temperature sensor LM35 -1
5. Bread Board-1
8. Connecting Wires -Required
Theory: The LM35 series are precision integrated-circuit temperature devices with an output
voltage linearly-proportional to the Centigrade temperature. ... The LM35 device is rated to
operate over a −55°C to 150°C temperature range, while the LM35C device is rated for a −40°C
to 110°C range (−10° with improved accuracy).
Circuit Diagram:

73
Procedure:
1. Open Arduino IDE.
2. Write the code in text editor.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those
errors and compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a
few seconds. If successful, the message "Done uploading." will appear
in the status bar.

Code:
float sensor, voltage, celsius;
void setup()
{
Serial.begin(9600);
}
void loop()
{
sensor = analogRead(0);
voltage = (sensor * 5000) / 1024; // convert raw sensor value to millivolts
celsius = voltage / 10;
delay(500
}
Result:
Temperature values are displayed on serial monitor for every 500ms.

74
11. Arduino board interfacing with the Humidity sensor
print output on Serial monitor.
Aim: Our goal in this project is to interface Humidity sensor with Arduino and print output on
serial monitor.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. Humidity sensor DHT11 -1
6. Bread Board-1
7. Connecting Wires -Required
Theory: A humidity sensor (or hygrometer) senses, measures and reports the relative humidity
in the air. It therefore measures both moisture and air temperature. Relative humidity is the ratio
of actual moisture in the air to the highest amount of moisture that can be held at that air
temperature. Humidity sensors can be used as a monitoring and preventive measure in homes for
people with illnesses that are affected by humidity. They are also found as part of home heating,
ventilating, and air conditioning systems (HVAC systems). They can also be found in offices,
cars, humidors, museums, industrial spaces and greenhouses and can be used in meteorology
stations to report and predict weather.
Circuit Diagram:

75
Procedure:
1. Open Arduino IDE.
2. Write the code in text editor. while writing the code add “dht.h”library to code. Download
required library for the project from the internet. To install a new library into your Arduino IDE
you can use the Library Manager. Open the IDE and click to the "Sketch" menu and then Include
Library > Manage Libraries. Then the library manager will open and you will find a list of
libraries that are already installed or ready for installation.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those
errors and compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a
few seconds. If successful, the message "Done uploading." will appear
in the status bar.

Code:
#include <dht.h>
dht DHT;
#define DHT11_PIN 2
void setup(){
Serial.begin(9600);
}
void loop()
{
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
delay(1000);
}
Result:
Temperature and humidity values are displayed on serial monitor using arduino.

76
12. Arduino board interfacing with the Touch sensor print
output on Serial monitor.
Aim: Our goal in this project is to interface Touch sensor with Arduino and print output on
serial monitor.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. Touch sensor -1
6. Bread Board-1
7. Connecting Wires -Required
Theory: A touch sensor is a type of equipment that captures and records physical touch or
embrace on a device and/or object. It enables a device or object to detect touch, typically by a
human user or operator. A touch sensor may also be called a touch detector.
Circuit Diagram:

Procedure:
1. Open Arduino IDE.
2. Write the code in text editor.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.

77
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those
errors and compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a
few seconds. If successful, the message "Done uploading." will appear
in the status bar.
Code:
int Led = 13 ; // define LED Interface
int buttonpin = 3; // define Metal Touch Sensor Interface
int val ; // define numeric variables val
void setup ()
{
pinMode (Led, OUTPUT) ; // define LED as output interface
pinMode (buttonpin, INPUT) ;
Serial.begin(9600)
}
void loop ()
{
val = digitalRead (buttonpin) ; // digital interface will be assigned a value of 3 to read val
if (val == HIGH) // When the metal touch sensor detects a signal, LED flashes
{
digitalWrite (Led, HIGH);
Serial.println(“object detected”);
}
else
{
digitalWrite (Led, LOW);
}
}

Result:
Whenever an object touches touch sensor, Led blink and corresponding message displayed in
serial monitor.

78
13. Arduino board interfacing with the Buzzer sensor print
output on Serial monitor.
Aim: Our goal in this project is to interface Buzzer sensor with Arduino and print output on
serial monitor.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. Buzzer sensor -1
6. Bread Board-1
7. Connecting Wires -Required
Theory: Active Buzzer Module will produces a single-tone sound when signal is high.

Circuit diagram:

Procedure:
1. Open Arduino IDE.
2. Write the code in text editor.
3. Save the sketch with .ino extension.

79
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those
errors and compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a
few seconds. If successful, the message "Done uploading." will appear
in the status bar.
Code:
int speakerPin = 8;
void setup () {
pinMode (speakerPin, OUTPUT);
Serial.begin(9600);
}
void loop () {
analogWrite (speakerPin, 255);
Serial.println(“buzzer activated”);
delay (50);
analogWrite (speakerPin, 0);
delay (10);
}

Result:
When signal is high active buzzer module produced single tone output respectively buzzer
activated message displayed in serial monitor.

80
14. Arduino board interfacing with the Ultrasonic sound
sensor print output on Serial monitor.
Aim: Our goal in this project is to interface Ultrasonic sensor with Arduino and print output on
serial monitor.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. Ultrasonic sensor-1
5. Bread Board-1
6. Connecting Wires -Required
Theory: Active ultrasonic sensors generate high-frequency sound waves and evaluate the
echo which is received back by the sensor, measuring the time interval between sending the
signal and receiving the echo to determine the distance to an object.
Circuit Diagram:

Procedure:
1. Open Arduino IDE.
2. Write the code in text editor.while writing the code add “ultrasonic.h”library to
code.Download required library for the project from the internet.To install a new library into
your Arduino IDE you can use the Library Manager. Open the IDE and click to the "Sketch"
menu and then Include Library > Manage Libraries.Then the library manager will open and you
will find a list of libraries that are already installed or ready for installation.
3. Save the sketch with .ino extension.

81
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those
errors and compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a
few seconds. If successful, the message "Done uploading." will appear
in the status bar.

Code:
#include <Ultrasonic.h>
Ultrasonic ultrasonic(4,2);
long microsec = 0;
float distanciaCM = 0;

void setup () {
Serial.begin(9600);
}
void loop () {
microsec = ultrasonic.timing();
distanciaCM = ultrasonic.convert(microsec, Ultrasonic::CM);
Serial.print(distanciaCM);
Serial.println(" cm");
delay(1000);
}
Result:
Whenever Ultrasonic sensor detects an object,distance between the object and sensor displayed
on the serial monitor.

82
15. Arduino board interfacing with the Color sensor print
output on Serial monitor.
Aim: Our goal in this project is to interface Color sensor with Arduino and print output on serial
monitor.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. Color sensor-1
5. Bread Board-1
6. Connecting Wires -Required
Theory: The color sensor product family provides red, green, blue and clear (RGBC) light
sensing for precise color measurement, determination, and discrimination. A SYNC input allows
for greater accuracy by enabling the color sensing to be synchronized with an external event.
Circuit Diagram:

83
Procedure:
1. Open Arduino IDE.
2. Write the code in text editor.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those
errors and compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a
few seconds. If successful, the message "Done uploading." will appear
in the status bar.
Code:
#define s0 8
#define s1 9
#define s2 12
#define s3 11
#define sensorOut 10
int frequency =0;
void setup() {
pinMode(s0,OUTPUT);
pinMode(s1,OUTPUT);
pinMode(s2,OUTPUT);
pinMode(s3,OUTPUT);
pinMode(sensorOut,OUTPUT);

digitalWrite(s0,HIGH);
digitalWrite(s1,LOW);
Serial.begin(9600);

void loop() {
digitalWrite(s2,LOW);
digitalWrite(s3,LOW);
frequency=pulseIn(sensorOut,LOW);
Serial.print("R= ");
Serial.print(frequency);
Serial.print(" ");

84
delay(100);

digitalWrite(s2,HIGH);
digitalWrite(s3,HIGH);
frequency=pulseIn(sensorOut,LOW);
Serial.print("G= ");
Serial.print(frequency);
Serial.print(" ");
delay(100);

digitalWrite(s2,LOW);
digitalWrite(s3,HIGH);
frequency=pulseIn(sensorOut,LOW);
Serial.print("B= ");
Serial.print(frequency);
Serial.print(" ");
delay(100);
}

Result:
Colors(R, G&B) which are detected are displayed on serial monitor.

85
16. a. Arduino interfacing with DC bipolar motor
Aim: Our goal in this project is to interface DC Bipolar motor with Arduino.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. DC Motor-1
5. Transistor PN2222-NPN -1
6. Diode 1N4001 -1
7. Resistor 270 -1
8. Bread Board-1
9. Connecting Wires -Required
Theory: A DC motor is any of a class of electrical machines that converts direct current
electrical power into mechanical power. The most common types rely on the forces produced by
magnetic fields. DC motors were the first type widely used, since they could be powered from
existing direct-current lighting power distribution systems. A DC motor's speed can be controlled
over a wide range, using either a variable supply voltage or by changing the strength of current in
its field windings. Small DC motors are used in tools, toys, and appliances.
Circuit Diagram:

86
Procedure:
1. Open Arduino IDE.
2. Write the code in text editor.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those errors and
compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a few
seconds. If successful, the message "Done uploading." will appear in the status bar.

Code:
int motorPin = 3;
void setup()
{
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
while (! Serial);
Serial.println("Speed 0 to 255");
}
void loop()
{
if (Serial.available())
{
int speed = Serial.parseInt();
if (speed >= 0 && speed <= 255)
{
analogWrite(motorPin, speed);
}
}
}
Result:
DC Motor is interfaced and controlled using Arduino.

87
16. b. Arduino interfacing with Stepper motor
Aim: Our goal in this project is to interface Stepper motor with Arduino.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. Stepper Motor-1
5. L293d-1
6. Bread Board-1
7. Connecting Wires -Required
Theory: A stepper motor is essentially a servo motor that uses a different method of
motorization. Where a servo motor uses a continuous rotation DC motor and
integrated controller circuit, stepper motors utilize multiple toothed electromagnets arranged
around a central gear to define position. Stepper motors are DC motors that move in discrete
steps. They have multiple coils that are organized in groups called "phases". By energizing each
phase in sequence, the motor will rotate, one step at a time. With a computer
controlled stepping you can achieve very precise positioning and/or speed control.
Circuit Diagram:

88
Procedure:
1. Open Arduino IDE.
2. Write the code in text editor. While writing the code add “Servo.h” library to code.
Download required library for the project from the internet. To install a new library into your
Arduino IDE you can use the Library Manager. Open the IDE and click to the "Sketch" menu
and then Include Library > Manage Libraries. Then the library manager will open and you will
find a list of libraries that are already installed or ready for installation.
3. Save the sketch with .ino extension.
4. Connect the hardware circuit and Connect your Arduino Board to the USB port of your
computer.
5. Select the serial device of the Arduino board from the Tools | Serial Port menu.
6. Compile the file by clicking on verify button.
7. If successful, the message "Done Compiling." will appear in the status bar.
8. If there is any errors it will show them in Transcript window, rectify those
errors and compile it again.
9. Push the reset button on the board then click the Upload button in the IDE. Wait a
few seconds. If successful, the message "Done uploading." will appear
in the status bar.

Code:
#include<Stepper.h>
int in1Pin = 12;
int in2Pin = 11;
int in3Pin = 10;
int in4Pin = 9;
Stepper motor(512, in1Pin, in2Pin, in3Pin, in4Pin);
void setup()
{
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(in3Pin, OUTPUT);
pinMode(in4Pin, OUTPUT);
while (!Serial);
Serial.begin(9600);
motor.setSpeed(20);
}
void loop()
{
if (Serial.available())
{
int steps = Serial.parseInt();
motor.step(steps);

89
}
}
Result:
Stepper Motor is interfaced and controlled using Arduino.

90
16. c. Arduino interfacing with Servo motor

Aim: Our goal in this project is to interface Servo motor with Arduino.
Software: Arduino IDE
Components Required: 1. System -1
2. Arduino Uno Board -1
3. Arduino dumping cable -1
4. Servo Motor-1
5. Variable resistor 10K -1
6. Capacitor 100F -1
7. Bread Board-1
8. Connecting Wires -Required
Theory: Servo motors are generally an assembly of four things: a DC motor, a gearing set, a
control circuit and a position-sensor (usually a potentiometer). The position of servo motors can
be controlled more precisely than those of standard DC motors, and they usually have three wires
(power, ground & control). Power to servo motors is constantly applied, with the servo control
circuit regulating the draw to drive the motor. Servo motors are designed for more specific tasks
where position needs to be defined accurately such as controlling the rudder on a boat or moving
a robotic arm or robot leg within a certain range. Servo motors do not rotate freely like a
standard DC motor. Instead the angle of rotation is limited to 180 Degrees (or so) back and forth.
Servo motors receive a control signal that represents an output position and applies power to the
DC motor until the shaft turns to the correct position, determined by the position sensor.
Circuit Diagram:

91
Code:
#include<Servo.h>
int potPin = 0;
int servoPin = 9;
Servo servo;
void setup()
{
servo.attach(servoPin);
}
void loop()
{
int reading = analogRead(potPin); // 0 to 1023
int angle = reading / 6; // 0 to 180-ish
servo.write(angle);
}
Result:
Servo motor is controlled using Arduino.

92

You might also like