IOT Assingment
IOT Assingment
Components:
2.Breadboard
3.LED
5.Jumper wires
Procedure:
Step 2-Connect the longer leg (anode) of the LED to a digital pin (e.g., Pin 13) on the Arduino using a
resistor.
Step 3-Connect the shorter leg (cathode) of the LED to the ground (GND) pin on the Arduino.
Step 4-Connect the Arduino board to your computer using a USB cable.
Step 5-Launch the Arduino IDE (Integrated Development Environment) on your computer.
void setup() {
pinMode(13, OUTPUT);
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
Step 7- Click on the "Upload" button in the Arduino IDE to compile and upload the code to the
Arduino board.
Page |2
Circuit Diagram-
Result-Observe the LED blinking with a one-second delay between each state change.
Components:
2.Breadboard
5.Jumper wires
Software Requirements:
Procedure:
Step 1-Set up the circuit according to the provided circuit diagram. Connect the longer leg (anode) of
the RGB LED to digital pins on the Arduino (e.g., Pin 9, Pin 10, and Pin 11) using a 220-ohm resistor
for each pin. Connect the shorter leg (cathode) of the RGB LED to the common ground (GND) pin on
the Arduino.
Step 2-Connect the Arduino board to your computer using a USB cable.
int redPin = 9;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
void loop() {
analogWrite(redPin, 255);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);
analogWrite(redPin, 0);
analogWrite(greenPin, 255);
analogWrite(bluePin, 0);
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
Page |4
analogWrite(bluePin, 255);
// Turn on the combination of red, green, and blue LEDs to create other colors
analogWrite(redPin, 255);
analogWrite(greenPin, 255);
analogWrite(bluePin, 0);
analogWrite(redPin, 0);
analogWrite(greenPin, 255);
analogWrite(bluePin, 255);
analogWrite(redPin, 255);
analogWrite(greenPin, 0);
analogWrite(bluePin, 255);
Step 6-Verify the code for any errors and upload it to the Arduino board by clicking on the "Upload"
button in the Arduino IDE.
Circuit Diagram-
Page |5
Result-
RGB LED changing colors according to the sequence. Each colour will be displayed for a 2-second
duration.
Components:
2.Breadboard
5.Jumper wires
Procedure:
Step 1-Set up the circuit according to the provided circuit diagram. Connect the anode (longer leg) of
each LED to a digital pin on the Arduino (e.g., LED1 - Pin 9, LED2 - Pin 10) using a 220-ohm resistor
for each LED. Connect the cathodes (shorter legs) of the LEDs to the common ground (GND) pin on
the Arduino.
Step 2-Connect the Arduino board to your computer using a USB cable.
int ledPin1 = 9;
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
void loop() {
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin1, LOW);
analogWrite(ledPin2, brightness);
analogWrite(ledPin2, brightness);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
Step 5-Verify the code for any errors and upload it to the Arduino board by clicking on the "Upload"
button in the Arduino IDE.
Result-
Observe the LED control based on the programmed sequence. LED1 will blink on/off every 1 second,
LED2 will fade in/out gradually, and both LEDs will alternate blinking every 500 milliseconds.
Components:
1. Arduino UNO
2. Breadboard (generic)
Page |7
6.Buzzer
Procedure:
Pin Wiring
Step 2-Connect the Arduino board to your computer using a USB cable.
void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
Page |8
void loop() {
Serial.println(analogSensor);
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
else
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
noTone(buzzer);
delay(100);
Step 5-Verify the code for any errors and upload it to the Arduino board by clicking on the "Upload"
button in the Arduino IDE.
Result-
This project will sense the gas and start the bipping.
Page |9
Circuit Diagram
Components:
2.Breadboard
3.LED
5.Jumper wires
Procedure:
Connect the anode (longer leg) of the LED to a GPIO pin (e.g., GPIO17) on the Raspberry Pi using a
220-ohm resistor.
Connect the cathode (shorter leg) of the LED to the ground (GND) pin on the Raspberry Pi.
Step 1-Connect the Raspberry Pi board to your computer using a USB cable.
Step 3-Write the following code in a text editor or directly in the terminal:
import time
led_pin = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin, GPIO.OUT)
try:
while True:
GPIO.output(led_pin, GPIO.HIGH)
time.sleep(1)
GPIO.output(led_pin, GPIO.LOW)
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
Step 5-Run the Python script using the following command in the terminal:
“python3 led_blink.py”
Result-
Objective: To create a web server using Raspberry Pi and control GPIO pins through a web interface.
Components:
2.Breadboard
P a g e | 11
3.LEDs
5.Jumper wires
Procedure:
Connect an LED to a GPIO pin (e.g., GPIO17) on the Raspberry Pi using a 220-ohm resistor.
Repeat the above step to connect additional LEDs to other GPIO pins.
Step 1 -Access the Raspberry Pi terminal either by connecting a monitor and keyboard directly or
using SSH.
Step 2-Install Flask (a Python web framework) by running the following command in the terminal:
Step 3-Write the following code in a text editor or directly in the terminal:
app = Flask(__name__)
GPIO.setmode(GPIO.BCM)
led_pins = [17, 18, 19] # Change the GPIO pin numbers as per your circuit
GPIO.setup(pin, GPIO.OUT)
@app.route('/')
def index():
return render_template('index.html')
P a g e | 12
@app.route('/toggle/<int:led_id>/<int:state>')
GPIO.output(led_pins[led_id], state)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
Step 4-Create a new folder called "templates" and create a new file named "index.html" inside the
templates folder. Add the following code to index.html:
<!DOCTYPE html>
<html>
<head>
<title>GPIO Control</title>
</head>
<body>
<h1>GPIO Control</h1>
{% for i in range(3) %}
{% endfor %}
</body>
</html>
Step 6-Run the Python script using the following command in the terminal:
“python3 server.py”
Step 7-Access the web server by entering the Raspberry Pi's IP address in a web browser on any
device connected to the same network.
P a g e | 13
Result-
Use the web interface to control the LEDs by turning them on and off.