Iot Practical File
Iot Practical File
& TECHNOLOGY
Experiment 1
Aim of the Experiment: Write the code to blink an LED on Arduino MKR1000.
Compile and verify the result on the serial monitor of Arduino IDE.
Circuit Diagram:
Software program:
void setup()
{
pinMode(7, OUTPUT);
}
void loop()
{
digitalWrite(7, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(7, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
Experiment 2
Aim of the Experiment: Interfacing of Arduino MKR1000 with LED and switch.
Write a program to control LED using Switch.
Circuit Diagram:
Software program:
void setup() {
pinMode (ledPin, OUTPUT); // declare LED as output
pinMode (inPin, INPUT); // declare pushbutton as input
}
void loop(){
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite (ledPin, LOW); // turn LED OFF
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
}
}
Experiment 3
Aim of the Experiment: Interfacing of Arduino MKR1000 with potentiometer and
LED. Write a program to vary the intensity of LED using a potentiometer.
Circuit Diagram:
Software program:
int potValue;
void setup()
{
Serial.begin(9600);
pinMode(A2,INPUT);
pinMode(11,OUTPUT);
}
void loop()
{
potValue=analogRead(A2);
Serial.println(potValue);
analogWrite(11,potValue*255/1023);
delay(100);
}
Experiment 4
Aim of the Experiment : a) Interfacing of Ultrasonic sensor with Arduino
MKR1000. Write a program to measure the distance from obstacle and display on the
serial monitor.
Circuit Diagram:
Software program:
int cm=0;
int inch =0;
int trigPin=7;
int echoPin=8;
long duration;
void setup()
{
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(trigPin,LOW);
delayMicroseconds(10);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
duration=pulseIn(echoPin,HIGH);
cm=duration*0.034/2;
Serial.print("Distance in cm is: ");
Serial.print(cm);
Serial.print("\n");
delay(100);
}
Circuit Diagram:
Software program:
const int ProxSensor=2;
int inputVal = 0;
void setup()
{
pinMode(13, OUTPUT);
pinMode(ProxSensor,INPUT);
Serial.begin(9600);
}
void loop()
{
if(digitalRead(ProxSensor)==HIGH)
{
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
inputVal = digitalRead(ProxSensor);
Serial.println(inputVal);
delay(1000);
}
Experiment 5
Aim of the Experiment : a) interfacing of Temperature sensor with Arduino
MKR1000. Write a program to read the specific temperature of a room and display on
the serial monitor.
Circuit Diagram:
Software program:
#include<DHT.h>
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN,DHTTYPE);
float hum;
float temp;
void setup()
{
Serial.begin(9600);
dht.begin();
}
void loop()
{
delay(500);
hum = dht.readHumidity();
temp = dht.readTemperature();
Serial.print("Humidity: ");
Serial.println(hum);
Serial.print("Temp: ");
Serial.println(temp);
}
Circuit Diagram:
Software program:
int sensorpin=A0;
int led=7;
void setup ()
{
pinMode(sensorpin, INPUT);
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int value=analogRead(sensorpin);
if(value<500)
{
digitalWrite(led, HIGH);
Serial.println(“Its DARK , Turn on the led”);
Serial.print(value);
}
else
{
digitalWrite(led, LOW);
Serial.println(“Its BRIGHT, Turn off the led”);
Serial.print(value);
}
}
Experiment 6
Aim of the Experiment: a) Interfacing of DC motor on Arduino MKR1000. Write a
program to rotate the motor in clockwise and anticlockwise direction with using a
delay of 2 seconds.
Circuit Diagram:
Software program:
void setup ()
{
pinMode(3, OUTPUT);
pin Mode(7, OUTPUT);
pinMode(8, OUTPUT);
Serial.begin(9600);
} void loop ()
{
analogWrite(3, 127);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
Serial.println(“CLOCKWISE”);
delay(1000);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
Serial.println(“ANTICLOCKWISE”);
delay(1000);
}
Experiment 7
Aim of the Experiment: Interfacing of a display device, i.e., LCD x2 with Arduino
MKR1000. Write a program to display “HELLO IOT” on LCD.
Circuit Dia3gram:
Software program:
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.print(“HELLO IOT”);
}
void loop() {
lcd.setCursor(0, 1);
lcd.print(millis()/1000);
}
Aim of the experiment: b) Write the program to scroll the message of “Welcome to
IOT lab” on LCD.
Software program:
// include the library code:
#include <LiquidCrystal.h>
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.print(“Welcome to IOT lab”);
}
void loop() {
lcd.setCursor(0, 1);
lcd.print(millis()/1000);
}
Aim of the experiment: c) Write the program to blink the message of “Hello IOT”
on Arduino MKR1000
Software program:
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.print(“Hello IOT”);
}
void loop() {
lcd.setCursor(0, 1);
lcd.print(millis()/1000);
}
Experiment 8
Aim of the experiment: Write down the steps to connect Arduino MKR1000. Write
a program to blink a LED using Arduino IoT cloud.
Components: Arduino MKR1000, LED, Breadboard Circuit
Circuit Diagram:
Software Program:
#include “thingProperties.h”
#define LED_BUILTIN 8
void setup ()
{
Serial.begin(9600);
delay (1500);
pinMode(LED_BUILTIN, OUTPUT);
int Properties ();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop ()
{
ArduinoCloud.update();
}
void onLedChange ()
{
digitalWrite(LED_BUILTIN, led);
}
Circuit Diagram:
Software program:
#include “arduino_secrets.h”
#include “thingProperties.h”
#define en 2
void setup ()
{
Serial.begin(9600);
delay (1500);
pinMode(en, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
digitalWrite(3,0);
digitalWrite(4,0);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop ()
{
ArduinoCloud.update();
}
void onMotorspeedChange()
{
analogWrite(en, motorspeed);
}
void onMotorChange()
{
digitalWrite(3, motor);
digitalWrite(4, motor);
}
Experiment 10
Aim of the experiment : Write a program to visualize data of temperature sensor on
Arduino IoT cloud.
Components: Arduino MKR1000, Temperature sensor, Breadboard Circuit
Circuit Diagram:
Software Program:
#include “arduino_secrets.h:
#include <DHT.h>
#include <DHT_U.h>
#include “thingProperties.h”
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup ()
{
Serial.begin(9600);
dht.begin();
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop ()
{
ArduinoCloud.update();
temp=dht.readTemperature();
humidity=dht.readHumidity();
}