IOT Lab Manual
IOT Lab Manual
LAB MANUAL
Semester II
ZEAL EDUCATION SOCIETY’S
ZEAL COLLEGE OF ENGINEERING & RESEARCH
DEPARTMENT OF ARTIFICIAL INTELLIGENCE & DATA SCIENCE
Sr.no. 39, Narhe, Pune-41. phone no. 020-67206127
Website:www.zcoer.in
Vision:
To produce competent artificial intelligence and data science professionals to serve the
needs of the society.
Mission:
LAB MANUAL
PART-I
Group B
5 Write a program using Arduino to control LED (One or more
ON/OFF). Or Blinking
6 Create a program that illuminates the green LED if the counter is
less than 100, illuminates the yellow LED if the counter is between
101 and 200 and illuminates the red LED if the counter is greater
than 200
7 Create a program so that when the user enters ‘b’ the green light
blinks, ‘g’ the green light is illuminated ‘y’ the yellow light is
illuminated and ‘r’ the red light is illuminated
8 Write a program that asks the user for a number and outputs the
number squared that is entered
9 Write a program to control the color of the LED by turning 3
different potentiometers. One will be read for the value of Red, one
for the value of Green, and one for the value of Blue
10 Write a program read the temperature sensor and send the values to
the serial monitor on the computer
11 Write a program so it displays the temperature in Fahrenheit as well
as the maximum and minimum temperatures it has seen
12 Write a program to show the temperature and shows a graph of the
recent measurements
13 Write a program using piezo element and use it to play a tune after
someone knocks
14 Understanding the connectivity of Raspberry-Pi /Beagle board
circuit / Arduino with IR sensor. Write an application to detect
obstacle and notify user using LEDs
Group C
15 Study of ThingSpeak – an API and Web
Service for the Internet of Things (Mini
Project: Same can be done parallel with PBL)
16 Write an application to control the operation of hardware simulated traffic
signals. (Mini Project: Same can be done parallel with PBL)
Aim: Study of Raspberry-Pi/ Beagle board/ Arduino and other microcontroller (History
& Elevation)
Outcome: At end of this experiment, student will be able to study of different microcontrollers
like Raspberry-Pi/ Beagle board/ Arduino
Theory:
Internet of Things: - IoT is short for Internet of Things. The Internet of Things refers to the
evergrowing network of physical objects that feature an IP address for internet connectivity,
and the communication that occurs between these objects and other Internet-enabled devices
and systems. The Internet of Things (IoT) refers to the use of intelligently connected devices
and systems to leverage data gathered by embedded sensors and actuators in machines and
other physical objects. In other words, the IoT (Internet of Things) can be called to any of the
physical objects connected with network.
Examples of IoT: -
1) Apple Watch and Home Kit.
2) Smart Refrigerator.
3) Smart Refrigerator.
4) Smart cars.
5) Google Glass.
6) Smart thermostats.
Digital Pins
In addition to the specific functions listed below, the digital pins on an Arduino board can be
used for general purpose input and output via the pinMode(), digitalRead(), and
digitalWrite() commands. Each pin has an internal pull-up resistor which can be turned on
and off using digitalWrite() (w/ a value of HIGH or LOW, respectively) when the pin is
configured as an input. The maximum current per pin is 40 mA.
Analog Pins
In addition to the specific functions listed below, the analog input pins support 10-bit
analog-to-digital conversion (ADC) using the analogRead() function. Most of the analog
inputs can also be used as digital pins: analog input 0 as digital pin 14 through analog input 5
as digital pin 19. Analog inputs 6 and 7 (present on the Mini and BT) cannot be used as digital
pins.
Power Pins
∙ VIN (sometimes labelled "9V"). The input voltage to the Arduino board when it's using an external
power source (as opposed to 5 volts from the USB connection or other regulated power source). You
can supply voltage through this pin, or, if supplying voltage via the power jack, access it through this
pin. Note that different boards accept different input voltages ranges, please see the documentation
for your board. Also note that the LilyPad has no VIN pin and accepts only a regulated input.
Other Pins
∙ AREF. Reference voltage for the analog inputs. Used with analogReference().
∙ Reset. (Diecimila-only) Bring this line LOW to reset the microcontroller. Typically used to add a reset
button to shields which block the one on the board. ∙ Analog Reference pin (orange) ∙ Digital Ground
(light green)
∙ Digital Pins 2-13 (green)
∙ Digital Pins 0-1/Serial In/Out - TX/RX (dark green) - These pins cannot be used for digital i/o
(digitalRead and digitalWrite) if you are also using serial communication (e.g. Serial.begin).
∙ Reset Button - S1 (dark blue)
∙ In-circuit Serial Programmer (blue-green)
∙ Analog In Pins 0-5 (light blue)
∙ Power and Ground Pins (power: orange, grounds: light orange)
∙ External Power Supply In (9-12VDC) - X1 (pink)
∙ Toggles External Power and USB Power (place jumper on two pins closest to desired supply) -SV1
(purple)
∙ USB (used for uploading sketches to the board and for serial communication between theboard
and the computer; can be used to power the board) (yellow)
● Theory:
1) Raspberry-Pi: - The Pi can run the official Raspbian OS, Ubuntu Mate, Snappy Ubuntu
Core, the Kodi- based media centers OSMC and LibreElec, the non-Linux based Risc OS
(one for fans of 1990s Acorn computers). It can also run Windows
10 IoT Core, which is very different to the desktop version of Windows, as mentioned
below.
● OS which install on Raspberry-Pi: Raspbian, Ubuntu MATE, Snappy Ubuntu, Pidora,
Linutop, SARPi, Arch Linux ARM, Gentoo Linux, etc.
Step 2: Unzip the file. The Raspbian disc image is compressed, so you’ll need to unzip
it. The file uses the ZIP64 format, so depending on how current your built-in utilities
Step 3: Write the disc image to your microSD card. Next, pop your microSD card into
your computer and write the disc image to it. The process of actually writing the image
will be slightly different across these programs, but it’s pretty self-explanatory no
matter what you’re using. Each of these programs will have you
select the destination (make sure you’ve picked your microSD card!) and the disc image
(the unzipped Raspbian file). Choose, double-check, and then hit the button to write.
Step 4: Put the microSD card in your Pi and boot up. Once the disc image has been
written to the microSD card, you’re ready to go! Put that sucker into your Raspberry Pi,
plug in the peripherals and power source, and enjoy. The current edition to Raspbian
will boot directly to the desktop. Your default credentials are username pi and password
raspberry.
2) BeagleBone Black: - The BeagleBone Black includes a 2GB or 4GB on-board eMMC
flash memory chip. It comes with the Debian distribution factory pre-installed. You can
flash new operating systems including Angstrom, Ubuntu, Android, and others.
Step 3: Insert your MicroSD (uSD) card into the proper slot. Most uSD cards come
with a full-sized SD card that is really just an adapter. If this is what you have then
insert the uSD into the adapter, then into your card reader.
Step 4: Now open Win32 Disk imager, click the blue folder icon, navigate to the
debian img location, and double click the file. Now click Write and let the process
complete. Depending on your processor and available RAM it should be done in
around 5 minutes.
Step 5: Alright, once that's done, you'll get a notification pop-up. Now we're ready to
get going. Remove the SD adapter from the card slot, remove the uSD card from the
adapter. With the USB cable disconnected insert the uSD into the BBB.
Step 6: Now, this next part is pretty straight forward. Plug the USB cable in and
wait some more. If everything is going right you will notice that the four (4) leds
just above the USB cable are doing the KIT impression. This could take up to 45
minutes; I just did it again in around 5 minutes. Your mileage will vary. Go back
and surf reddit some more.
Step 7: If you are not seeing the leds swing back and forth you will need to unplug
the USB cable, press and hold down the user button above the uSD card slot (next
to the 2 little 10 pin ICs) then plug in the USB cable. Release the button and wait.
You should see the LEDs swinging back and forth after a few seconds. Once this
happens it's waiting time. When all 4 LEDs next to the USB slot stay lit at the same
time the flash process has been completed.
Step 8: Remove the uSD card and reboot your BBB. You can reboot the BBB by
removing and reconnecting the USB cable, or hitting the reset button above the
USB cable near the edge of the board.
Step 9: Now using putty, or your SSH flavor of choice, connect to the BBB
using the IP address 192.168.7.2. You'll be prompted for a username. Type root and
press Enter. By default, there is no root password. I recommend changing this
ASAP if you plan on putting your BBB on the network. To do this type password,
hit enter, then enter your desired password. You will be prompted to enter it again
to verify.
3) Arduino: - The Arduino itself has no real operating system. You develop code for
the Arduino using the Arduino IDE which you can download from Arduino - Home.
Versions are available for Windows, Mac and Linux. The Arduino is a constrained
microcontroller. Arduino consists of both a physical programmable circuit board
(often referred to as a microcontroller) and a piece of software, or IDE (Integrated
Development Environment) that runs on your computer, used to write and upload
computer code to the physical board. You are literally writing the "firmware" when
you write the code and upload it. It's both good and its bad.
Conclusion: Here studied different operating systems for platforms such as Raspberry-Pi/ Beagle
board/Arduino
EXPERIMENT NO. 3 (Group A)
Aim: Study of different GATES (AND, OR, XOR), Sensors and basic binary operations.
Outcome: To study different GATES (AND, OR, XOR), Sensors
Theory:
A logic gate is a device that acts as a building block for digital circuits. They perform
basic logical functions that are fundamental to digital circuits. Most electronic devices
we use today will have some form of logic gates in them. For example, logic gates can
be used in technologies such as smartphones, tablets or within memory devices.
In a circuit, logic gates will make decisions based on a combination of digital signals
coming from its inputs. Most logic gates have two inputs and one output. Logic
gates are based on Boolean algebra. At any given moment, every terminal
is in one of the two binary conditions, false or true. False represents 0, and true
represents 1. Depending on the type of logic gate being used and the combination of
inputs, the binary output will differ. A logic gate can be thought of like a light switch,
wherein one position the output is off -- 0, and in another, it is on -- 1. Logic gates are
commonly used in integrated circuits (IC).
AND gate
Input 1 Input 2 Outpu
t
1
1
1 1 1
The OR gate gets its name from the fact that it behaves after the fashion of the logical
inclusive "or." The output is "true" if either or both of the inputs are "true." If both
inputs are "false," then the output is "false." In other words, for the output to be 1, at
least input one OR two must be 1.
OR gate
1 1
1 1
1 1 1
The XOR ( exclusive-OR ) gate acts in the same way as the logical "either/or." The
output is "true" if either, but not both, of the inputs are "true." The output is "false" if
both inputs are "false" or if both inputs are "true." Another way of looking at this
circuit is to observe that the output is 1 if the inputs are different, but 0 if the inputs are
the same.
XOR gate
Input 1 Input 2 Outpu t
A logical inverter,
sometimes 1 1 called a NOT
gate to 1 1 differentiate it
from other 1 1 types of
electronic inverter devices,
has only one input. It reverses the logic state. If the input is 1, then the output is 0. If
the input is 0, then the output is 1.
NAND gate
Input 1 Input 2 Outpu
t
1
1 1
1 1
1 1
The NOR gate is a combination OR gate followed by an inverter. Its output is "true" if
both inputs are "false." Otherwise, the output is "false."
NOR gate
Input 1 Input 2 Outpu
t
1
1
1
1 1
XNOR gate
Input 1 Input 2 Outpu
t
1
1
1
1 1 1
Complex operations can be performed using combinations of these logic gates. In
theory, there is no limit to the number of gates that can be arrayed together in a single
device. But in practice, there is a limit to the number of gates that can be packed into a
given physical space. Arrays of logic gates are found in digital ICs. As IC technology
advances, the required physical volume for each individual logic gate decreases and
digital devices of the same or smaller size become capable of performing ever-more-
complicated operations at ever-increasing speeds.
Composition of logic gates
High or low binary conditions are represented by different voltage levels. The logic
state of a terminal can, and generally does, often change as the circuit processes data.
In most logic gates, the low state is approximately zero volts (0 V), while the high
state is approximately five volts positive (+5 V).
Logic gates can be made of resistors and transistors or diodes. A resistor can
commonly be used as a pull-up or pull-down resistor. Pull-up and pull-down resistors
are used when there are any unused logic gate inputs to connect to a logic level 1 or
0. This prevents any false
switching of the gate. Pull-up resistors are connected to Vcc (+5V), and pull-down
resistors are connected to ground (0 V).
Commonly used logic gates are TTL and CMOS. TTL, or Transistor-Transistor Logic,
ICs will use NPN and PNP type Bipolar Junction Transistors. CMOS, or
Complementary Metal-Oxide-Silicon, ICs are constructed from MOSFET or JFET type
Field Effect Transistors. TTL IC's may commonly be labeled as the 7400 series of
chips, while CMOS ICs may often be marked as a 4000 series of chips.
Types of Sensors
There are many different types of sensors. Here at Variohm, we offer a full range of
sensors for industrial and commercial use.
Sensors are used throughout almost every industry for applications which we come into
contact with on a daily basis as well as more industrial and specialist applications.
Sensors can be found in the home, the office, in our cars, buses, trains, trams, computers,
medical facilities, labs, power plants, restaurants, food processing factories, production
lines etc A Sensor is used to take a measurement, the measurement will be processed and
the result of the process, an output will be given. The output will then cause something to
change or move. A simple example is the temperature sensor in a thermostat. The
temperature sensor is constantly monitoring the temperature, once the measurement taken
reaches the desired temperature, the measurement is processed and the output causes the
boiler to switch off.
Types of Sensors
There are many different types of sensors, the main categories are;
● Position Sensors
● Pressure Sensors
● Temperature Sensors
● Force Sensors
● Vibration Sensors
● Piezo Sensors
● Fluid Property Sensors
● Humidity Sensors
● Strain gauges
● Photo Optic Sensors
● Flow and Level Switches
These categories can all be split further into subcategories for example, within position
sensors there are the following types;
● Contacting
● Non-contacting
● Rotary
● Linear
And these types of sensors can be split even further, within non-contacting you have the
following types of sensors;
● Hall effect
● Capacitive
● Eddy Current
● Ultrasonic
● Laser
● Proximity
By splitting one category – Position Sensors it is clear to see that the number of sensors
present in today’s world is so vast that one blog post could not cover every type of sensor.
However, here is an overview of different types of sensors Variohm can offer.
●
● Aim: Study of Connectivity and configuration of Raspberry-Pi /Beagle board/Arduinocircuit
with basic peripherals like LEDS. Understanding GPIO and its use in the program.
Theory:
Connecting Hardware Peripherals to Raspberry-Pi board. Raspberry-Pi setup through SSH (Headless
Configuration of Raspberry-Pi-3 (VNC, Putti))
After this, make sure that the networking connection is changed to “Local Area Connection”
Now, to check the IP assigned to the network established, click on the new local area connection link
created:
Enter the 8 digit password which was entered in the VNC server installation on your Raspberry Pi:
Finally, the Raspberry Pi desktop should appear as a VNC window.
You will be able to access the GUI and do everything as if you are using the Pi’s keyboard, mouse,
and monitor directly.
Most modern television sets and monitors have an HDMI port, and are the easiest to get working with
the Raspberry Pi.
You can use an HDMI cable to connect the Raspberry Pi directly to the television or monitor.
VGA
Some old monitors have a VGA port.
These can be trickier to use as you'll need an HDMI-to-VGA converter, which can change digital
video to analogue video.
A simple port adapter won't work.
Power supplies
For Raspberry Pi 3, it's recommended to use a 5V, 2.5A power
supply. Mobile device charger
Many mobile devices are powered using a 5V micro USB charger.
These can often be used to power the Raspberry Pi, although it's worth checking that they provide
sufficient voltage and current (5V / 1.2 - 2.5A).
The below table summarizes the pinout of Raspberry-Pi in both the number systems.
import time
Set numbering scheme to be used. The method used for this is GPIO.setmode(). We will
use physical number scheme. So the method is written as
GPIO.setmode(GPIO.BOAD)
Set the pin mode as INPUT or OUTPUT using the commands GPIO.setup(channel, GPIO.IN)
GPIO.setup(channel, GPIO.OUT)
Read input using following command
GPIO.input(pin no)
Write output using following comman
GPIO.output(pin no, state)
Give delay using command using following command time.sleep(1) # delay for 1
second Clean up GPIO and exit using following commands GPIO.cleanup()
print(“Exiting...”)
You must clean up the pin set-ups before your program exits otherwise those pin settings will
persist, and that might cause trouble when you use the same pins in another program.
The Pi ‘expresses its displeasure’ with a warning.
To clean up the entire set of pins, invoke GPIO.cleanup().
If you want only a few pins to be cleaned up, then the pin numbers should be provided
as GPIO.cleanup (channel_list).
Anyway, you can suppress the warning messages by calling GPIO.setwarnings
(False). Save the program with proper name. The file is saved with extension ‘.py’.
The IDE named ‘IDLE’ used for programming is an interpreter and not a compiler. So to run
the python program, we need to give the super user permission as follows.
Studying Connectivity and Configuration of Raspberry Pi board with basic peripherals (LEDs)
Aim/Objectives:
To understand the concept of Led bar
To understand the common anode & common cathode configuration.
To interface LED bar with Raspberry Pi.
Generate various patterns on LED bar.
Software: Raspbian OS , IDLE editor
Hardware Modules: Raspberry Pi Board, LED bar, Monitor
Introduction to “LED”
LED is a Light Emitting Diode. Light emitting diode is a two lead semiconductor light source. It is a
p-n junction diode, which emits light when it is activated. When a suitable voltage is applied to the
leads, electrons are able to recombine with electron holes within the device, and the color of light
(corresponding to the energy of photon) is determined by the energy band gap of the semiconductor.
It has two terminals named as ‘anode (+ve)’ and ‘cathode (-ve)’. Battery is connected to these two
terminals. When LED is forward biased, it emits light. In LED bar number of LEDs are connected in
series (in our case 8 LEDs are connected) LED bar has two configurations as Common Anode: In this,
anode terminal of all the LEDs are made common and connected to the VCC (+5v). By controlling
cathode terminal we can make LED ON or OFF (current sourcing). Common Cathode: In this,
cathode terminal of all the LEDs are made common and connected to the Ground (0v). By controlling
anode terminal we can make LED ON or OFF (current sinking).
Safety precautions:
Raspberry-Pi provides 3.3V and 5V VCC
pins Raspberry-Pi operates on 3.3V.
Various sensors and actuators operate on different voltages.
Read datasheet of a given sensor or an actuator and then use appropriate VCC pin to connect
a sensor or an actuator.
Ensure that signal voltage coming to the Raspberry-Pi from any sensor or actuator does not
exceed 3.3V.
If signal/data coming to Raspberry-Pi is greater than 3.3V then use voltage level shifter
module to decrease the incoming voltage.
The Raspberry-Pi is a costly device, hence you should show the circuit connections to
your instructor before starting your experiment.
Interface diagram:
Connect led bar module pins from D0- D3 to Raspberry Pi GPIO pins 7, 11, 13, 15
respectively. Connect led bar module pin COM to the GND pin of Raspberry-Pi module.
Procedure:
Conclusion:We have implemented this experiment using LED glowing with Arduino IDE and arduino board and
LED
Questions:
Aim: Write a program using Arduino to control LED (One or more ON/OFF). Or Blinking
Theory:
This example shows the simplest thing you can do with an Arduino to see physical output: it
blinks the on-board LED.
This example uses the built-in LED that most Arduino boards have. This LED is connected to
a digital pin and its number may vary from board type to board type. To make your life
easier, we have a constant that is specified in every board descriptor file. This constant is
LED_BUILTIN and allows you to control the built-in LED easily. Here is the correspondence
between the constant and the digital pin.
● D13 - 101
● D13 - Due
● D1 - Gemma
● D13 - Intel Edison
● D13 - Intel Galileo Gen2
● D13 - Leonardo and Micro
● D13 - LilyPad
● D13 - LilyPad USB
● D13 - MEGA2560
● D13 - Mini
● D6 - MKR1000
● D13 - Nano
● D13 - Pro
● D13 - Pro Mini
● D13 - UNO
● D13 - Yún
● D13 - Zero
If you want to lit an external LED with this sketch, you need to build this circuit, where you
connect one end of the resistor to the digital pin correspondent to the LED_BUILTIN
constant. 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
GND. In the diagram below we show an UNO board that has D13 as the LED_BUILTIN
value.
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.
// C++ code
//
void setup()
pinMode(LED_BUILTIN, OUTPUT);
void loop()
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(LED_BUILTIN, LOW);
}
Schematic
Code
After you build the circuit plug your Arduino 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 LED_BUILTIN pin as
an output pin with the line
pinMode(LED_BUILTIN, OUTPUT);
In the main loop, you turn the LED on with the line:
digitalWrite(LED_BUILTIN, HIGH);
This supplies 5 volts to the LED anode. That creates a voltage difference across the pins of the
LED, and lights it up. Then you turn it off with the line:
digitalWrite(LED_BUILTIN, LOW);
That takes the LED_BUILTIN pin 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. Once you've understood the basic
examples, check out the BlinkWithoutDelay example to learn how to create a delay while
doing other things.
Once you've understood this example, check out the DigitalReadSerial example to learn how
read a switch connected to the board.
Conclusion: -
EXPERIMENT NO. 6 (Group B)
Aim: Create a program that illuminates the green LED if the counter is less than
100, illuminates the yellow LED if the counter is between 101 and 200 and
illuminates the red LED if the counter is greater than 200
Outcome: Connectivity, configuration and control of LED using Arduino circuit under
different conditions.
Theory:
The problem statement is like Arduino traffic light, a fun little project that you can build in
under an hour. Here's how to build your own using an Arduino, and how to change
the circuit for an advanced variation.
● 1 x 10k-ohm resistor
● 1 x pushbutton switch
● 6 x 220-ohm resistors
● A breadboard
● Connecting wires
● Red, yellow and green
Basics
Let's start small. A basic, single traffic light is a good place to start. Here's the circuit:
Connect the anode (long leg) of each LED to digital pins eight, nine, and ten (via a 220- ohm
resistor). Connect the cathodes (short leg) to the Arduino's ground.
// C++ code
//
int counter1=0;
void setup()
{
//pinMode(LED_BUILTIN, OUTPUT);
void loop()
{
if (counter1<10)
{
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
delay(1000);
}
else
{
if(counter1<20)
{
digitalWrite(13,LOW);
digitalWrite(12,HIGH);
digitalWrite(11,LOW);
delay(1000);
}
else
{
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,HIGH);
delay(1000);
}
// Wait for 1000 millisecond(s)
}
counter1= counter1+1;
}
Code for the Arduino Traffic Light
Start by defining variables so that you can address the lights by name rather than a
number. Start a new Arduino project, and begin with these lines:
Next, let’s add the setup function, where you'll configure the red, yellow and green LEDs to
be outputs. Since you have created variables to represent the pin numbers, you can now refer
to the pins by name instead:
The pinMode function configures the Arduino to use a given pin as an output. You have to
do this for your LEDs to work at all. Now for the actual logic of the traffic light. Here's the
code you need. Add this below your variable definitions and setup function:
Upload this code to your Arduino, and run (make sure to select the correct board and port
from the Tools > Board and Tools > Port menus). You should have a working traffic light that
changes every 15 seconds, like this (sped up):
Let's break down this code. The changeLights function performs all the hard work. This
rotates the traffic light through yellow and red, then back to green. As this gets called inside
the loop function, the Arduino will run this code forever, with a 15-second pause every time.
These four steps replicate the process used in real traffic lights. For each step, the code is very
similar. The appropriate LED gets turned on or off using digitalWrite. This is an Arduino
function used to set output pins to HIGH (for on), or LOW (for off).
After enabling or disabling the required LEDs, the delay makes the Arduino wait for a given
amount of time. Three seconds in this case.
Now that you know the basics, let's improve it. Add in a pushbutton for pedestrians to change
the light whenever they like:
Notice how the traffic light is exactly the same as the previous example. Connect the button
to digital pin 12. You'll notice that the switch has a high-impedance 10k-ohm resistor
attached to it, and you may be wondering why. This is a pull-down resistor.
A switch either lets the current flow or doesn't. This seems simple enough, but in a logic
circuit, the current should be always flowing in either a high or low state (remember, 1 or 0,
HIGH or LOW). You might assume that a pushbutton switch that isn't actually pressed would
be in a LOW state, but in fact, it's said to be 'floating', because no current gets drawn at all.
In this floating state, it's possible that a false reading will occur as it fluctuates with electrical
interference. In other words, a floating switch is giving neither a reliable HIGH nor LOW
reading. A pull-down resistor keeps a small amount of current flowing when the switch gets
closed, thereby ensuring an accurate low state reading.
In other logic circuits, you may find a pull-up resistor instead, and this works on the same
principle, but in reverse, making sure that particular logic gate defaults to high.
Now, in the loop part of the code, instead of changing the lights every 15 seconds, you're
going to read the state of the pushbutton switch instead, and only change the lights when it's
activated.
Now, in the setup function, add a new line to declare the switch as an input. Add a line to set
the traffic lights to the green stage. Without this initial setting, they would off until the first
time changeLights runs.
That should do it. You may be wondering why the button checking happens twice
(digitalRead(button)), separated by a small delay. This is debouncing. Much like the pull-
down resistor for the button, this simple check stops the code detecting minor interference as
a button press.
By waiting inside the if statement for 15 seconds, the traffic lights can't change for at least
that duration. Once 15 seconds is over the loop restarts. Each restart of the loop, it reads the
state of the button again, but if it isn't pressed, the if statement never activates, the lights never
change, and the program restarts again.
Connect the second traffic light to digital pins 11, 12, and 13.
First, assign your new traffic light pins to variables, and configure them as outputs, like in
the first example:
Now, update your loop to use the code from the first example (instead of the pedestrian
crossing):
Once again, all the work is carried out in the changeLights function. Rather than going red >
red & yellow > green, this code will alternate the traffic lights. When one is on green, the
other is on red. Here's the code:
Conclusion:
EXPERIMENT NO. 7 (Group B)
Aim: Create a program so that when the user enters "B" the green light blinks, "g" the
green light is illuminated "y" the yellow light is illuminated and "r" the red light is
illuminated
Outcome: Connectivity, configuration and control of LED using Arduino circuit under
different conditions.
● Theory:
The problem statement is like Arduino traffic light, a fun little project that you can build in
under an hour. Here's how to build your own using an Arduino, and how to change
the circuit for an advanced variation.
● 1 x 10k-ohm resistor
● 1 x pushbutton switch
● 6 x 220-ohm resistors
● A breadboard
● Connecting wires
● Red, yellow and green
Basics
Let's start small. A basic, single traffic light is a good place to start. Here's the circuit:
Connect the anode (long leg) of each LED to digital pins eight, nine, and ten (via a 220- ohm
resistor). Connect the cathodes (short leg) to the Arduino's ground.
// C++ code
//
int mychar=0;
void setup()
{
Serial.begin(9600);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
void loop()
{
if(Serial.available()>0)
{
//read the incoming byte
mychar=Serial.read();
Serial.print("I received 1");
Serial.print(mychar);
}
if(mychar==114)
{
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
}
if(mychar==103)
{
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
}
if(mychar==98)
{
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
}
Code for the Arduino Traffic Light
Start by defining variables so that you can address the lights by name rather than a
number. Start a new Arduino project, and begin with these lines:
Next, let’s add the setup function, where you'll configure the red, yellow and green LEDs to
be outputs. Since you have created variables to represent the pin numbers, you can now refer
to the pins by name instead:
The pinMode function configures the Arduino to use a given pin as an output. You have to
do this for your LEDs to work at all. Now for the actual logic of the traffic light. Here's the
code you need. Add this below your variable definitions and setup function:
Upload this code to your Arduino, and run (make sure to select the correct board and port
from the Tools > Board and Tools > Port menus). You should have a working traffic light that
changes every 15 seconds, like this (sped up):
Let's break down this code. The changeLights function performs all the hard work. This
rotates the traffic light through yellow and red, then back to green. As this gets called inside
the loop function, the Arduino will run this code forever, with a 15-second pause every time.
These four steps replicate the process used in real traffic lights. For each step, the code is very
similar. The appropriate LED gets turned on or off using digitalWrite. This is an Arduino
function used to set output pins to HIGH (for on), or LOW (for off).
After enabling or disabling the required LEDs, the delay makes the Arduino wait for a given
amount of time. Three seconds in this case.
Now that you know the basics, let's improve it. Add in a pushbutton for pedestrians to change
the light whenever they like:
Notice how the traffic light is exactly the same as the previous example. Connect the button
to digital pin 12. You'll notice that the switch has a high-impedance 10k-ohm resistor
attached to it, and you may be wondering why. This is a pull-down resistor.
A switch either lets the current flow or doesn't. This seems simple enough, but in a logic
circuit, the current should be always flowing in either a high or low state (remember, 1 or 0,
HIGH or LOW). You might assume that a pushbutton switch that isn't actually pressed would
be in a LOW state, but in fact, it's said to be 'floating', because no current gets drawn at all.
In this floating state, it's possible that a false reading will occur as it fluctuates with electrical
interference. In other words, a floating switch is giving neither a reliable HIGH nor LOW
reading. A pull-down resistor keeps a small amount of current flowing when the switch gets
closed, thereby ensuring an accurate low state reading.
In other logic circuits, you may find a pull-up resistor instead, and this works on the same
principle, but in reverse, making sure that particular logic gate defaults to high.
Now, in the loop part of the code, instead of changing the lights every 15 seconds, you're
going to read the state of the pushbutton switch instead, and only change the lights when it's
activated.
Now, in the setup function, add a new line to declare the switch as an input. Add a line to set
the traffic lights to the green stage. Without this initial setting, they would off until the first
time changeLights runs.
That should do it. You may be wondering why the button checking happens twice
(digitalRead(button)), separated by a small delay. This is debouncing. Much like the pull-
down resistor for the button, this simple check stops the code detecting minor interference as
a button press.
By waiting inside the if statement for 15 seconds, the traffic lights can't change for at least
that duration. Once 15 seconds is over the loop restarts. Each restart of the loop, it reads the
state of the button again, but if it isn't pressed, the if statement never activates, the lights never
change, and the program restarts again.
Connect the second traffic light to digital pins 11, 12, and 13.
First, assign your new traffic light pins to variables, and configure them as outputs, like in
the first example:
Now, update your loop to use the code from the first example (instead of the pedestrian
crossing):
Once again, all the work is carried out in the changeLights function. Rather than going red >
red & yellow > green, this code will alternate the traffic lights. When one is on green, the
other is on red. Here's the code:
Conclusion: -
EXPERIMENT NO. 8 (Group B)
● Aim: Write a program that asks the user for a number and outputs the number
squared that is entered
● Theory:
● Load an Example Sketch that uses the Serial Monitor to an Arduino Board
Start the Arduino IDE application. Select File → Examples → 04.Communication → ASCIITable
from the top Arduino IDE menu bar. As a result, the ASCIITable example sketch opens in a new
Arduino IDE window. Upload the ASCIITable example sketch to the Arduino Uno or MEGA
2560 board.
After the ASCIITable sketch is uploaded, nothing is seen to happen. This is because this example
sketch sends text out of the USB port of the Arduino board. Because there is nothing running on the
computer to receive this text, nothing is seen.
//
int power=2;
int out=0;
void setup()
void loop()
if(Serial.available()>0)
mychar=Serial.read();
out=pow(mychar,power);
Serial.print("I received....");
Serial.print(mychar);
Serial.print("Square of no....");
Serial.print(out);
}
}
Click the Serial Monitor icon near the top right of the Arduino IDE to open the serial monitor
window. The above image shows the serial monitor window opened, and on top of the Arduino
IDE window. Because the ASCIITable example is loaded on the Arduino board, when the serial
monitor window opens, the Arduino sends text to the serial monitor window. This is also because
opening the serial monitor window resets the Arduino board, causing the ASCIITable sketch to
run from the beginning again.
The ASCIITable sketch sends text out of the USB port of the Arduino. Because the serial monitor
is connected to the USB port, it receives the text and displays it in the big receive area of the
window. As a result, text scrolls on the serial monitor window for a while. The text then stops
because the Arduino has finished sending text. Use the right scrollbar in the serial monitor
window to scroll up. Scrolling up reveals all of the text that the Arduino sent.
The ASCIITable sketch sends the numbers 33 through to 126 out of the USB port. This results in
the printable text characters from the ASCII table displayed in the serial monitor window. In
addition to the ASCII characters, the number that represents each character is displayed. Each
number is shown in four different numbering systems. These are the decimal, hexadecimal, octal
and binary number systems. In the serial monitor window, these number systems are abbreviated
to dec, hex, oct and bin.
-----------------------------------------------------------------------------------------------------------------
-------
Conclusion: -
EXPERIMENT NO. 9 (Group B)
● Aim: Write a program to control the color of the LED by turning 3 different
potentiometers. One will be read for the value of Red, one for the value of Green, and
one for the value of Blue
● Theory:
The problem statement is like Arduino traffic light, a fun little project that you can build in
under an hour. Here's how to build your own using an Arduino, and how to change
the circuit for an advanced variation.
● 1 x 10k-ohm resistor
● 1 x pushbutton switch
● 6 x 220-ohm resistors
● A breadboard
● Connecting wires
● Red, yellow and green
Basics
Let's start small. A basic, single traffic light is a good place to start. Here's the circuit:
Connect the anode (long leg) of each LED to digital pins eight, nine, and ten (via a 220- ohm
resistor). Connect the cathodes (short leg) to the Arduino's ground.
Code for the Arduino Traffic Light
// C++ code//
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
void loop()
{
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
}
Start by defining variables so that you can address the lights by name rather than a
number. Start a new Arduino project, and begin with these lines:
Next, let’s add the setup function, where you'll configure the red, yellow and green LEDs to
be outputs. Since you have created variables to represent the pin numbers, you can now refer
to the pins by name instead:
The pinMode function configures the Arduino to use a given pin as an output. You have to
do this for your LEDs to work at all. Now for the actual logic of the traffic light. Here's the
code you need. Add this below your variable definitions and setup function:
Upload this code to your Arduino, and run (make sure to select the correct board and port
from the Tools > Board and Tools > Port menus). You should have a working traffic light that
changes every 15 seconds, like this (sped up):
Let's break down this code. The changeLights function performs all the hard work. This
rotates the traffic light through yellow and red, then back to green. As this gets called inside
the loop function, the Arduino will run this code forever, with a 15-second pause every time.
These four steps replicate the process used in real traffic lights. For each step, the code is very
similar. The appropriate LED gets turned on or off using digitalWrite. This is an Arduino
function used to set output pins to HIGH (for on), or LOW (for off).
After enabling or disabling the required LEDs, the delay makes the Arduino wait for a given
amount of time. Three seconds in this case.
Now that you know the basics, let's improve it. Add in a pushbutton for pedestrians to change
the light whenever they like:
Notice how the traffic light is exactly the same as the previous example. Connect the button
to digital pin 12. You'll notice that the switch has a high-impedance 10k-ohm resistor
attached to it, and you may be wondering why. This is a pull-down resistor.
A switch either lets the current flow or doesn't. This seems simple enough, but in a logic
circuit, the current should be always flowing in either a high or low state (remember, 1 or 0,
HIGH or LOW). You might assume that a pushbutton switch that isn't actually pressed would
be in a LOW state, but in fact, it's said to be 'floating', because no current gets drawn at all.
In this floating state, it's possible that a false reading will occur as it fluctuates with electrical
interference. In other words, a floating switch is giving neither a reliable HIGH nor LOW
reading. A pull-down resistor keeps a small amount of current flowing when the switch gets
closed, thereby ensuring an accurate low state reading.
In other logic circuits, you may find a pull-up resistor instead, and this works on the same
principle, but in reverse, making sure that particular logic gate defaults to high.
Now, in the loop part of the code, instead of changing the lights every 15 seconds, you're
going to read the state of the pushbutton switch instead, and only change the lights when it's
activated.
Now, in the setup function, add a new line to declare the switch as an input. Add a line to set
the traffic lights to the green stage. Without this initial setting, they would off until the first
time changeLights runs.
That should do it. You may be wondering why the button checking happens twice
(digitalRead(button)), separated by a small delay. This is debouncing. Much like the pull-
down resistor for the button, this simple check stops the code detecting minor interference as
a button press.
By waiting inside the if statement for 15 seconds, the traffic lights can't change for at least
that duration. Once 15 seconds is over the loop restarts. Each restart of the loop, it reads the
state of the button again, but if it isn't pressed, the if statement never activates, the lights never
change, and the program restarts again.
Connect the second traffic light to digital pins 11, 12, and 13.
First, assign your new traffic light pins to variables, and configure them as outputs, like in
the first example:
Now, update your loop to use the code from the first example (instead of the pedestrian
crossing):
Once again, all the work is carried out in the changeLights function. Rather than going red >
red & yellow > green, this code will alternate the traffic lights. When one is on green, the
other is on red. Here's the code:
Conclusion:
EXPERIMENT NO. 10 (Group B)
● Aim: Write a program read the temperature sensor and send the values to the serial
monitor on the computer
● Theory:
2 Analog There will be increase in 10mV for raise of every 1°C. Can range
Out from -1V(-55°C) to 6V(150°C)
below.
If the temperature is 0°C, then the output voltage will also be 0V. There will be rise of 0.01V (10mV)
for every degree Celsius rise in temperature. The voltage can converted into temperature using the
below formulae.
● Specification of DHT11
● It has humidity range from 20 to 90% RH
● It has temperature range from 0 – 50 C
● It has signal transmission range of 20 m
● It is inexpensive
● It has fast response and it is also durable
void loop()
{
temp = map(((analogRead(A0) - 20) * 3.04), 0, 1023, -40, 125);
Serial.println(temp);
delay(1011); // Delay a little bit to improve simulation performance
}
● Installing the DHT11 Library
To run the following code in Arduino IDE you will first have to install the DHT library in you
Arduino directory.
Download the zip file from here and place it in your Arduino library folder. The path to Arduino
library folder for my computer is
Documents/ Arduino/ Libraries
Unzip the downloaded file and place it in this folder.
After copying the files, the Arduino library folder should have a new folder named DHT containing
the dht.h and dht.cpp. After that copy the following code in the Arduino IDE and upload the code.
}
}
● Weather Station using DHT11 and arduino
In this example we will make a weather station that will sense the humidity and temperature and will
show it on the lcd attached to the Arduino. Make the circuit as shown in the diagram. The resistor in
the circuit will make the black light darker. We have used the 220 ohm resistor but you can use any
resistor having value near to that. The potentiometer we used in the circuit is used to set the screen
contrast. We have used the 10 K ohm value but you can choose any value relative to that one.
● Components Required
● Arduino Uno (you can use any)
● 16 x 2 LCD
● DHT11 Temperature and humidity sensor
● 10 K ohm potentiometer
● 220 ohm resistor
// Install the library of the DHT before uploading the code in the Arduino IDE
#include < dht.h > // including the DHT library
void loop ( )
Conclusion:
EXPERIMENT NO. 11 (Group B)
● Aim: Write a program read the temperature sensor and send the values to the serial
monitor on the computer
● Theory:
2 Analog There will be increase in 10mV for raise of every 1°C. Can range
Out from -1V(-55°C) to 6V(150°C)
below.
If the temperature is 0°C, then the output voltage will also be 0V. There will be rise of 0.01V (10mV)
for every degree Celsius rise in temperature. The voltage can converted into temperature using the
below formulae.
● Specification of DHT11
● It has humidity range from 20 to 90% RH
● It has temperature range from 0 – 50 C
● It has signal transmission range of 20 m
● It is inexpensive
● It has fast response and it is also durable
}
}
● Weather Station using DHT11 and arduino
In this example we will make a weather station that will sense the humidity and temperature and will
show it on the lcd attached to the Arduino. Make the circuit as shown in the diagram. The resistor in
the circuit will make the black light darker. We have used the 220 ohm resistor but you can use any
resistor having value near to that. The potentiometer we used in the circuit is used to set the screen
contrast. We
have used the 10 K ohm value but you can choose any value relative to that one.
● Components Required
● Arduino Uno (you can use any)
● 16 x 2 LCD
● DHT11 Temperature and humidity sensor
● 10 K ohm potentiometer
● 220 ohm resistor
// Install the library of the DHT before uploading the code in the Arduino IDE
#include < dht.h > // including the DHT library
void loop ( )
}
Temperature Scales
Thermometers measure temperature according to well-defined scales of measurement. The three most
common temperature scales are the Fahrenheit, Celsius, and Kelvin scales.
The Celsius scale has a freezing point of water as 0ºC and the boiling point of water as 100ºC. On the
Fahrenheit scale, the freezing point of water is at 32ºF and the boiling point is at 212ºF. The temperature
difference of one degree Celsius is greater than a temperature difference of one degree Fahrenheit. One
degree on the Celsius scale is 1.8 times larger than one degree on the Fahrenheit scale 180/100=9/5.
● Kelvin Scale
Kelvin scale is the most commonly used temperature scale in science. It is an absolute temperature scale
defined to have 0 K at the lowest possible temperature, called absolute zero. The freezing and boiling
points of water on this scale are 273.15 K and 373.15 K, respectively. Unlike other temperature scales, the
Kelvin scale is an absolute scale. It is extensively used in scientific work. The Kelvin temperature scale
possesses a true zero with no negative temperatures. It is the lowest temperature theoretically achievable
and is the temperature at which the particles in a perfect crystal would become motionless.
The relationship between three temperature scales is given in the table below:
Conclusion: -
● Theory:
void setup()
Serial.begin(9600);
pinMode(sensor,INPUT);
pinMode(LED,OUTPUT);
pinMode(buzzer,OUTPUT);
void loop()
digitalWrite(LED,HIGH); //led on
digitalWrite(LED,LOW);
noTone(buzzer);
delay(300);
● Aim: Study of ThingSpeak – an API and Web Service for the Internet of Things
Connectivity, configuration and serial communication with Arduino.
● Theory: write it by your own with the help of link provided to you.