Вы находитесь на странице: 1из 21

CHITKARA UNIVERSITY INSTITUTE OF ENGINEERING

& TECHNOLOGY

COMPUTER SCIENCE ENGINEERING

Submitted By: Submitted To:


S. No.
Lab Experiment Date Signature
1 Write the code to blink an LED on Arduino MKR1000. Compile and
verify the result on the serial monitor of Arduino IDE.
2 Interfacing of Arduino MKR1000 with LED and switch. Write a
program to control LED using Switch.
3 Interfacing of Arduino MKR1000 with potentiometer and LED. Write a
program to vary the intensity of LED using a potentiometer.
4 (a) Interfacing of Ultrasonic sensor with Arduino MKR1000. Write

a program to measure the distance from obstacle and display on


the serial monitor.
(b) Interface an IR sensor with Arduino MKR1000. Write a
program to detect obstacle and display on the serial monitor.
5 (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.
(b) Interfacing of LDR with Arduino MKR1000. Write a program
to control the intensity of LED using LDR.
6 (a) Interfacing of DC motor with Arduino MKR1000. Write a
program to rotate the motor in clockwise and anticlockwise
direction with using a delay of 2 sec.
(b) Familiarize the concept of pulse width modulation. Write a
program to control the speed of DC motor using PWM.

7 (a) Interfacing of a display device, i.e., LCD x2 with Arduino


MKR1000. Write a program to display “HELLO IOT” on LCD.
(b) Write a program to scroll the message “Welcome to IoT Lab.”
(c) Write a program to blink the message “Hello IoT.”
8 Write down the steps to connect Arduino MKR1000 with IoT cloud.
Write a program to blink an LED using Arduino IoT cloud.
9 Write a program to visualize data of temperature sensor on Arduino IoT
cloud.
10 Design an interface to control the speed of DC motor using cloud
services. Store and visualize the data of speed of DC motor after every
one sec.

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.

Components Used: Arduino MKR1000, Bread Board, LED, Resistor, Micro-USB


Data Cable, Connecting Wires, Computer With 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.

Components Used: MKR1000, Bread Board, LED, 2 Resistors, Micro-USB Data


Cable, Connecting Wires, Computer With Arduino IDE, Push Button.

Circuit Diagram:

Software program:

int ledPin = 13; // choose the pin for the LED


int inPin = 7; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status

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.

Components Used: MKR1000, Bread Board, LED, Resistor, Micro-USB Data


Cable, Connecting Wires, Computer With Arduino IDE, 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.

Components Used: MKR1000, Bread Board, Ultra-Sonic Sensor, Micro-USB Data


Cable, Connecting Wires, Computer With Arduino IDE.

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

b) Aim of the Experiment: Interface an IR sensor with Arduino MKR1000. Write a


program to detect obstacle and display on the serial monitor.

Components Used: MKR1000, Bread Board, IR Sensor, Micro-USB Data Cable,


Connecting Wires, Computer With Arduino IDE.

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.

Components Used: MKR1000, Bread Board, DHT22(Temperature & Humidity


Sensor), Micro-USB Data Cable, Connecting Wires, Computer With Arduino IDE.

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

Aim of the experiment: b) Interfacing of LDR with Arduino MKR1000. Write a


program to control the intensity of LED using LDR. Components: Arduino
MKR1000, LDR, LED, Resistor

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

Screenshot of Serial monitor:

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.

Components Used: MKR1000, Bread Board, DC Motor, Motor Driver, Micro-USB


Data Cable, Connecting Wires, Computer With Arduino IDE.

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.

Components Used: MKR1000, Bread Board, LCD Display(16 x 2), Potentiometer,


Micro-USB Data Cable, Connecting Wires, Computer With Arduino IDE.

Circuit Dia3gram:

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

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>

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

Snapshot of Serial monitor:


Experiment 9
Aim of the experiment: Design an interface to control the speed of DC motor using
cloud services. Store and visualize the data of speed of DC motor after 1 sec.

Components: Arduino MKR1000, DC motor, l293d, Breadboard Circuit

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

Snapshot of Serial monitor:

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

Snapshot of Serial monitor: