Nothing Special   »   [go: up one dir, main page]

IoT Lab 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Experiment 1: Measuring Temperature:

Aim:
To measure the room temperature of a place through Arduino using Lm-35.

Components Used:
1. Resistor - 470ɏ
2. Temperature resistor (LM35)
3. Arduino Uno Rev 2
4. Breadboard
5. Connecting wires

Circuit Diagram:

Figure 1: Circuit Diagram of measuring temperature


Theory:
Lm-35 is an absolute temperature sensor which can measure the
temperature of the surroundings with in 100 to 500 feet. Lm-35 output voltage
is proportional to the Celsius/centigrade temperature which increments the
output by 1 on every 10-mV change in temperature. Lm-35 can measure from -
50 to 150 degree Celsius.
x Arduino analog pins work normally on +5 volts.
x Resolution of analog pin starts from 0 to 1023.
x Maximum voltage of Lm35 is 1.5 voltage.
x Formula for converting the voltage into system input number =
(V/1024)*5

Procedure:
1. Make connections as per circuit diagram
2. Connect the Arduino to pc and configure Arduino IDE.
3. Copy and verify the code in Arduino IDE.
4. Upload the code to arduino.
5. Now see the temperature through serial monitor and webserver.

Arduino IDE code to display in serial monitor:


const int sensor=A0;
float tempc;
float tempf;
float vout;

void setup() {
pinMode(sensor,INPUT);
Serial.begin(9600);
}

void loop() {
vout=analogRead(sensor);
vout=(vout/1024.0)*5.0;
tempc = (vout - 0.5)*100;
tempf=(tempc*1.8)+32;
Serial.print("in DegreeC=");
Serial.print("\t");
Serial.print(tempc);
Serial.print(" °C ");
Serial.print("in Fahrenheit=");
Serial.print("\t");
Serial.print(tempf);
Serial.println(" °F ");
delay(5000);
}

Arduino code to display in web server:


#include <SPI.h>
#include <WiFiNINA.h>

char ssid[] = "wifi username";


char pass[] = "wifi password";
int keyIndex = 0;
int status = WL_IDLE_STATUS;

const int sensor=A0;


float tempc;
float tempf;
float vout;

WiFiServer server(80);

void setup() {
pinMode(sensor,INPUT);
Serial.begin(9600);

while ( status != WL_CONNECTED) {


Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);

delay(10000);
}
server.begin();
// you're connected now, so print out the status:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
}

void loop() {
vout=analogRead(sensor); //Reading the value from sensor
vout=(vout/1024.0)*5.0;
tempc = (vout - 0.5)*100;
tempf=(tempc*1.8)+32; // Converting to Fahrenheit
Serial.print("in DegreeC=");
Serial.print("\t");
Serial.print(tempc);
Serial.print(" °C ");
Serial.print("in Fahrenheit=");
Serial.print("\t");
Serial.print(tempf);
Serial.println(" °F ");
// listen for incoming clients
WiFiClient client = server.available();
client.println("<html>");
client.println("<table style='width:100%',>");
client.println("<tr>");
client.println("<th>");
client.println("Temperature in Celsius : ");
client.println(tempc);
client.println("°C ");
client.println("</th>");
client.println("Temperature in Fahrenheit : ");
client.println(tempf);
client.println("°F ");
client.println("</th>");
client.println("</tr></table>");
client.println("</html>");
delay(5000);
}

Precautions:
1. Connections should be made properly.
2. Avoid loose connections.
3. Verify the code before uploading.

Result:
Temperature is measured with temperature sensor LM35.
Experiment 2. Distance of the object
Aim:
To measure the distance of the object using ultrasonic sensor .

Components Used:
1. Ultrasonic sensor
2. Arduino Uno Rev 2
3. Breadboard
4. Connecting wires

Circuit Diagram:

Figure-2 Circuit Diagram of finding the distance of the experiment

Theory:
The Ultrasonic sensor emits out the very high frequency sound pulse and
checks the time taken to reflect the sound back. It has two openings in front
one for transmitting and other for receiving the sound waves. The sound
travels with the speed of 341 meters per second in air. The time difference
between the sending and receiving will help to measure the of the object
The mathematical equation: Distance = Time *(speed of sound/2)
Ultrasonic sensors will measure the following without any contact with the
medium:
1. Distance
2. Level
3. Position
4. Presence
5. Diameter
Procedure:
1. Make connections as per circuit diagram
2. Connect the Arduino to pc and configure Arduino IDE.
3. Copy and verify the code in Arduino IDE.
4. Upload the code to Arduino.
5. Now we can find out the distance through serial monitor.

Arduino IDE code to display in Serial monitor:


const int trigPin = 3;
const int echoPin = 2;
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.println(distance);
delay(10);
}

Arduino IDE code to display in Web server:


#include <SPI.h>
#include <WiFiNINA.h>

char ssid[] = "username"; //Enter your wifi username here


char pass[] = "password"; //Enter your wifi password here
int keyIndex = 0;

int status = WL_IDLE_STATUS;


const int trigPin = 3;
const int echoPin = 2;
long duration;
int distance;

WiFiServer server(80);

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);

// wait 10 seconds for connection:


delay(10000);
}
server.begin();
// you're connected now, so print out the status:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.println(distance);
Serial.print(" cm");
WiFiClient client = server.available();
client.println("<html>");
client.println("<table style='width:100%',>");
client.println("<tr>");
client.println("<th>");
client.println("Distance: ");
client.println(distance);
client.println(" cm");
client.println("</th>");
client.println("</tr></table>");
client.println("</html>");
delay(5000);
}

Precautions:
1. Connections should be made properly.
2. Avoid loose connections.
3. Verify the code before uploading.

Result:
So, the distance of the object is measured with the ultra- sonic sensor.
Experiment 3. Stopwatch in LCD
Aim:
To display stopwatch through LCD and control the stopwatch through
start/stop button.

Components Used:
1. LCD Screen
2. 220ɏ Resistor -(1)
3. 10kɏ potentiometer - (1)
4. Arduino Uno (any board)
5. Breadboard
6. Connecting wires
7. Push button - 2

Circuit Diagram:

Figure 3: Circuit diagram of stopwatch in LCD


Theory:
We come across LCD displays all around the world. Laptops, mobiles,
calculators, T.V, digital watches use display to display the digits. An L.C.D uses
the liquid crystal to show us the visible image which Is an electronic device. In
circuits we generally use 16*2 LCD display which is most used. The 16
characters are displayed in 2 lines, so we call it as a 16*2 display. Each
character is displayed in 5*7-pixel matrix. So here we now display the
stopwatch with the LCD.
Procedure:
1. Make connections as per circuit diagram.
2. Connect the Arduino to pc and configure Arduino IDE.
3. Copy and verify the code in Arduino IDE.
4. Upload the code to Arduino.
5. Now we can find out the stopwatch in the L.C.D.

Arduino IDE code:


#include<LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
double i = 0;
double a = millis();
double c ;
void setup()
{
lcd.begin(16, 2);
lcd.clear();

Serial.begin(9600);

pinMode(8, INPUT);
digitalWrite(8, HIGH);
pinMode(9, INPUT);
digitalWrite(9, HIGH);
}

void loop(){
lcd.clear();
lcd.print("press start");
delay(100);

if(digitalRead(8) == LOW)
{

lcd.clear();
a = millis();
while(digitalRead(9) == HIGH)
{

c = millis();
i = (c - a) / 1000;
lcd.print(i);
lcd.setCursor(7,0);
lcd.print("Sec's");
lcd.setCursor(0,0);
Serial.println(c);
Serial.println(a);
Serial.println(i);
Serial.println(" ..... ");
delay(100);
}

if(digitalRead(9) == LOW)
{
while(digitalRead(8) == HIGH)
{
lcd.setCursor(0,0);
lcd.print(i);
lcd.setCursor(11,0);
lcd.print("");
lcd.setCursor(0,0);
delay(100);
}
}
}
}

Precautions:
1.Connections should be made properly.
2.Avoid loose connections.
3.Verify the code before uploading.

Result:
The Stopwatch is displayed in the Liquid Crystal display with the
start/stop button.
Experiment 4. Traffic lights using LED’s
Aim: To control the traffic lights by switching LED’s with time.

Components Used:
1.Red, orange, green LED – 1No
2. 470ɏ – 3No
3. Arduino Uno (any board)
4. Push button
5. Breadboard
6. Connecting wires

Circuit Diagram:

Figure Error! No text of specified style in document.4: Circuit Diagram of traffic lights using
LED's

Theory:
An L.E.D(Light emitting diode) is a small light which works with very little
power. The digital pin 13 is built in the Arduino board for the L.E.D. LEDs have
polarity will work only the legs are oriented in the proper way. The two legs of
the L.E.D one leg goes for the positive and other leg is for the ground. The L.E.D
has flat edge on one side of the bulb. To protect the L.E.D we should use
resistors in series to protect it from burning.

Procedure:
1. Make connections as per circuit diagram.
2. Connect the Arduino to pc and configure Arduino IDE.
3. Copy and verify the code in Arduino IDE.
4. Upload the code to Arduino.
5. Now we can see the L.E.D lights up.

Arduino IDE code:


int red = 10;
int yellow = 9;
int green = 8;

void setup() {
// put your setup code here, to run once:
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);

void loop(){
// put your main code here, to run repeatedly:
digitalWrite(green, HIGH);
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
delay(5000);
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
digitalWrite(red, LOW);
delay(5000);
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delay(5000);
}

Precautions:
1.Connections should be made properly.
2.Avoid loose connections.
3.Verify the code before uploading.

Result:
Traffic lights with LED’s are achieved with time difference.
Experiment 5. Dark sensing light
Aim:
To light up an LED automatically if the room has no light present in it.

Components Used:
1. L.E.D
2. Resistors 470ɏ - 1
3. Photo Resistor
4. Arduino Uno (any board)
5. Breadboard
6. Connecting wires

Circuit Diagram:

Figure-5 Circuit Diagram of dark sensing light

Theory:
An LDR (Light Dependent Resistor) is a component which changes its resistance
depending upon the light intensity falling on it. These components are used in
light sensing circuits. In most common LDR if the light intensity is more falling
on it then the resistance will gradually decrease.
The resistance of the LDR have the following
Daylight = 5000ё
Dark = 20000000ё
Some of the application of LDR:
1. Lighting Switch
2. Camera shutter control
An L.E.D(Light emitting diode) is a small light which works with very little
power. The digital pin 13 is built in the Arduino board for the L.E.D. LEDs have
polarity will work only the legs are oriented in the proper way. The two legs of
the L.E.D one leg goes for the positive and other leg is for the ground. The L.E.D
has flat edge on one side of the bulb. To protect the L.E.D we should use
resistors in series to protect it from burning.

Theory for the coding:


We will the check the LDR for its analog values in the dark and the
daylight conditions. So as per the values we command the LDR to light up the
LED in the dark and to turn off the light in the daylight condition using the if
condition.

Procedure:
1. Make connections as per circuit diagram.
2. Connect the Arduino to pc and configure Arduino IDE.
3. Design the code with the help of the instructor.
4. Upload the code to Arduino.
5. Now we can see the L.E.D lights up.

Precautions:
1.Connections should be made properly.
2.Avoid loose connections.
3.Verify the code before uploading.

Result:
We can see the LED lighting up in the dark.

You might also like