Iot Lab Record
Iot Lab Record
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()
RESULT:
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:
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:
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);
}//end "setup()"
void loop(){
//Start of Program
DHT.read11(dht_apin);
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
RESULT:
Aim:
To interface motor using relay with Arduino and write a program to turn on motor when push
button is pressed
Program:
RESULT:
Aim:
To interface push button/Digital sensor (IR/LDR) with NodeMCU and write a program to print
LDR values
Program:
// Hardware: NodeMCU
int BUTTONstate = 0;
void setup()
Serial.begin(115200);
pinMode(LED, OUTPUT);
void loop()
digitalWrite(LED, LOW);
BUTTONstate = digitalRead(BUTTON);
if (BUTTONstate == HIGH)
digitalWrite(LED, LOW);
else
digitalWrite(LED, HIGH);
delay(1000);
RESULT:
Aim:
To interface buzzer with NodeMCU and write a program to turn on buzzer when push
button is pressed
Program:
// Hardware: NodeMCU
int BUTTONstate = 0;
void setup()
Serial.begin(115200);
pinMode(LED, OUTPUT);
void loop()
digitalWrite(LED, LOW);
BUTTONstate = digitalRead(BUTTON);
if (BUTTONstate == HIGH)
digitalWrite(LED, HIGH);
else
digitalWrite(LED, LOW);
delay(1000);
Result:
Aim:
Write а program on NodeMCU to upload temperature and humidity data to thingspeak cloud.
Program:
#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_value();
upload();
void upload()
internet();
if (x == 200)Serial.println("Data Updated.");
if (x != 200)
delay(15000);
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()
Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.println(outputValue);
delay(1000);
Result:
Aim:
To interface Wifi with NodeMCU and write a program to send data to Webpage
Program:
#include <ESP8266WiFi.h>
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);
int value = 0;
void loop()
analog_value = analogRead(ANALOG_PIN_0);
WiFiLocalWebPageCtrl();
delay(100);
/***************************************************
****************************************************/
void WiFiLocalWebPageCtrl(void)
//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.
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_value);
client.print("<br>");
client.print("<br>");
client.println();
break;
currentLine = "";
} else if (c != '\r') { // if you got anything else but a carriage return character,
// Check to see if the client request was "GET /H" or "GET /L":
if (currentLine.endsWith("GET /H")) {
if (currentLine.endsWith("GET /L")) {
client.stop();
Serial.println("Client Disconnected.");
/***************************************************
****************************************************/
void connectWiFi(void)
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();
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
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin, GPIO.OUT)
# Blink forever
try:
while True:
finally:
GPIO.cleanup()
Result:
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 time
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...')
time.sleep(0.2)
else:
GPIO.output(led, False)
def endprogram():
GPIO.output(led, False)
GPIO.cleanup()
if __name__ == '__main__':
setup()
try:
loop()
except KeyboardInterrupt:
endprogram()
Result:
Aim:
Program:
import httplib
import urllib
import time
def thermometer():
while True:
conn = httplib.HTTPConnection("api.thingspeak.com:80")
try:
response = conn.getresponse()
print temp
data = response.read()
conn.close()
break
if __name__ == "__main__":
while True:
thermometer()
Result: