Lab #1
Lab #1
Internet of Things
Lab # 1
Last date of Submission: 13-03-2023
Introduction:
Objectives:
• Getting familiar with how Arduino works in the internet of things environment.
• The basic concept of Arduino and understanding different pins and parts of the
module.
• Command on how to do the programming using the software and hardware
PINOUT Configuration:
The Arduino Uno is a microcontroller board based on the ATmega328p microcontroller. It has
the following pinout:
• 14 digital input/output pins (6 can be used as Pulse Width Modulation (PWM) outputs)
• 6 analog inputs
• Crystal oscillator
• USB connection
• Power jack
• In-Circuit Serial Programming ICSP header
• Reset button
Digital pins: These pins are used with digitalRead(), digitalWrite(), and analogWrite().
analogWrite() works only on the pins with the PWM symbol as shown in Fig. 1.
Pin 13 LED: This pin includes only actuator built-in to your board. Besides being a handy
target for your first blink sketch, this LED is very useful for debugging.
Power LED: This pin indicates that your Arduino is receiving power. It is very useful for
debugging.
GND and 5V: These pins are used to provide +5V power and ground to your circuits.
Power connector: This is used to power your Arduino when it’s not plugged into a USB port
for power. It can accept voltages between 7-12V.
TX and RX LEDs: These LEDs indicate communication between your Arduino and your
computer. They also flicker rapidly during sketch upload as well as during serial
communication. These are also useful for debugging.
USB port: This port is used for powering your Arduino Uno, uploading your sketches to your
Arduino, and for communicating with your Arduino.
Reset button: This button is used to resets the ATmega microcontroller.
Arduino Software (IDE): The software and step-by-step directions for its installation is
available at: http://arduino.cc/en/Main/Software
Install the Drivers for Windows: After successfully installing Arduino IDE, the next step is
to install the supported drivers for the cable that has been used for connecting the Arduino
board to Computer. Following steps need to be followed for the successful installation of the
drivers.
1. Plug-in board via USB and wait for Windows to begin its driver installation process.
After a few moments, the process will fail i.e., this is not unexpected.
2. Click on the “StartMenu”, and open up the “Control Panel”.
3. While in the “Control Panel”, navigate to “System and Security”. Next, click on
“System”. Once the System window is up, open the “Device Manager”.
4. Look under Ports (COM & LPT). There must be an open port named "Arduino UNO
(COMxx)".
5. Right-click on the "Arduino UNO (COMxx)" port and choose the "Update Driver
Software" option.
6. Next, choose the"Browse my computer for Driver software" option.
7. Finally, navigate to and select the Uno’s driver file, named "ArduinoUNO.inf", located
in the "Drivers" folder of the Arduino Software download.
8. Windows will finish up the driver installation from there.
Integrated Development Environment (IDE): Different menus with a variety of options are
available in Arduino IDE which makes it easy to use. The few important and most frequently
used icons are discussed as under.
Compile: Before program “code” can be sent to the board, it first needs to be converted into
instructions that the board understands. This process is called compiling.
Create new Sketch: This opens a new window to create a new sketch.
Upload to Board: This compiles the code and then transmits it over the USB cable to board.
Serial Monitor: This is used to receive data from external devices through USB cable /DB9
connector.
Tab Button: This lets you to create multiple files in sketch. This is for more advanced
programming that is not a part of this course.
Text Console: This shows what the IDE is currently doing and error messages are also
displayed here.
The Arduino IDE consists of few example sketches which can be uploaded to Arduino board
by using following steps:
setup ():
This function is called once when the program starts.
loop ():
This function is called repetitively over and over again.
Digital Pins: Digital pins are much easy to understand as there are only two states, either ON
or OFF. In Arduino sketch terms, an ON state is known as HIGH (5V) and OFF state is
known as LOW (0V).
PINMode (): This command configures the specified pin to behave either as an input or an
output.
• If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set
to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for
LOW.
• If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable
(LOW) the internal pull-up on the input pin. It is recommended to set the pinMode()
to INPUT_PULLUP to enable the internal pull-up resistor
DigitalRead(): This command reads the value from a specified digital pin, either HIGH or
LOW .
Syntax: digitalRead(pin)
Sample Program:
Serial Monitor
The Arduino IDE has a feature that can be of a great help in debugging sketches or controlling
Arduino from your computer's keyboard. It displays serial data being sent from Arduino UNO
(USB or serial board).
1. Connect Arduino UNO board by USB to your computer to activate the Serial Monitor.
2. To get familiar with using the Serial Monitor, Write the following Sketch into a blank
Arduino IDE window.
3. Then verify it and if it's OK, Upload it.
4. Click on Serial Monitor icon at right corner
5. A pop-up in a new window
6. Look at the Serial Monitor window.
a. The small upper box is where you can type characters (hit or click "Send")
Arduino will be displayed.
b. The larger area (corner can be dragged to enlarge) is where character sent from
Arduino will be displayed
c. At the bottom are two pull-downs:
i. One sets the "line ending" that will be sent to Arduino when you or click
Send
ii. The other set the Baud Rate (9600) for communications. (If this does not
match the value set up in your sketch in Setup, characters will be
unreadable).
SETUP: In Setup you need to begin Serial Communications and set the Baud Rate (speed) that
data will be transferred at. That looks like this:
LOOP: Here we can use the following commands to send data serially & configure it to the
Serial Monitor.
Examples:
serial.availabe(): This command is use to get the number of bytes (characters) available for
reading from the serial port.
serial.flush() :
This command is used to wait for the transmission of outgoing serial data to complete.
serial.print(data):
This command prints data to the serial port as human-readable ASCII text.
serial.read():
This command is used to reads incoming serial data.
Sample Sketch:
After doing LAB # 1, write a report according to the following. The report should be
concise and not more than 2/3 pages. The report must be submitted in hard-copies as well
as uploaded on the blackboard.
Note: Don’t forget to mention your Name, Student ID, Course Code, Course Name, Section,
and Department/Program. The report must be neat, clear and computer generated in either pdf
or word.
Thank you 😊