Internet of Things Labaratory
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.
}
}
}
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);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
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.
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.
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 motor1_0 = 3;
int motor1_1 = 4;
int motor2_0 = 5;
int motor2_1 = 6;
int i;
void setup() {
void loop()
{
// put your main code here, to run repeatedly:
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!");
}
}
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 motor1_0 = 3;
int motor1_1 = 4;
int motor2_0 = 5;
int motor2_1 = 6;
int i;
void setup() {
void loop()
{
// put your main code here, to run repeatedly:
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!");
}
}