Iot Lab Manual
Iot Lab Manual
To Interface LED With Arduino And Write A Program To Turn ON LED For 1 Sec After Every 2 Seconds.
AIM:
To interface LED with Arduino and write a program to turn ON LED for 1 sec after every 2
seconds.
PROGRAM:
void setup()
void loop()
OUTPUT:
RESULT:
To Interface Push Button/Digital Sensor (IR/LDR) With Arduino And Write A Program To Turn ON LED When Push Bu
AIM
: To interface Push button/Digital sensor (IR/LDR) with Arduino and write a
program to turn ON LED when push button is pressed or at sensor detection.
PROGRAM:
13;
int BUTTONstate = 0;
void setup()
pinMode(BUTTON,
INPUT); pinMode(LED,
OUTPUT);
void loop()
BUTTONstate =
digitalRead(BUTTON); if
(BUTTONstate == HIGH)
digitalWrite(LED, HIGH);
else{
digitalWrite(LED, LOW);
OUTPUT:
RESULT:
To Interface DHT11 Sensor With Arduino And Write A Program To Print Temperature And Humidity Readings.
Aim:
To interface DHT11 sensor with Arduino and write a program to print temperature and
humidity readings.
Program:
#include "dht.h"
dht DHT;
void setup(){
Serial.begin(9600);
boot
}//end "setup()"
void loop(){
//Start of Program
DHT.read11(dht_apin);
Serial.print("Current humidity =
"); Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
Output:
RESULT:
To Interface Motor Using Relay With Arduino And Write A Program To Turn On MotorWhen Push Button Is Pressed
Aim:
To interface motor using relay with Arduino and write a program to turn on motor when push
button is pressed
Program:
#8//
output//
Output:
RESULT:
To Interface Push Button/Digital Sensor (IR/LDR) With Nodemcu And Write A Program To Print LDR Values
Aim:
To interface push button/Digital sensor (IR/LDR) with NodeMCU and write a program to
print LDR values
Program:
// Hardware: NodeMCU
2;
int BUTTONstate = 0;
void setup()
Serial.begin(115200);
pinMode(LED, OUTPUT);
pinMode (BUTTON,
INPUT);
void loop()
digitalWrite(LED, LOW);
BUTTONstate =
digitalRead(BUTTON);
Serial.print(BUTTONstat
e); if (BUTTONstate ==
HIGH)
digitalWrite(LED, LOW);
else
digitalWrite(LED, HIGH);
delay(1000);
Output:
RESULT:
To Interface Buzzer With Nodemcu And Write A Program To Turn On Buzzer When Push Button Is Pressed
Aim
: To interface buzzer with NodeMCU and write a program to turn on buzzer when push
button is pressed
Program:
// Hardware: NodeMCU
4;
int BUTTONstate = 0;
void setup()
Serial.begin(115200);
pinMode(LED, OUTPUT);
pinMode (BUTTON,
INPUT);
void loop()
digitalWrite(LED, LOW);
BUTTONstate =
digitalRead(BUTTON);
Serial.print(BUTTONstat
e); if (BUTTONstate ==
HIGH)
digitalWrite(LED, HIGH);
else
digitalWrite(LED, LOW);
delay(1000);
Output:
Result:
Aim:
Write а program on NodeMCU to upload temperature and humidity data to thingspeak cloud.
Program:
// ----------(c) Electronics-Project-Hub-----------//
#include "ThingSpeak.h"
#include
<ESP8266WiFi.h>
//float value
= 0; int x =
0;
// //
// //
WiFiClient client;
void setup()
Serial.begin(115200);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
void loop()
internet(
);
get_valu
e();
upload()
void upload()
internet();
if (x != 200)
delay(150
00);
upload();
void internet()
if (WiFi.status() != WL_CONNECTED)
"); Serial.println(ssid);
WiFi.begin(ssid,
pass);
Serial.print(".");
delay(5000);
Serial.println("\nConnected.");
void get_value()
sensorValue = analogRead(analogInPin);
255);
Serial.print(sensorValue);
Serial.println(outputValue);
delay(1000);
// ----------(c) Electronics-Project-Hub-----------//
Output:
Result:
To Interface Wif With Nodemcu And Write A Program To Send Data To Webpage
Aim:
To interface Wifi with NodeMCU and write a program to send data to Webpage
Program:
#include <ESP8266WiFi.h>
password = "sara1980";
WiFiServer server(80);
/* LED */
#define LED_PIN 2
//Analog Input
#define ANALOG_PIN_0
A0 int analog_value = 0;
void setup()
Serial.begin(115200);
pinMode(LED_PIN,
OUTPUT);
delay(10);
connectWiFi();
int value = 0;
void loop()
analog_value =
analogRead(ANALOG_PIN_0);
WiFiLocalWebPageCtrl();
delay(100);
/***************************************************
**************************************************
//client = server.available();
String currentLine = ""; // make a String to hold incoming data from the client
// if the current line is blank, you got two newline characters in a row.
response: if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("Content-type:text/html");
client.println();
//WiFiLocalWebPageCtrl();
client.print("Analog Data:
");
client.print(analog_value);
client.print("<br>");
client.print("<br>");
LED off.<br>");
line: client.println();
break;
if (currentLine.endsWith("GET /L")) {
// close the
connection:
client.stop();
Serial.println("Client Disconnected.");
/***************************************************
**************************************************
Serial.println();
Serial.println();
Serial.print("Connecting to
"); Serial.println(ssid);
WiFi.begin(ssid,
password);
delay(500);
Serial.print("
.");
Serial.println("");
Serial.println("WiFi
connected.");
Serial.println(WiFi.localIP());
server.begin();
Output:
Result:
To Interface LED With Raspberry Pi And Write A Program To Turn ON LED For 1 Sec After Every 2 Seconds.
Aim
: To interface LED with raspberry pi and write a program to turn ON LED for 1 sec after
every 2 seconds.
Program:
import time
# Pin
definitions
led_pin = 12
numbering
GPIO.setmode(GPIO.BC
M)
GPIO.setup(led_pin,
GPIO.OUT)
# Blink
forever try:
while True:
off
resources finally:
GPIO.cleanup()
Output:
Result:
To Interface Push Button/Digital Sensor (IR/LDR) With Raspberry Pi And WriteA Program To Turn ON LED When Push
Aim:
To interface Push button/Digital sensor (IR/LDR) with raspberry pi and write a program
to turn ON LED when push button is pressed or at sensor detection.
Program:
import RPi.GPIO as
button = 16
led = 18
def setup():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(led, GPIO.OUT)
def loop():
while True:
button_state =
GPIO.input(button) if
button_state == False:
GPIO.output(led,
True) print('Button
Pressed...')
while GPIO.input(button) ==
False: time.sleep(0.2)
else:
GPIO.output(led, False)
def endprogram():
GPIO.output(led,
False)
GPIO.cleanup()
setup()
try:
loop()
except KeyboardInterrupt:
detected' endprogram()
Output:
Result:
Aim:
Write а program on raspberry pi to upload temperature and humidity data to thingspeak
cloud
Program:
import
httplib
import
urllib
import
time
while True:
conn =
httplib.HTTPConnection("api.thingspeak.com:80") try:
print temp
print response.status,
response.reason data =
response.read()
conn.close()
except:
print "connection
failed" break
while True:
thermometer()
Output:
Result: