0% found this document useful (0 votes)
60 views

Internet of Things Labaratory

The document describes 10 different circuits that can be constructed for an Internet of Things laboratory. The circuits cover topics like blinking LEDs, controlling LEDs based on number of visitors, measuring distance with ultrasonic sensors, controlling street lights with an LDR sensor, measuring temperature and controlling fans, interfacing motors with switches or sensors, and counting visitors in a shopping mall. Traffic light and obstacle avoidance circuits are also included.

Uploaded by

Abhiram Grandhi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Internet of Things Labaratory

The document describes 10 different circuits that can be constructed for an Internet of Things laboratory. The circuits cover topics like blinking LEDs, controlling LEDs based on number of visitors, measuring distance with ultrasonic sensors, controlling street lights with an LDR sensor, measuring temperature and controlling fans, interfacing motors with switches or sensors, and counting visitors in a shopping mall. Traffic light and obstacle avoidance circuits are also included.

Uploaded by

Abhiram Grandhi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

INTERNET OF THINGS LABARATORY

1. Construct circuit with different color LEDs and at once blink same color LEDs for 1000ms
and then blink random color LEDs with 1000ms delay for infinite loop.

void setup()
{

pinMode(2, OUTPUT);
pinMode(6, OUTPUT);

void loop()
{
digitalWrite(2, LOW);
digitalWrite(6, HIGH);
delay(1000);
digitalWrite(2, HIGH );
digitalWrite(6, LOW);
delay(1000);

}
}

2. Construct circuit to switch ON the LED only if the visitors in room are equal to or greater
than five.

const int in=8;


int led=3;
int temp=0;
void setup()
{
Serial.begin(9600);
pinMode(in,INPUT);
pinMode(led,OUTPUT);
Serial.println("Visitor Counter");
}
void loop()
{
if(digitalRead(in)==1)
{
temp=temp+1;
Serial.print("No.of persons inside: ");
Serial.println(temp);
if(temp>=5)
{
digitalWrite(led,HIGH);
}
else
{
digitalWrite(led, LOW);

}
}
}

3. Construct a circuit to find the distance of an obstacle.

int echoPin = 2; // attach pin D2 Arduino to pin Echo of HC-SR04


int trigPin = 3; //attach pin D3 Arduino to pin Trig of HC-SR04
int led = 10;

long duration; // variable for the duration of sound wave travel


int distance; // variable for the distance measurement

void setup()

{
pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
pinMode(led, OUTPUT); // Sets the trigPin as an OUTPUT
Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed
Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print some text in Serial Monitor

}
void loop()
{

digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Sets the trigPin HIGH (ACTIVE) for 10 microseconds

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds

duration = pulseIn(echoPin, HIGH);

// Calculating the distance

distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)

// Displays the distance on the Serial Monitor

Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
if(distance>50)
{
digitalWrite(led, HIGH);
}
else

{
digitalWrite(led, LOW);

}}
4. Construct a circuit to control the street light using LDR.

int ldr = A0;


int value = 0;
void setup()
{
Serial.begin(9600);
pinMode(3,OUTPUT);
}

void loop()
{
value = analogRead(A0);
Serial.println("LDR value is : ");
Serial.println(value);
if(value >= 200)
{
digitalWrite(3,HIGH);
}
else
{
digitalWrite(3,LOW);
}
delay(200);
}

5. Find the room Temperature and send the value over serial Monitor. Also assume two LEDs
as FANs and control the FANs based on room temperature. ( LED 1 should glow when
temperature exceeds 23 degrees and LED 2 should glow when temperature is beyond 40
degrees).

float temp;
int tempPin = A0;

void setup() {
Serial.begin(9600);
pinMode(11, OUTPUT);
pinMode(13, OUTPUT);
pinMode(A0,INPUT);
}
void loop() {
temp = analogRead(tempPin);
// read analog volt from sensor and save to variable temp
temp = temp * 0.48828125;
// convert the analog volt to its temperature equivalent
Serial.print("TEMPERATURE = ");
Serial.print(temp); // display temperature value
Serial.print("*C");
Serial.println();
delay(1000); // update sensor reading each one second
if (temp > 23)
{
digitalWrite(11, HIGH);

}
elseif (temp > 40)
{
digitalWrite(13, HIGH);

else

{
digitalWrite(11, LOW);
digitalWrite(13, LOW);
}
}

6. Construct circuit to Interface the Motor and switch to Arduino controller and when switch
1 pressed motor should rotate in forward direction and if switch 2 pressed motor should
rotate in reverse direction else in stop position.

int motor1pin1 = 12;


int motor1pin2 = 11;
int motor2pin1 = 10;
int motor2pin2 = 9;
int sw1 = 1;
int sw2 = 2;

void setup()

pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(motor2pin1, OUTPUT);
pinMode(motor2pin2, OUTPUT);
pinMode(sw1, INPUT);
pinMode(sw2, INPUT);

void loop()

{
if(digitalRead(1)==1)
{
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);

digitalWrite(motor2pin1, HIGH);
digitalWrite(motor2pin2, LOW);

//delay(10000);
}

if(digitalRead(2)==1)
{

digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);

digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, HIGH);

// delay(10000);
}
}
7. Construct circuit to Interface the Motor with PIR sensor, and if any obstacle then motor
should move in reverse direction and then take right turn.

int sensor = 7; // the pin that the sensor is atteched to


int state = 0; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)

int motor1_0 = 3;
int motor1_1 = 4;
int motor2_0 = 5;
int motor2_1 = 6;

int i;
void setup() {

pinMode(sensor, INPUT); // initialize sensor as an input


pinMode(motor1_0,OUTPUT);
pinMode(motor1_1,OUTPUT);
pinMode(motor2_0,OUTPUT);
pinMode(motor2_1,OUTPUT);
Serial.begin(9600);
}

void loop()

{
// put your main code here, to run repeatedly:

val = digitalRead(sensor); // read sensor value


if (val == HIGH)
{
Serial.println("Obstacle detected!");
// ROBOT STOP
digitalWrite(motor1_0,LOW); // motor stop
digitalWrite(motor1_1,LOW); // motor stop
digitalWrite(motor2_0,LOW); // motor stop
digitalWrite(motor2_1,LOW); // motor stop
delay(5000);
Serial.println("Motion STOPPED!");
// ROBOT BACKWARD
digitalWrite(motor1_0,HIGH); // enable on
digitalWrite(motor1_1,LOW); // enable on
digitalWrite(motor2_0,LOW); // enable on
digitalWrite(motor2_1,HIGH); // enable on
delay(5000);
Serial.println("Motion reversed!");
// ROBOT RIGHT
digitalWrite(motor1_0,HIGH); // enable on
digitalWrite(motor1_1,LOW); // enable on
digitalWrite(motor2_0,LOW); // enable on
digitalWrite(motor2_1,LOW); // enable on
delay(5000);
Serial.println("Motion right turn!");
// ROBOT FORWARD

digitalWrite(motor1_0,HIGH); // enable on
digitalWrite(motor1_1,LOW); // enable on
digitalWrite(motor2_0,LOW); // enable on
digitalWrite(motor2_1,HIGH); // enable on
Serial.println("Motion forward!");

}
else
{
digitalWrite(motor1_0,HIGH); // enable on
digitalWrite(motor1_1,LOW); // enable on
digitalWrite(motor2_0,LOW); // enable on
digitalWrite(motor2_1,HIGH); // enable on
Serial.println("Robot Moving!");
}
}

8. Construct a circuit to count visitors in a shopping mall.

const int in=8;


const int out=9;
int temp=0;
void setup()
{
Serial.begin(9600);
pinMode(in,INPUT);
pinMode(out,INPUT);
Serial.println("Visitor Counter");
}
void loop()
{
if(digitalRead(in)==1)
{
temp=temp+1;
Serial.print("No.of persons inside: ");
Serial.println(temp);
delay(500);
}
else if(digitalRead(out)==1)
{
temp=temp-1;
Serial.print("No.of persons out of room: ");
Serial.println(temp);
delay(500);
}
}

9. Construct a circuit for Traffic light controller with 60 Sec delay for each light.

void setup()
{
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}

void loop()
{
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(8, HIGH);
digitalWrite(11, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(10, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
delay(3000); // Wait for 1000 millisecond(s)
digitalWrite(7, HIGH);
digitalWrite(2, HIGH);
digitalWrite(8, HIGH);
digitalWrite(11, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(9, LOW);
digitalWrite(4, LOW);
digitalWrite(3, LOW);
digitalWrite(5, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
delay(3000); // Wait for 1000 millisecond(s)
}

10. Construct circuit to Interface the Motor with ultrasonic sensor, and if any obstacle then
motor should move in reverse direction , take left turn and move in forward direction.

int sensor = 7; // the pin that the sensor is atteched to


int state = 0; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)

int motor1_0 = 3;
int motor1_1 = 4;
int motor2_0 = 5;
int motor2_1 = 6;

int i;
void setup() {

pinMode(sensor, INPUT); // initialize sensor as an input


pinMode(motor1_0,OUTPUT);
pinMode(motor1_1,OUTPUT);
pinMode(motor2_0,OUTPUT);
pinMode(motor2_1,OUTPUT);
Serial.begin(9600);
}

void loop()

{
// put your main code here, to run repeatedly:

val = digitalRead(sensor); // read sensor value


if (val == HIGH)
{
Serial.println("Obstacle detected!");
// ROBOT STOP
digitalWrite(motor1_0,LOW); // motor stop
digitalWrite(motor1_1,LOW); // motor stop
digitalWrite(motor2_0,LOW); // motor stop
digitalWrite(motor2_1,LOW); // motor stop
delay(5000);
Serial.println("Motion STOPPED!");
// ROBOT BACKWARD
digitalWrite(motor1_0,HIGH); // enable on
digitalWrite(motor1_1,LOW); // enable on
digitalWrite(motor2_0,LOW); // enable on
digitalWrite(motor2_1,HIGH); // enable on
delay(5000);
Serial.println("Motion reversed!");
// ROBOT LEFT
digitalWrite(motor1_0,LOW); // enable on
digitalWrite(motor1_1,LOW); // enable on
digitalWrite(motor2_0,HIGH); // enable on
digitalWrite(motor2_1,LOW); // enable on
delay(5000);
Serial.println("Motion right turn!");
// ROBOT FORWARD

digitalWrite(motor1_0,HIGH); // enable on
digitalWrite(motor1_1,LOW); // enable on
digitalWrite(motor2_0,LOW); // enable on
digitalWrite(motor2_1,HIGH); // enable on
Serial.println("Motion forward!");

}
else
{
digitalWrite(motor1_0,HIGH); // enable on
digitalWrite(motor1_1,LOW); // enable on
digitalWrite(motor2_0,LOW); // enable on
digitalWrite(motor2_1,HIGH); // enable on
Serial.println("Robot Moving!");
}
}

You might also like