IoT Lab 2
IoT Lab 2
IoT Lab 2
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:
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.
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);
}
WiFiServer server(80);
void setup() {
pinMode(sensor,INPUT);
Serial.begin(9600);
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:
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.
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);
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:
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.
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:
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.
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.