0% found this document useful (0 votes)
18 views41 pages

iot_lab_programs

The document provides a series of Arduino projects, including LED blinking, buzzer sound, light sensor control, and interfacing with various components like LCDs, motors, and sensors. Each project includes an aim, required components, circuit diagrams, and programming code, with results verified for each. Additionally, it covers advanced applications such as weather monitoring, smart waste management, and IoT implementations using platforms like Blynk and Thingspeak.

Uploaded by

manojdhawan2017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views41 pages

iot_lab_programs

The document provides a series of Arduino projects, including LED blinking, buzzer sound, light sensor control, and interfacing with various components like LCDs, motors, and sensors. Each project includes an aim, required components, circuit diagrams, and programming code, with results verified for each. Additionally, it covers advanced applications such as weather monitoring, smart waste management, and IoT implementations using platforms like Blynk and Thingspeak.

Uploaded by

manojdhawan2017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

LED BLINKING USING ARDUINO

Aim: Upload computer code to the physical board (Microcontroller) to blink a LED.

Components Required : Arduino Uno, LED, Resistor and Bread Board

Circuit Diagram:

POSITIVE
TERMINAL

Program:

void setup()
{
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
delay(1000);

1
digitalWrite(13, LOW);
delay(1000);
}

Result: Output has been verified

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

const int buzzer = 7; //buzzer to arduino pin 9

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;

const int ldrPin = A0;

void setup()
{

Serial.begin(9600);

pinMode(ledPin, OUTPUT);

pinMode(ldrPin, INPUT);

5
void loop()
{

int ldrStatus = analogRead(ldrPin);

if (ldrStatus <= 200)


{

digitalWrite(ledPin, HIGH);

else

digitalWrite(ledPin, LOW);

Result : Output has been verified.

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.

Components Required : Arduino Uno, potentiometer and Bread Board

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);
}

Result : Output has been verified.

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);
}

Result : Output has been verified.

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

You will need the following components −

 1x Arduino UNO board ,1x PN2222 Transistor/ BC547, 1x Small 6V DC Motor,

1x 1N4001 diode, 1x 270 Ω Resistor

Circuit Diagram

Program 1:
int motorPin = 3;

void setup()
{

14
void loop()
{
digitalWrite(motorPin, HIGH);
}

Program2 : To control speed of DC Motor


int motorPin = 9;

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);
}
}
}

Result : Output has been verified.

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);
}

for (pos = 180; pos >= 0; pos - = 1)


{
myservo.write(pos);
delay(15);
}
}

Result : Output has been verified.

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:

const int trigPin = 9;


const int echoPin = 10;
long duration;
int distance;

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);

duration = pulseIn(echoPin, HIGH);

distance= duration*0.034/2;
Serial.print("Distance: ");
Serial.println(distance);
}

Result : Output has been verified.

20
ARDUINO IR SENSOR INTERFACE

Aim: Set up a test circuit to test IR sensor.

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()
{

int statusSensor = digitalRead (IRSensor);

if (statusSensor == 1)
{
digitalWrite(LED, LOW); }

else
{
digitalWrite(LED, HIGH);
}

Result : Output has been verified.

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 :

Connect SCL pin of BMP180 to GPIO12 ( D6 ) of


Nodemcu

Connect SDA pin of BMP180 to GPIO13 ( D7 ) of


Nodemcu

Connect VIN of BMP180 to 3.3V of Nodemcu

Connect GND of BMP180 to GND of Nodemcu

23
Connect OUT/DATA pin of DHT11 to GPIO2 ( D4 ) of Nodemcu

Connect VCC of DHT11 to 3.3V of Nodemcu

Connect GND of DHT11 to GND of Nodemcu

24
Program

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

#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();
}

Result : Output has been verified.

26
SMART WASTE MANAGEMENT

Aim: Implement Smart Waste Management Sytem using BLYNY-IoT platform

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

CONNECT GND PIN OF ULTRASONIC SENSOR TO GND PIN OF ESP8266

CONNECT TRIGGER PIN OF ULTRASONIC SENSOR TO D1 OF ESP8266\

CONNECT ECHO PIN OF ULTRASONIC SENSOR TO D2 OF ESP8266

Program:

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;

char auth[] = "gdGYFiXP_rFnOwy9yt-4v_qp4Us3FYco";


char ssid[] = "AndroidAP";
char pass[] = "fuxl8848";

const int trigPin = D1;

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>

static const int RXPin = 4, TXPin = 3;


static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;

30
SoftwareSerial ss(RXPin, TXPin);

void setup()
{
Serial.begin(9600);
ss.begin(GPSBaud);
}

void loop()
{

while (ss.available() > 0)


{
gps.encode(ss.read());

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

Aim: To implement Smart Home Automation using BLYNK IoT Platform.


Components Required: ESP8266, 4 Channel Relay Module and connecting wires.

32
Program:

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = " 8zEn8ZirKBFahUdC0gnLnMN9EJ6Mlhdm";


char ssid[] = "AndroidAP";
char pass[] = "fuxl8848";

void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}

void loop()
{
Blynk.run();
}

Result: Output has been verified

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:

const int ledPin = 13;


const int ldrPin = A0;
int IRSensor = 2;

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);

if ((ldrStatus <= 200) && (statusSensor == 0))


{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}

Result: Output has been verified

35
THINGSPEAK-IoT PLATFORM
Aim: To upload sensor data from DHT11 and BMP180 to Thingspeak-IoT Platform.

Components Required: ESP8266, DHT11, BMP180 and connecting wires.

Circuit Diagram:

Connect SCL pin of BMP180 to GPIO12 ( D6 ) of


Nodemcu

Connect SDA pin of BMP180 to GPIO13 ( D7 ) of


Nodemcu

Connect VIN of BMP180 to 3.3V of Nodemcu

Connect GND of BMP180 to GND of Nodemcu

36
Connect OUT/DATA pin of DHT11 to GPIO2 ( D4 ) of Nodemcu

Connect VCC of DHT11 to 3.3V of Nodemcu

Connect GND of DHT11 to GND 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

String apiKey = "XR0UM232QPHL4KKT";

const char *ssid = "AndroidAP";

const char *pass = "fuxl8848";

const char* server = "api.thingspeak.com";

DHT dht(DHTPIN, DHT11);

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);

while (WiFi.status() != WL_CONNECTED)

delay(500);

Serial.print(".");

Serial.println("");

Serial.println("WiFi connected");

void loop()

if (!bmp.begin())

Serial.println("Could not find a valid BMP085 sensor, check wiring!");

while (1) {}

float bp = bmp.readPressure();

39
float h = dht.readHumidity();

float t = dht.readTemperature();

if (isnan(h) || isnan(t))

Serial.println("Failed to read from DHT sensor!");

return;

if (client.connect(server, 80))

String postStr = apiKey;

postStr += "&field1=";

postStr += String(t);

postStr += "&field2=";

postStr += String(h);

postStr += "&field3=";

postStr += String(bp);

postStr += "\r\n\r\n";

client.print("POST /update HTTP/1.1\n");

client.print("Host: api.thingspeak.com\n");

40
client.print("Connection: close\n");

client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\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(" degrees Celcius, Humidity: ");

Serial.print(h);

Serial.print(" %, pressure: ");

Serial.print(bp);

Serial.println("pasacal");

client.stop();

Serial.println("Waiting...");

delay(1000);

Result: Sensor data has been uploaded successfully.

41

You might also like