IOT RECORD - pdf2
IOT RECORD - pdf2
Aim:
Write aprogram to find the average of three numbers
Program:
Output:
Enter the first number:1
Enter the second
number:2 Enter the
third number:3
Result:
EVEN OR NOT
Aim:
Write aprogram to check whether the given number is even or not.
Program:
num =int(input("Enter the number:"))
if num %2== 0:
OUTPUT:
Enter the
number:6 6is an
even number
Result:
Experiment 3
Aim:
Program:
Output:
Result:
Aim:
13
Program:
Output:
Enter the first number:10
Enter the second number:30
Enter the third number:20
Result:
The above program is executed and the output is obtained.
4
Experiment 5
Aim:
Program:
import turtle
t=turtle.Turtle()
s=int(input("Enter the length of the square: "))
turtle.done()
Output:
Enter the length of the square :200
Result:
15
Experiment 6
Aim:
Program:
import turtle
t=turtle.Turtle()
turtle.done()
Output:
Enter the length of the rectangle :500
Enter the breadth of the rectangle :200
Result:
6
Experiment 7
Components:
Arduino Board (e.g., Arduino Uno)
USB Cable
Breadboard
Jumper Wires
Procedure:
1. Examine the Arduino board, identifying components such as the
microcontroller, digital and analog pins, power jack, USB port, and reset
button.
2. Connect the Arduino board to acomputer using the USB cable.
3. Open the Arduino IDE on the computer.
4. Write asimple code to blink an LED connected to pin 13.
5. Upload the code to the Arduino board.
6. Observe the onboard LED (connected to pin 13) and external LED (if
used): Onboard LED and external LED (if used) blinking on and off.
17
Experiment 8
Components:
Arduino Board
LED (Light Emitting Diode)
Resistor (220-330 ohms)
Jumper Wires
Procedure:
1. Connect the anode (+) of the LED to adigital pin on the Arduino through
acurrent-limiting resistor.
2. Connect the cathode (-) of the LED to the ground (GND) on the Arduino.
3. Upload the following Arduino code to the board.
4. Observe the LED blinking on and off.
Arduino Code:
void setup()
{ pinMode(LED_BUILTIN, OUTPUT); // Set the LED pin as an
output
}
void loop()
{ digitalWrite(LED_BUILTIN, HIGH); // Turn on the LED
delay(1000); // Wait for 1second
digitalWrite(LED_BUILTIN, LOW); // Turn off the LED delay(1000);
// Wait for 1second
}
Output:
8
The LED connected to the specified pin will blink on and off at 1-second
intervals.
Result:
Successful implementation of abasic Arduino program to blink one led.
Experiment 9
Components:
Arduino board
3LEDs (Red, Yellow, Green)
3current-limiting resistors
Breadboard
Jumper wires
Procedure:
1. Connect the LEDs to the Arduino board with appropriate current-
limiting resistors.
2. Write an Arduino program to control the LEDs, simulating the traffic
light sequence (red, red-yellow, green, yellow, repeat).
3. Upload the program to the Arduino using the Arduino IDE.
4. Power the Arduino board.
Arduino Code:
int red =9;
int yellow
=8; int green
=7; void
setup()
{ pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
9
pinMode(green, OUTPUT);
}
void loop()
{ digitalWrite(red,
HIGH) delay(15000);
digitalWrite(red,
LOW);
digitalWrite(yellow,
HIGH); delay(1000);
digitalWrite(yellow,
LOW); delay(500);
digitalWrite(green, HIGH);
delay(20000);
digitalWrite(green, LOW);
delay(500);
Output:
The LEDs will display asimulated traffic light sequence, cycling through the
phases of red, red-yellow, and green, with appropriate delays to mimic atypical
traffic light.
Result:
10
Experiment 10
Aim:
To design asimple Arduino experiment utilizing an IR sensor to detect
obstacles and provide avisual output.
Components:
Arduino Uno
IR Sensor Module
Jumper Wires
Breadboard
LEDs (Red and Green)
Resistors (220 ohms)
Power Supply (9V)
Procedure:
1. Connect the IR Sensor VCC to Arduino 5V, GND to GND, and Signal to
Arduino digital pin 2.
2. Connect the Red LED's anode to Arduino digital pin 3through a220-ohm
resistor and cathode to GND.
3. Connect the Green LED's anode to Arduino digital pin 4through a220-ohm
resistor and cathode to GND.
4. Power the Arduino Uno using the 9V power supply.
5. Write acode to read IR sensor data and control the LEDs accordingly. (See
code below)
6. Upload the code to the Arduino using the Arduino IDE.
7. Observe the LEDs:
Red LED ON indicates obstacle detection.
Green LED ON indicates no obstacle.
Code:
void loop()
{
int obstacle =digitalRead(irSensorPin);
if (obstacle == HIGH)
{ digitalWrite(redLedPin, HIGH);
digitalWrite(greenLedPin,
LOW);
Serial.println("Obstacle detected!");
}
else
{ digitalWrite(redLedPin, LOW);
digitalWrite(greenLedPin,
HIGH);
Serial.println("No obstacle detected.");
}
delay(500);
}
Output: Visual indication using LEDs (Red LED for obstacle detected, Green LED
for no obstacle).
12
Experiment 11
Aim: To create an Arduino experiment utilizing aPIR sensor for detecting motion
and triggering aresponse.
Components:
Arduino Uno
PIR (Passive Infrared) Sensor Module
Jumper Wires
LEDs (any color)
Resistors (220 ohms)
Breadboard
Power Supply (9V)
Procedure:
1. Connect PIR Sensor VCC to Arduino 5V, GND to GND, and OUT to Arduino
digital pin 2.
2. Connect the anode of the LED to Arduino digital pin 3through a220-ohm
resistor and the cathode to GND.
4. Write acode to read PIR sensor data and control the LED when motion is
detected. (See code below)
13
void setup()
{ pinMode(pirSensorPin,
INPUT); pinMode(ledPin,
OUTPUT); Serial.begin(9600);
}
void loop()
{ int motion
=digitalRead(pirSensorPin);
if (motion == HIGH)
{ digitalWrite(ledPin,
HIGH);
Serial.println("Motion detected!");
}
else
{ digitalWrite(ledPin,
LOW);
Serial.println("No motion detected.");
}
delay(500);
}
Result: The experiment successfully demonstrates the use of aPIR sensor for
motion detection, triggering an LED response based on sensor readings
Experiment 12
Aim: To design an Arduino experiment using an MQ-7 gas sensor for detecting
and displaying the concentration of combustible gases.
Components:
Arduino Uno
MQ-7 Gas Sensor Module
14
Jumper Wires
Breadboard
Power Supply (9V)
Procedure:
1. Connect the MQ-7 sensor VCC to Arduino 5V, GND to GND, Analog OUT to
Arduino analog pin A0, and Digital OUT to Arduino digital pin 2.
3. Write acode to read MQ-7 sensor data, detect gas presence, and display it
on the serial monitor. (See code below)
void setup()
{ pinMode(mq7DigitalPi
n,
INPUT); Serial.begin(9600);
}
void loop()
{ int gasConcentration
=analogRead(mq7AnalogPin); int gasPresence
=digitalRead(mq7DigitalPin);
if (gasPresence == HIGH)
{
Serial.println("Gas Detected!");
}
15
delay(1000);
}
Output: Real-time gas concentration displayed on the LCD; "Gas Detected!"
message on Serial Monitor if gas is present.
FAMILIARIZATION OF RASPBERRY PI
Procedure:
Raspberry Pi processor :
It has ARM based Broadcom Processor SoC along with on-chip GPU (Graphics
Processing Unit).The CPU speed of Raspberry Pi varies from 700 MHz to 1.2 GHz.
Also, it has on-board SDRAM that ranges from 256 MB to 1GB. Raspberry Pi also
provides on-chip SPI, I2C, I2S and UART modules.
PIN DIAGRAM:
16
ARaspberry Pi 4board has 40 pins on it. Among these pins, we have four power
pins on the Raspberry Pi, two of which are 5v pins and another two are 3.3v pins.
The 5v power pins are connected directly to the Raspberry Pi's power input and
we can use these pins to run low power applications
5V pins: The 5V pins are used to output the 5V power supply provided by
the Type-C port. The pins are numbered 2and 4on the Raspberry Pi
4device.
3.3V pins: The 3.3V pins provide a3.3V power supply to the external
components, numbered 1and 17.
Ground pins: The ground pins are used to close the electric circuits. The
ground pins help you to protect your board from burning and play an
important part in a circuit. The ground pins are numbered
6,9,14,20,25,30,34 and 39.
17
IR SENSOR CONTROL USING RASPBERRY PI WITH PYTHON APPLICATION
Components:
Raspberry Pi (any model with GPIO pins)
IR Sensor Module
Jumper Wires
Procedure:
1. Connect the IR Sensor's VCC to 5V, GND to GND, and Signal to aGPIO pin
(e.g., GPIO17) on the Raspberry Pi.
3. Write aPython script to read data from the IR sensor and control an output
(e.g., GPIO18).
Python code :
import RPi.GPIO as
GPIO import time
GPIO.setmode(GPIO.BCM)
ir_sensor_pin =17
led_pin =18
GPIO.setup(ir_sensor_pin, GPIO.IN)
GPIO.setup(led_pin, GPIO.OUT)
try:
18
while True:
if GPIO.input(ir_sensor_pin) == GPIO.HIGH:
print("Object detected!") GPIO.output(led_pin, GPIO.HIGH)
else:
print("No object detected.")
GPIO.output(led_pin, GPIO.LOW)
time.sleep(1)
except
KeyboardInterrupt:
GPIO.cleanup()
Output: Console messages indicating object detection status and LED turning
ON/OFF accordingly.
19