Iot Devanshi
Iot Devanshi
Practical: 1
• USB (used for uploading sketches to the board and for serial communication between the board and
the computer; can be used to power the board) (yellow)
• Arduino 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 Genuino hardware to upload programs and communicate
with them.
• Writing Sketches
1. File
2. Edit
3. Sketch
4. Tools
5. Help
• Sketchbook
• Tabs, Multiple Files, and Compilation
• Uploading
• Libraries
• Third-Party Hardware
• Serial Monitor
• Preferences
• Language Support
• Boards
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 also 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.
Sketchbook:
The Arduino Software (IDE) uses the concept of a sketchbook: a standard place to store your programs
2
IOT 210820107015
(or sketches). The sketches in your sketchbook can be opened from the File >Sketchbook menu or from
the Open button on the toolbar. The first time you run the Arduino software, it will automatically create a
directory for your sketchbook. You can view or change the location of the sketchbook location from with
the Preferences dialog. Beginning with version 1.0, files are saved with a.ino file extension. Previous
versions use the .pde extension. You may still open .pde named files in version 1.0 and later, the
software will automatically rename the extension to .ino.
Uploading:
Before uploading your sketch, you need to select the correct items from the Tools > Board and
Tools > Port menus. The boards are described below. On the Mac, the serial port is probably
something like
/dev/tty.usbmodem241 (for an Uno or Mega2560 or Leonardo) or
/dev/tty.usbserial-1B1 (for a Duemilanove or earlier USB board), or /dev/tty.USA19QW1b1P1.1
(for a serial board connected with a Keyspan USB-to-Serial adapter).
On Windows, it's probably COM1 or COM2 (for a serial board) or COM4, COM5, COM7, or
higher (for a USB board) - to find out, you look for USB serial device in the ports section of the
Windows Device Manager. On Linux, it should be
/dev/ttyACMx , /dev/ttyUSBx or similar.
Once you've selected the correct serial port and board, press the upload button in the toolbar or
select the Upload item from the File menu.
Current Arduino boards will reset automatically and begin the upload. With older boards (pre-
Diecimila) that lack auto-reset, you'll need to press the reset button on the board just before starting the
upload. On most boards, you'll see the RX and TX LEDs blink as the sketch is uploaded. The Arduino
Software (IDE) will displaya message when the upload is complete, or show an error. When you upload
a sketch, you're using the Arduino boot loader, a small program that has been loaded on to the
microcontroller on your board. It allows you to upload code without using any additional hardware. The
boot loader is active for a few seconds when the board resets; then it starts whichever sketch was most
recently uploaded to the microcontroller. The boot loader will blink the on-board (pin 13) LED when it
starts (i.e. when the boardresets).
Libraries:
Libraries provide extra functionality for use in sketches, e.g. working with hardware or manipulating
data. To use a library in a sketch, select it from the Sketch > Import Library menu. This will insert one or
more #include statements at the top of the sketch and compile the library with your sketch. Because
3
IOT 210820107015
libraries are
4
IOT 210820107015
uploaded to the board with your sketch, they increase the amount of space it takes up. If a sketch no
longer needs a library, simply delete its #include statements from the top of your code.
There is a list of libraries in the reference. Some libraries are included with the Arduino software.
Others can be downloaded from a variety of sources or through the Library Manager. Starting with
version 1.0.5 of the IDE, you do can import a library from a zip file and use it in an open sketch. See
these instructionsfor installing a third-party library.
Third-Party Hardware:
Support for third-party hardware can be added to the hardware directory of your sketch book directory.
Platforms installed there may include board definitions (which appear in the board menu), core libraries,
boot loaders, and programmer definitions. To install, create the hardware directory, then unzip the third
party platform into its own sub-directory. (Don't use "arduino" as the sub-directory name or you'll
override the built-in Arduino platform.) To uninstall, simply delete its directory.
Serial Monitor
Displays serial data being sent from the Arduino board. To senddata 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. Note that onWindows, Mac or Linux, the Arduino or Genuino board will
reset when you connect with the serial monitor.
Preferences:
Some preferences can be set in the preferences dialog (found under the Arduino menu on the Mac, or
Fileon Windows and Linux). The rest can be found in the preferences file, whose location is shown in
the preference dialog.
Language Support:
Since version 1.0.1, the Arduino Software (IDE) has been translated into 30+ different languages. By
default, the IDE loads in the language selected by your operating system. (Note: on Windows and
possibly Linux, this is determined by the locale setting which controls currency and date formats, not by
the language the operating system is displayed in.) If you would like to change the language manually,
start the Arduino Software (IDE) and open the Preferences window. Next to the Editor Language there is
a dropdown menu of currently supported languages. Select your preferred language from the menu, and
restart the software to use the selected language. If your operating system language is not supported, the
Arduino Software (IDE) will default to English.
Boards:
The board selection has two effects: it sets the parameters (e.g. CPU speed and baud rate) used when
compiling and uploading sketches; and sets and the file and fuse settings used by the burn boot loader
command. Some of the board definitions differ only in the latter, so even if you've been uploading
successfully with a particular selection you'll want to check it before burning the boot loader.
- Arduino/Genuino Uno: An ATmega328 running at 16 MHz with auto-reset, 6 Analog In, 14 Digital
I/O and 6 PWM.
- Arduino Mega: An ATmega1280 running at 16 MHz with auto-reset, 16 Analog In, 54 Digital I/O and
5
IOT 210820107015
15 PWM.
- Arduino Micro: An ATmega32u4 running at 16 MHz with auto-reset, 12 Analog In, 20 Digital I/O
and 7 PWM.
Arduino Cables:
Arduino is great but sometimes connecting interesting things to it can be a pain. Here are some things
that may make it easier for you. Here are some of the cables and pins that are available, and below we'll
show you how to use them for many different applications.
cable.
Compatible with most Arduino boards such as Arduino Mega, Romeo, and Arduino Duemilanove.
Often used for printers and other peripherals. While still a little bulky in shape for small embedded
systems, thisis a standard cable found everywhere. Use this cable with Arduino UNO and others, but not
for ArduinoLeonardo based boards may come in White or Black.
6
IOT 210820107015
Practical: 2
Interface LED / Buzzer with Arduino Uno and write a program to turn ON LED for 1sec after every
2 seconds.
Hardware Required:
• Arduino or Genuino Board
• LED
• 220 ohm resistor
Circuit:
To build the circuit, connect one end of the resistor to Arduino pin 13. Connect the long leg of the LED
(the positive leg, called the anode) to the other end of the resistor. Connect the short leg of the LED (the
negative leg,called the cathode) to the Arduino GND, as shown in the diagram and the schematic below.
Most Arduino boards already have an LED attached to pin 13 on the board itself. If you run this example
with nohardware attached, you should see that LED blinks.
The value of the resistor in series with the LED may be of a different value than 220 ohm; the LED will lit
up also with values up to 1K ohm.
7
IOT 210820107015
Code:
After you build the circuit plug your Arduino or Genuino board into your computer, start the Arduino
Software (IDE) and enter the code below. You may also load it from the menu File/Examples/01.Basics/Blink .
The first thing you do is to initialize pin 13 as an output pin with the Line
pinMode(13, OUTPUT);
In the main loop, you turn the LED on with the line:
digitalWrite(13, HIGH);
This supplies 5 volts to pin 13. That creates a voltage difference across the pins of the LED, and lights
it up.Then you turn it off with the line:
digitalWrite(13, LOW);
That takes pin 13 back to 0 volts, and turns the LED off. In between the on and the off, you want enough time
for a person to see the change, so the delay() commands tell the board to do nothing for 1000 milliseconds, or
one second. When you use the delay() command, nothing else happens for that amount of time.
// the setup function runs once when you press reset or power the board
void setup()
{ // initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
8
IOT 210820107015
Practical 3
Interface Push button/Digital sensor (IR/LDR) with Arduino Uno and write a program to turn ON
LED when push button is pressed or at sensor detection
Circuit:
Code:
int buttonState=0;
void setup()
{
pinMode(11, OUTPUT);
pinMode(4, INPUT);
}
Void loop()
9
IOT 210820107015
} else{
delay(5);
10
IOT 210820107015
Practical 4
To interface TMP36 sensor with Arduino Uno and write a program to print temperatureand
humidity readings
Circuit:
Code:
11
IOT 210820107015
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void loop() {
// set threshold temperature to activate LEDsbaselineTemp
= 40;
// measure temperature in Celsius
celsius = map(((analogRead(A1) - 20) * 3.04), 0, 1023, -40, 125);
// convert to Fahrenheit
fahrenheit = ((celsius * 9) / 5 + 32);
Serial.print(celsius);
Serial.print(" C, ");
Serial.print(fahrenheit);
Serial.println(" F");
if (celsius < baselineTemp)
{ digitalWrite(5, LOW);
digitalWrite(6, LOW); digitalWrite(7,
LOW);
}
if (celsius >= baselineTemp && celsius < baselineTemp + 10)
{ digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
}
if (celsius >= baselineTemp + 10 && celsius < baselineTemp + 20)
{ digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
}
if (celsius >= baselineTemp + 20 && celsius < baselineTemp + 30)
{ digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
}
if (celsius >= baselineTemp + 30)
{ digitalWrite(5, HIGH);
digitalWrite(6, HIGH); digitalWrite(7,
HIGH);
}
delay(10); // Wait for 1000 millisecond(s)
12
IOT 210820107015
13
IOT 210820107015
14
IOT 210820107015
Practical 5
Interface motor using relay with Arduino Uno and write a program to turn ON motorwhen push button
is pressed
Code:
int buttonState = 0;
int sensorValue = 0;
void setup()
{
pinMode(2, INPUT);
pinMode(A0, INPUT);
Serial.begin(9600);
}
void loop()
{
15
IOT 210820107015
16
IOT 210820107015
Practical 6
Perform Experiment using Arduino Uno to measure the distance of any object usingUltrasonic Sensor.
Circuit of Ultrasonic Sensor:
Code:
/*
Ping))) Sensor
This sketch reads a PING))) ultrasonic rangefinder and returns the distance to the closestobject in
range. To do this, it sends a pulse to the sensor to initiate a reading, and then listens for a pulse to
return. The length of the returning pulse is proportional to the distance of the object from the
sensor. The circuit:
* +V connection of the PING))) attached to +5V
* GND connection attached to ground
* SIG connection attached to digital pin 7
*/
int inches = 0;
int cm=0;
17
IOT 210820107015
Shadow:
18
IOT 210820107015
19
IOT 210820107015
Practical 7
Circuit of Potentiometer:
Code:
int sensorValue = 0;
void setup()
{
pinMode(A0, INPUT);
pinMode(13, OUTPUT);
}
void loop()
{
// read the value from the sensor
sensorValue = analogRead(A0);
20
IOT 210820107015
21
IOT 210820107015
Circuit of Photoregister:
Code:
int sensorValue = 0;
void setup()
{
pinMode(A0, INPUT);
pinMode(9, OUTPUT);
Serial.begin(9600);
}
void loop()
{
23
IOT 210820107015
Practical 8
Circuit:
Code:
#include <Adafruit_NeoPixel.h>
// To add the NeoPixel library, which opens up a new set of commands we for controlling ourNeoPixel
ring. #define PIN 9
#define NUMPIXELS 24
int delayval = 50; int
currentColor = 0;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB +
NEO_KHZ800);
void setup()
{
pixels.begin(); // This initializes the NeoPixel lib
pixels.setBrightness(100);
pixels.show();
}
void loop()
{
24
IOT 210820107015
25
IOT 210820107015
Practical 9
Circuit:
Code:
int sensorState = 0;
void setup()
{
pinMode(2, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop()
{
// read the state of the sensor/digital inputsensorState =
digitalRead(2);
26
IOT 210820107015
LED blinked when High Value (Inside the LED not blink when Low Value (Outside
Shadow area) the Shadow area)
27
IOT 210820107015
Practical 10
An Introduction to Raspberry Pi
Introduction
Raspberry Pi is a series of low-cost single-board computers which comes with built-in features such as
WIFI andBluetooth and some USB and HDMI ports. We can connect a display, USB keyboard and mouse to the
system. These mini-computers are highly flexible in the areas where they can be used such as embedded system,
weather reports and small security system. It is highly recommended for beginners to explore this excellent
device to be able to do projects like WIFI Hacker, AD-Blocker and a working server that has some practical
relevance!!
This is Raspberry Pi 4 Model B:
This document is divided into three sections as per the relevance of the project and need. The subsections are as
follows:
28
IOT 210820107015
Prerequisites
Few prerequisites are:
1. A functional Raspberry Pi
4. A working computer
6. Internet
A step by step procedure of process which tells you how to get started with Raspberry Pi is in this Link:
https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up
1. Head over to below link to download the Full Version of Raspbian OS (This should be around 2.4 GB).
• Windows
• macOS
• Ubuntu
2. Open Raspberry Pi Imager and select the SD card with CHOOSE SD CARD option. Select the SD
29
IOT 210820107015
3. Go to CHOOSE OS option. Select Use Custom option. A dialog box will appear. Navigate to the
zip file of NOOBS which was downloaded.
5. When prompted as done, safely eject the SD card from the reader.
1. Insert power adaptor and Ethernet cable to Raspberry Pi and Laptop. Power on the device. An
Unidentified Network should appear as Local Area Connection.
2. Connect the keyboard, mouse, and HDMI display if you want. Remember that the external screen
only needed to run the Pi for the first time.
3. Click on it and select Properties and select Internet Protocol Version 4. Note the IP Address
shown. The IP settings, in general, are as follows.
Name : raspberrypi
IP : 192.168.43.X {where X varies from system to system}Note down all the details.
1. Turn Off your Pi device and take out the SD card to plug it back to your computer to create a blank
file to turn on SSH.
2. Note the drive letter of SD card on the computer. Open cmd and type the following command, where
K is your drive letter. This enables SSH in your device on start-up.
30
IOT 210820107015
echo>K:\ssh
NOTE: Download putty.exe file under Alternate Binary Files 64-bit or 32-bit and Standalone 64-bit for
VNC viewer.
2. Open PuTTy and follow the steps below
SELECT THE SSH OPTION FROM OPTIONS AND SET PORT TO 22 WRITE
THE IP OF YOUR RASPBERRY PI WHICH WAS NOTED EARLIER
3. Click OK to connect to Raspberry Pi via SSH.
Username : pi
Password : raspberry
5. Once you are connected to Raspberry Pi via SSH, follow the procedure below in shell. These settings
help you to connect to the device via SSH and VNC.
v. Goto Finish.
5. Close Putty and open VNC viewer. Enter the IP address of Raspberry Pi in the top search option and
press enter.
31
IOT 210820107015
GPIO Programming
GPIO, or General-Purpose Input / Output, is a feature in most modern embedded computer hardware and a
crucial part of many embedded systems.
These pins are used with digital data which is typically referred to as High voltage and Low voltage.
Variousdiscrete levels of voltages cannot be used with these pins.
GPIO programming is usually done with Python using RPi. GPIO which can be installed via terminal.
32
IOT 210820107015
Foot Note
For Linux and macOS, connecting is even easier. Just use Advanced IP Scanner/Nmap or any tool you
wish to scan for Raspberry Pi and use the following command.
ssh pi@<IP>
33
IOT 210820107015
Practical 11
Win32 disk:
Procedure:
Step 2 : Insert SD Card into pc/laptop (system on which OS and win32disk is downloaded).
Make sure that SD card is empty and have atleast 4GB memory.
Step 3 : Open win32 disk. The UI view of it is shown in fig-
2.1. Step 4 : Browse the image file which has downloaded .
Step 5: Click on “write”.
Step 6: When writing is complete, remove the SD card and insert it into the raspberry pi.
Step7: ON the power of raspberry pi. Blinking Status of green LED shows that booting has
started.
References:
1. http://androidpi.wikia.com/wiki/Android_Pi_Wiki
34