iot_lab_programs
iot_lab_programs
Aim: Upload computer code to the physical board (Microcontroller) to blink a LED.
Circuit Diagram:
POSITIVE
TERMINAL
Program:
void setup()
{
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
1
digitalWrite(13, LOW);
delay(1000);
}
2
SOUND BUZZER USING ARDUINO
Aim : Write and upload computer code to the physical Arduino board Micro controller to
sound buzzer.
Components Required : Arduino Uno, buzzer, Resistor(100 ohms) and Bread Board
Circuit Diagram:
Program
void setup()
{
pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output
}
void loop()
{
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(1000); // ...for 1sec
}
3
Result : Output has been verified.
4
Auto ON/OFF Light using Arduino
Aim:Circuit and program to Interface light sensor – LDR with arduino to switch ON/OFF
LED based on light intensity.
Components Required : Arduino Uno, buzzer, Resistor(100 ohms) and Bread Board
Circuit Diagram:
Program
const int ledPin = 13;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ldrPin, INPUT);
5
void loop()
{
digitalWrite(ledPin, HIGH);
else
digitalWrite(ledPin, LOW);
6
INTERFACE POTENTIOMETER WITH ARDUINO
Aim: Set up & test circuit to interface potentiometer with Arduino board and map to digital
values for eg. 0-1023.
Circuit Diagram:
GND
5VOLT
Program
void setup()
{
Serial.begin(9600);
}
void loop()
{
int sensorValue = analogRead(A2);
Serial.println(sensorValue);
delay(500);
}
7
Result : Output has been verified.
8
ARDUINO RELAY MODULE INTERFACING
Aim: Rig up the Circuit and upload a program to Control a relay and switch on/off LED light
using Arduino.
Components Required : Arduino Uno, potentiometer and Bread Board
Circuit Diagram : High Voltage Caution. Do not Touch the circuit when the power is
ON.
Program
void setup()
{
pinMode(11,OUTPUT);
}
void loop()
{
digitalWrite(11,HIGH);
delay(1000);
digitalWrite(11,LOW);
}
9
ARDUINO LCD DISPALY INTERFACE
Aim: Make Circuit and upload a program to Interface LCD display with a microcontroller to
display characters.
Components Required : Arduino Uno, potentiometer, 16X2 LCD Dispaly, connecting wires
and Bread Board
Circuit Diagram:
10
5 VOLT
GND
Program:
#include <LiquidCrystal.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);
void setup()
{
lcd.begin(16,2);
}
void loop()
{
lcd.print("Arduino");
delay(3000);
lcd.setCursor(0,1);
lcd.print("LCD Tutorial");
delay(3000);
lcd.setCursor(0,0);
lcd.clear();
delay(3000);
}
Result : Output has been verified.
11
DISPLAY TEMPERATURE ON THE LCD
Aim: Rig up the circuit and upload a program to interface temperature sensor – LM35 with a
controller to display temperature on the LCD.
Components Required : Arduino Uno, potentiometer, 16X2 LCD Dispaly, connecting wires
and Bread Board
Circuit Diagram
Program:
#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int sensor=A1;
float tempc;
float tempf;
float vout;
void setup()
{
pinMode(sensor,INPUT);
12
Serial.begin(9600);
lcd.begin(16,2);
delay(500);
}
void loop()
{
vout=analogRead(sensor);
vout=(vout*500)/1023;
tempc=vout;
tempf=(vout*1.8)+32;
lcd.setCursor(0,0);
lcd.print("in DegreeC= ");
lcd.print(tempc);
lcd.setCursor(0,1);
lcd.print("in Fahrenheit=");
lcd.print(tempf);
delay(1000);
}
13
ARDUINO DC MOTOR INTERFACE USING TRANSISTOR
Aim: Set up Circuit and upload program to Interface DC motor (actuator) with
microcontroller to control on /off /forward/reverse operations.
Components Required
Circuit Diagram
Program 1:
int motorPin = 3;
void setup()
{
14
void loop()
{
digitalWrite(motorPin, HIGH);
}
void setup()
{
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
while (! Serial);
Serial.println("Speed 0 to 255");
}
void loop()
{
if (Serial.available())
{
int speed = Serial.parseInt();
if (speed >= 0 && speed <= 255)
{
analogWrite(motorPin, speed);
}
}
}
15
PROGRAM TO CONTROL THE DIRECTION OF MOTOR USING L293 MODULE
int motorPin1 = 6;
int motorPin2 = 7;
void setup()
{
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
}
void loop()
{
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
}
16
ARDUINO SERVO INTERFACE
Aim: To control the direction and speed of servo motor using Arduino UNO.
Components Required : Arduino Uno, Servo Motor, connecting wires and Bread Board
Circuit Diagram
Program:
#include <Servo.h>
Servo myservo;
int pos = 0;
void setup()
{
myservo.attach(9);
}
17
void loop()
{
for (pos = 0; pos <= 180; pos += 1)
{
myservo.write(pos);
delay(15);
}
18
ARDUINO ULTRASONIC SENSOR INTERFACE
Aim: To interface ultrasonic sensor with arduino and measure the distance.
Components Required : Arduino Uno, ultrasonic sensor, connecting wires and Bread Board
Circuit Diagram
Program:
void setup()
{
19
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
distance= duration*0.034/2;
Serial.print("Distance: ");
Serial.println(distance);
}
20
ARDUINO IR SENSOR INTERFACE
Components Required : Arduino Uno, ultrasonic sensor, connecting wires and Bread Board
Circuit Diagram: Connect OUT PIN of IR sensor to pin 2 of Arduino. Connect VCC and
GND of IR sensor to 5 volt and Gnd of Arduino.
Program:
int IRSensor = 2;
int LED = 13;
void setup()
{
pinMode (IRSensor, INPUT);
pinMode (LED, OUTPUT);
}
21
void loop()
{
if (statusSensor == 1)
{
digitalWrite(LED, LOW); }
else
{
digitalWrite(LED, HIGH);
}
22
WEATHER MONITORING STATION
Aim: Design a weather monitoring station using ESP8266 and BLYNK-IoT PLATFORM to
measure and record Information such as temperature, relative humidity, solar radiation and
atmospheric pressure.
Components required: ESP8266, DHT11 Sensor, BMP180 Pressure sensor, Breadboard and
connecting wires.
Circuit Diagram :
23
Connect OUT/DATA pin of DHT11 to GPIO2 ( D4 ) of Nodemcu
24
Program
#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
#define I2C_SCL 12
#define I2C_SDA 13
char auth[] = "559WJy8iD89zad2WwUFe9W7CVXFCOfx6";
char ssid[] = "AndroiP";
char pass[] = "blkl8848";
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
float bp = bmp.readPressure();
float bpp = bp/100.0;
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
Blynk.virtualWrite(V4, bpp);
}
25
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
dht.begin();
Wire.begin(I2C_SDA, I2C_SCL);
bmp.begin();
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
26
SMART WASTE MANAGEMENT
Components required: ESP8266, DHT11 Sensor, BMP180 Pressure sensor, Breadboard and
connecting wires.
Circuit Diagram :
27
CONNECT VCC PIN OF ULTRASONIC SENSOR TO 3.3V PIN OF ESP8266
Program:
28
const int echoPin = D2;
long duration;
int d;
void sendSensor()
{
d = duration*0.034/2;
float dis = 20.0 - d;
Blynk.virtualWrite(V5, dis);
}
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, sendSensor); // 1 second delay
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
delay(1000);
Blynk.run();
timer.run();
}
Result: Output has been verified
29
ARDUINO GPS INTERFACE
Aim: To interface Arduino with GPS module and display latitude, longitude, Altitude and
Speed on Serial Monitor
Components Required: Arduino Uno, GPS Module and connecting wires
Circuit Diagram
Program:
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
30
SoftwareSerial ss(RXPin, TXPin);
void setup()
{
Serial.begin(9600);
ss.begin(GPSBaud);
}
void loop()
{
if (gps.location.isUpdated())
{
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude= ");
Serial.println(gps.location.lng(), 6);
Serial.print("Altitude in feet = ");
Serial.println(gps.altitude.feet());
Serial.print("Number os satellites in use = ");
Serial.println(gps.satellites.value());
Serial.print("Altitude in meters = ");
Serial.println(gps.altitude.meters());
Serial.print("Speed in km/h = ");
Serial.println(gps.speed.kmph());
}
}
}
Result: Output has been verified
31
SMART HOME AUTOMATION
32
Program:
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
33
SMART STREET LIGHTING SYSTEM
Aim: To implement smart street light system using LDR and IR sensor.
Components Required: Arduino Uno, LDR, IR Sensor, 10K Resistor, Bread Board and
connecting wires.
Circuit:
Program:
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
34
pinMode(ldrPin, INPUT);
pinMode (IRSensor, INPUT);
}
void loop()
{
int ldrStatus = analogRead(ldrPin);
int statusSensor = digitalRead (IRSensor);
35
THINGSPEAK-IoT PLATFORM
Aim: To upload sensor data from DHT11 and BMP180 to Thingspeak-IoT Platform.
Circuit Diagram:
36
Connect OUT/DATA pin of DHT11 to GPIO2 ( D4 ) of Nodemcu
Program:
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
#define I2C_SCL 12
#define I2C_SDA 13
37
#define DHTPIN 2
WiFiClient client;
void setup()
Serial.begin(115200);
delay(10);
dht.begin();
delay(10);
Wire.begin(I2C_SDA, I2C_SCL);
delay(10);
bmp.begin();
Serial.println("Connecting to ");
Serial.println(ssid);
38
WiFi.begin(ssid, pass);
delay(500);
Serial.print(".");
Serial.println("");
Serial.println("WiFi connected");
void loop()
if (!bmp.begin())
while (1) {}
float bp = bmp.readPressure();
39
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
return;
if (client.connect(server, 80))
postStr += "&field1=";
postStr += String(t);
postStr += "&field2=";
postStr += String(h);
postStr += "&field3=";
postStr += String(bp);
postStr += "\r\n\r\n";
client.print("Host: api.thingspeak.com\n");
40
client.print("Connection: close\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(h);
Serial.print(bp);
Serial.println("pasacal");
client.stop();
Serial.println("Waiting...");
delay(1000);
41