0% found this document useful (0 votes)
30 views13 pages

IOT Assingment

The document describes six experiments using Arduino and Raspberry Pi to control LEDs and other components. Experiment 1 introduces Arduino and basic LED blinking. Experiment 2 controls an RGB LED to change colors. Experiment 3 programs multiple LEDs with different patterns. Experiment 4 builds a smoke detector. Experiment 5 blinks an LED connected to Raspberry Pi. Experiment 6 creates a web server to control GPIO pins and LEDs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views13 pages

IOT Assingment

The document describes six experiments using Arduino and Raspberry Pi to control LEDs and other components. Experiment 1 introduces Arduino and basic LED blinking. Experiment 2 controls an RGB LED to change colors. Experiment 3 programs multiple LEDs with different patterns. Experiment 4 builds a smoke detector. Experiment 5 blinks an LED connected to Raspberry Pi. Experiment 6 creates a web server to control GPIO pins and LEDs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Page |1

Experiments Based on Arduino Programming

Experiment 1: Introduction to Arduino and Basic LED Control

Components:

1.Arduino board (e.g., Arduino Uno)

2.Breadboard

3.LED

4.Resistor (220 ohms)

5.Jumper wires

Procedure:

Step 1-Set up the Arduino board on the breadboard.

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.

Step 6-Write the code

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.

Experiment 2-RGB Colour Mixing with Arduino

Components:

1.Arduino board (e.g., Arduino Uno)

2.Breadboard

3.RGB LED (common cathode)

4.Resistors (220 ohms)

5.Jumper wires

Software Requirements:

Arduino IDE (Integrated Development Environment)

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.

Step 3-Launch the Arduino IDE on your computer.


Page |3

Step 5-Write the code

int redPin = 9;

int greenPin = 10;

int bluePin = 11;

void setup() {

pinMode(redPin, OUTPUT);

pinMode(greenPin, OUTPUT);

pinMode(bluePin, OUTPUT);

void loop() {

// Turn on the red LED

analogWrite(redPin, 255);

analogWrite(greenPin, 0);

analogWrite(bluePin, 0);

delay(2000); // 2-second delay

// Turn on the green LED

analogWrite(redPin, 0);

analogWrite(greenPin, 255);

analogWrite(bluePin, 0);

delay(2000); // 2-second delay

// Turn on the blue LED

analogWrite(redPin, 0);

analogWrite(greenPin, 0);
Page |4

analogWrite(bluePin, 255);

delay(2000); // 2-second delay

// Turn on the combination of red, green, and blue LEDs to create other colors

analogWrite(redPin, 255);

analogWrite(greenPin, 255);

analogWrite(bluePin, 0);

delay(2000); // 2-second delay

analogWrite(redPin, 0);

analogWrite(greenPin, 255);

analogWrite(bluePin, 255);

delay(2000); // 2-second delay

analogWrite(redPin, 255);

analogWrite(greenPin, 0);

analogWrite(bluePin, 255);

delay(2000); // 2-second delay

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.

Experiment 3- LED Controller with Arduino

Components:

1.Arduino board (e.g., Arduino Uno)

2.Breadboard

3.LEDs (multiple, as per your preference)

4.Resistors (220 ohms)

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.

Step 3-Launch the Arduino IDE on your computer.

Step 4-Write the code in the Arduino IDE-

int ledPin1 = 9;

int ledPin2 = 10;

void setup() {

pinMode(ledPin1, OUTPUT);

pinMode(ledPin2, OUTPUT);

void loop() {

// Blink LED1 (On/Off)

digitalWrite(ledPin1, HIGH);

delay(1000); // 1-second delay


Page |6

digitalWrite(ledPin1, LOW);

delay(1000); // 1-second delay

// Fade LED2 (Brightness Control)

for (int brightness = 0; brightness <= 255; brightness += 5) {

analogWrite(ledPin2, brightness);

delay(20); // Delay between each brightness increment

for (int brightness = 255; brightness >= 0; brightness -= 5) {

analogWrite(ledPin2, brightness);

delay(20); // Delay between each brightness decrement

// Alternate Blinking of LED1 and LED2

digitalWrite(ledPin1, HIGH);

digitalWrite(ledPin2, LOW);

delay(500); // 500 ms delay

digitalWrite(ledPin1, LOW);

digitalWrite(ledPin2, HIGH);

delay(500); // 500 ms delay

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.

Experiment 4-Smoke detection with MQ-2 detector

Components:

1. Arduino UNO

2. Breadboard (generic)
Page |7

3. MQ-2 Smoke detection sensor

4. Male/Female Jumper Wires

5. 5 mm LED: Red & Green

6.Buzzer

7.Resistor 221 ohm

Procedure:

Step 1-Set up the circuit according to the provided circuit diagram.

Pin Wiring

The MQ-2 sensor has 4 pins.

A0 pin is Analog pins,D0 pin is Digital pins,GND is Ground,VCC is supply of5V

Step 2-Connect the Arduino board to your computer using a USB cable.

Step 3-Launch the Arduino IDE on your computer.

Step 4-Write the code in the Arduino IDE-

int redLed = 12;

int greenLed = 11;

int buzzer = 10;

int smokeA0 = A5;

// Your threshold value

int sensorThres = 400;

void setup() {

pinMode(redLed, OUTPUT);

pinMode(greenLed, OUTPUT);

pinMode(buzzer, OUTPUT);

pinMode(smokeA0, INPUT);

Serial.begin(9600);

}
Page |8

void loop() {

int analogSensor = analogRead(smokeA0);

Serial.print("Pin A0: ");

Serial.println(analogSensor);

// Checks if it has reached the threshold value

if (analogSensor > sensorThres)

digitalWrite(redLed, HIGH);

digitalWrite(greenLed, LOW);

tone(buzzer, 1000, 200);

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

Experiment 5- LED Blinking with Rusberrypi

Objective: To control an LED connected to Raspberry Pi and make it blink.

Components:

1.Raspberry Pi board (e.g., Raspberry Pi 4 Model B)

2.Breadboard

3.LED

4.Resistor (220 ohms)

5.Jumper wires

Procedure:

Set up the circuit:

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.

Ensure proper connections and polarity.


P a g e | 10

Step 1-Connect the Raspberry Pi board to your computer using a USB cable.

Step 2-Launch a terminal on the Raspberry Pi or use SSH to access it remotely.

Step 3-Write the following code in a text editor or directly in the terminal:

import RPi.GPIO as GPIO

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 4-Save the file with a .py extension (e.g., led_blink.py).

Step 5-Run the Python script using the following command in the terminal:

“python3 led_blink.py”

Result-

Observe the LED blinking at a 1-second interval.

Experiment 6: Web Server and GPIO Control

Objective: To create a web server using Raspberry Pi and control GPIO pins through a web interface.

Components:

1.Raspberry Pi board (e.g., Raspberry Pi 4 Model B)

2.Breadboard
P a g e | 11

3.LEDs

4.Resistors (220 ohms)

5.Jumper wires

Procedure:

Set up the circuit:

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:

“pip3 install Flask”

Step 3-Write the following code in a text editor or directly in the terminal:

from flask import Flask, render_template

import RPi.GPIO as GPIO

app = Flask(__name__)

GPIO.setmode(GPIO.BCM)

led_pins = [17, 18, 19] # Change the GPIO pin numbers as per your circuit

for pin in led_pins:

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>')

def toggle(led_id, state):

GPIO.output(led_pins[led_id], state)

return 'LED state changed.'

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

<h3>LED {{ i+1 }}</h3>

<a href="/toggle/{{ i }}/1">Turn On</a>

<a href="/toggle/{{ i }}/0">Turn Off</a>

{% endfor %}

</body>

</html>

Step 5-Save both files.

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy