Professional Documents
Culture Documents
Course Objectives:
To introduce the raspberry PI platform, that is widely used in IoT applications
To introduce the implementation of distance sensor on IoT devices
Course Outcomes:
Ability to introduce the concept of M2M (machine to machine) with necessary protocols and get
awareness in implementation of distance sensor
Get the skill to program using Python Scripting Language which is used in many IoT devices
Experiments:
1. Getting started with Raspberry Pi, Install Raspian on your SD card
2. Python-based IDE (integrated development environments) for the Raspberry Pi and how to trace and
debug Python code on the device
3. Using Raspberry pi
a. Calculate the distance using distance sensor.
b. Basic LED functionality.
4. Raspberry Pi interact with online services through the use of public APIs and SDKs
5. Using Arduino
a. Calculate the distance using distance sensor.
b. Basic LED functionality.
c. Calculate temperature using temperature sensor
6. Using Node MCU
a. Calculate the distance using distance sensor.
b. Basic LED functionality.
ADDITIONAL EXPERIMENTS
7) DHT11 Temperature and Humidity sensor Interfacing with Arduino Uno and display output on LCD
8) StreetLight Automation using LDR sensor
9) OLED Inerfacing with Arduino Uno and display graphical Information
To get started with your Raspberry Pi, you’ll need the following:
a power supply
boot media (e.g. a microSD card with ample storage and speed)
You can set up your Raspberry Pi as an interactive computer with a desktop, or as a headless computer
accessible only over the network. To set your Raspberry Pi up headless, you don’t need any additional
peripherals; you can preconfigure a hostname, user account, network connection, and SSH when
you install an operating system. If you want to use your Raspberry Pi directly, you’ll need the following
additional accessories:
a display
a keyboard
a mouse
Power Supply
The following table shows the USB-PD power mode required to power various Raspberry Pi models.
You can use any high quality power supply that provides the correct power mode.
Raspberry Pi 5 5V/5A, 5V/3A limits peripherals to 600mA 27W USB-C Power Supply
Plug your power supply into the port marked "POWER IN", "PWR IN", or "PWR". Some Raspberry Pi
models, such as the Zero series, have output USB ports with the same form factor as the power port. Be
sure to use the correct port on your Raspberry Pi!
Boot Media
Raspberry Pi models lack onboard storage, so you have to supply it. You can boot your Raspberry Pi
from an operating system image installed on any supported media: commonly microSD cards, but also
USB storage, network storage, and storage connected via a PCIe HAT. However, only recent Raspberry
Pi models support all of these media types.
All Raspberry Pi consumer models since the Raspberry Pi 1 Model A+ feature a microSD slot. Your
Raspberry Pi automatically boots from the microSD slot when the slot contains a card.
Recommended SD cards
We recommend using an SD card with at least 16GB of storage with Raspberry Pi OS. If you use
Raspberry Pi OS Lite, we recommend at least 4GB.
Because of a hardware limitation, the following devices will only boot from a boot partition of 256GB
or less:
Raspberry Pi Zero
Raspberry Pi 1
Other operating systems have different requirements. Check the documentation for your operating
system for capacity requirements.
Keyboard
You can use any of the USB ports on your Raspberry Pi to connect a wired keyboard or USB Bluetooth
receiver.
Mouse
You can use any of the USB ports on your Raspberry Pi to connect a wired mouse or USB Bluetooth
receiver.
Display
If your Raspberry Pi has more than one HDMI ports, plug your primary monitor into the port
marked HDMI0.
Raspberry Pi 4 (all models) 2x micro HDMI, audio and composite out via 3.5mm TRRS jack
Raspberry Pi 3 (all models) HDMI, audio and composite out via 3.5mm TRRS jack
Raspberry Pi 2 (all models) HDMI, audio and composite out via 3.5mm TRRS jack
Raspberry Pi 1 Model B+ HDMI, audio and composite out via 3.5mm TRRS jack
Audio
All Raspberry Pi models with HDMI, micro HDMI, or mini HDMI support audio output over HDMI.
All Raspberry Pi models support audio over USB. All Raspberry Pi models equipped with Bluetooth
support Bluetooth audio. All variants of the Raspberry Pi 1, 2, 3, and 4 include a 3.5mm
auxiliary TRRS jack which may require amplification for sufficient output volume.
Networking
The following Raspberry Pi models come with WiFi and Bluetooth connectivity:
Raspberry Pi 5
Raspberry Pi 4
Raspberry Pi 3B+
Raspberry Pi 3
Rsapberry Pi Zero 2 W
The "Model B" suffix indicates variants with an Ethernet port; "Model A" indicates no Ethernet port. If
your model doesn’t have an Ethernet port, you can still connect to a wired internet connection using a
USB-to-Ethernet adapter.
To use your Raspberry Pi, you’ll need an operating system. By default, Raspberry Pis check for an
operating system on any SD card inserted in the SD card slot.
Depending on your Raspberry Pi model, you can also boot an operating system from other storage
devices, including USB drives, storage connected via a HAT, and network storage.
To install an operating system on a storage device for your Raspberry Pi, you’ll need:
a computer you can use to image the storage device into a boot device
Imager supports images packaged in the .img format as well as container formats like .zip.
If you have no other computer to write an image to a boot device, you may be able to install an
operating system directly on your Raspberry Pi from the internet.
Download the latest version from raspberrypi.com/software and run the installer.
Install it from a terminal using your package manager, e.g. sudo apt install rpi-imager.
Once you’ve installed Imager, launch the application by clicking the Raspberry Pi Imager icon or
running rpi-imager.
Click Choose device and select your Raspberry Pi model from the list.
Next, click Choose OS and select an operating system to install. Imager always shows the
recommended version of Raspberry Pi OS for your model at the top of the list.
Connect your preferred storage device to your computer. For example, plug a microSD card in using an
external or built-in SD card reader. Then, click Choose storage and select your storage device.
In a popup, Imager will ask you to apply OS customisation. We strongly recommend configuring your
Raspberry Pi via the OS customisation settings. Click the Edit Settings button to open OS
customisation.
If you don’t configure your Raspberry Pi via OS customisation settings, Raspberry Pi OS will ask you
for the same information at first boot during the configuration wizard. You can click the No button to
skip OS customisation.
OS customisation
The OS customisation menu lets you set up your Raspberry Pi before first boot. You can preconfigure:
WiFi credentials
remote connectivity
Department of CSE-IoT III B-Tech I Sem 12 | P a g e
Internet of Things (IoT Lab) Aditya College of Engineering
When you first open the OS customisation menu, you might see a prompt asking for permission to load
WiFi credentials from your host computer. If you respond "yes", Imager will prefill WiFi credentials
from the network you’re currently connected to. If you respond "no", you can enter WiFi credentials
manually.
The hostname option defines the hostname your Raspberry Pi broadcasts to the network using mDNS.
When you connect your Raspberry Pi to your network, other devices on the network can communicate
with your computer using <hostname>.local or <hostname>.lan.
The username and password option defines the username and password of the admin user account on
your Raspberry Pi.
The wireless LAN option allows you to enter an SSID (name) and password for your wireless network.
If your network does not broadcast an SSID publicly, you should enable the "Hidden SSID" setting. By
default, Imager uses the country you’re currently in as the "Wireless LAN country". This setting
controls the WiFi broadcast frequencies used by your Raspberry Pi. Enter credentials for the wireless
LAN option if you plan to run a headless Raspberry Pi.
The locale settings option allows you to define the time zone and default keyboard layout for your Pi.
The Services tab includes settings to help you connect to your Raspberry Pi remotely.
If you plan to use your Raspberry Pi remotely over your network, check the box next to Enable SSH.
You should enable this option if you plan to run a headless Raspberry Pi.
Choose the password authentication option to SSH into your Raspberry Pi over the network
using the username and password you provided in the general tab of OS customisation.
OS customisation also includes an Options menu that allows you to configure the behaviour of Imager
during a write. These options allow you to play a noise when Imager finishes verifying an image, to
automatically unmount storage media after verification, and to disable telemetry.
Write
When you’ve finished entering OS customisation settings, click Save to save your customisation.
Then, click Yes to apply OS customisation settings when you write the image to the storage device.
Finally, respond Yes to the "Are you sure you want to continue?" popup to begin writing data to the
storage device.
If you see an admin prompt asking for permissions to read and write to your storage medium, it’s safe
to proceed.
Grab a cup of coffee or go for a walk. This could take a few minutes.
If you want to live especially dangerously, you can click cancel verify to skip the verification process.
When you see the "Write Successful" popup, your image has been completely written and verified.
You’re now ready to boot a Raspberry Pi from the storage device!
Next, proceed to the first boot configuration instructions to get your Raspberry Pi up and running.
If you used OS customisation in Imager to preconfigure your Raspberry Pi, congratulations! Your
device is ready to use. Proceed to next steps to learn how you can put your Raspberry Pi to good use.
If your Raspberry Pi does not boot within 5 minutes, check the status LED. If it’s flashing, see the LED
warning flash codes for more information. If your Pi refuses to boot, try the following mitigation steps:
if you used a boot device other than an SD card, try booting from an SD card
re-image your SD card; be sure to complete the entire verify step in Imager
update the bootloader on your Raspberry Pi, then re-image your SD card
If you chose to skip OS customisation in Imager, your Raspberry Pi will run a configuration wizard on
first boot. You need a monitor and keyboard to navigate through the wizard; a mouse is optional.
Bluetooth
If you’re using a Bluetooth keyboard or mouse, this step will walk you through device pairing. Your
Raspberry Pi will scan for pairable devices and connect to the first device it finds for each item.
This process works with built-in or external USB Bluetooth adapters. If you use a USB adapter, plug it
in before booting your Raspberry Pi.
Locale
This page helps you configure your country, language, and time zone, and keyboard layout.
User
This page helps you configure the username and password for the default user account.
By default, older versions of Raspberry Pi OS set the username to "pi". If you use the username "pi",
avoid the old default password of "raspberry" to keep your Raspberry Pi secure.
Wi-Fi
Department of CSE-IoT III B-Tech I Sem 22 | P a g e
Internet of Things (IoT Lab) Aditya College of Engineering
This page helps you connect to a WiFi network. Choose your preferred network from the list.
Browser
This page lets you select Firefox or Chromium as your default internet browser. You can optionally
uninstall the browser you don’t set as default.
Software updates
Once your Raspberry Pi has internet access, this page helps you update your operating system and
software to the latest versions. During the software update process, the wizard will remove the non-
default browser if you opted to uninstall it in the browser selection step. Downloading updates may take
several minutes.
When you see a popup indicating that your system is up to date, click OK to proceed to the next step.
Finish
At the end of the configuration wizard, click Restart to reboot your Raspberry Pi. Your Raspberry Pi
will apply your configuration and boot to the desktop.
RESULT: Hence we have studied on getting started with raspberry Pi and installation of Rasbian OS
on SD card.
IDLE (Integrated Development and Learning Environment) is a simple, lightweight Python IDE that
comes bundled with the standard Python distribution. It's designed to be easy to use, making it a good
choice for beginners and those who prefer a straightforward development environment. While IDLE is
not as feature-rich as some other IDEs, it provides essential tools for writing, running, and debugging
Python code on the Raspberry Pi.
IDLE Features:
Editor:
The IDLE editor allows you to write and edit Python code.
Syntax highlighting helps you identify code elements visually.
Automatic indentation improves code readability.
Shell:
IDLE includes an interactive Python shell, allowing you to execute Python commands and test code
snippets interactively.
Debugger:
IDLE comes with a basic debugger that allows you to set breakpoints, step through code, and inspect
variables.
Debugging in IDLE can be initiated by selecting "Debug" from the "Run" menu.
Integrated Documentation:
IDLE integrates documentation directly into the IDE, making it easy to access information about
Python functions and modules.
Tracing and Debugging in IDLE:
Here's a basic guide on how to trace and debug Python code using IDLE on the Raspberry Pi:
Open IDLE:
Launch IDLE by opening a terminal and typing idle or by navigating to the Programming menu in the
Raspberry Pi desktop environment.
Open or Create a Python Script:
Use the IDLE editor to open an existing Python script or create a new one.
Set Breakpoints:
Place breakpoints in your code by clicking on the left margin of the editor at the line where you want to
pause execution.
Run in Debug Mode:
Select "Debug" from the "Run" menu to start debugging your script.
Alternatively, you can use the F5 key as a shortcut for starting the debugger.
Debugging Controls:
While debugging, you can inspect the values of variables by hovering over them or by checking the
"Variables" window.
Exit Debug Mode:
When you're done debugging, you can exit debug mode by selecting "Exit" from the "Run" menu.
Limitations of IDLE:
While IDLE is a simple and accessible IDE, it has some limitations:
Basic Features:
IDLE lacks some of the advanced features found in other IDEs, such as Visual Studio Code or
PyCharm.
For more advanced debugging capabilities or features, users might consider exploring other IDEs like
Thonny or Visual Studio Code on the Raspberry Pi. These IDEs offer more sophisticated tools and a
broader range of features for Python development.
RESULT: Hence we have studied Python-based IDE (integrated development environments) for the
Raspberry Pi and how to trace and debug Python code on the Raspberry Pi.
3. Using Raspberry pi
a. Calculate the distance using distance sensor.
b. Basic LED functionality.
WORKING PRINCIPLE:
The ultrasonic sensor uses a technique called “ECHO”. “ECHO” is simply a reflected sound wave. You
will have an ECHO when sound reflects back after reaching a dead end.
HCSR04 module generates a sound vibration in ultrasonic range when we make the ‘Trigger’ pin high
for about 10us which will send a 8 cycle sonic burst at the speed of sound and after striking the object,
it will be received by the Echo pin. Depending on time taken by sound vibration to get back, it provides
appropriate pulse output. If the object is far away then it takes more time for ECHO to be heard and the
output pulse width will be big. And if the obstacle is near, then the ECHO will be heard faster and
output pulse width will be smaller.
The value is divided by two since the wave travels forward and backward covering the same distance.
Thus the time to reach obstacle is just half the total time taken
Procedure:
Complete working of Raspberry Pi Distance Measure goes as,
2. Sound wave is sent by the sensor. After receiving the ECHO, sensor module provides an output
proportional to distance.
3. We will record the time when the output pulse goes from LOW to HIGH and when again when its
goes form HIGH to LOW.
4. We will have start and stop time. We will use distance equation to calculate the distance.
Accordingly we have written the Python Program for Raspberry Pi to do the following functions:
CODE
import time
import RPi.GPIO as IO #calling for header file which helps in using GPIOs of PI
string_of_characters = 0
IO.setwarnings(False) #do not show any warnings
IO.setmode (IO.BCM) #programming the GPIO by BCM pin numbers. (like PIN29 as GPIO5)
IO.setup(17,IO.OUT) #initialize GPIO17,27,24,23,18,26,5,6,13,19,21 as an output
IO.setup(27,IO.OUT)
IO.setup(24,IO.OUT)
IO.setup(23,IO.OUT)
IO.setup(18,IO.OUT)
IO.setup(26,IO.OUT)
IO.setup(5,IO.OUT)
IO.setup(6,IO.OUT)
IO.setup(13,IO.OUT)
IO.setup(19,IO.OUT)
IO.setup(21,IO.OUT)
IO.setup(16,IO.IN) #initialize GPIO16 as an input
def send_a_command (command): #steps for sending a command to 16x2 LCD
pin=command
PORT(pin);
IO.output(17,0)
#PORTD&= ~(1<<RS);
IO.output(27,1)
#PORTD|= (1<<E);
time.sleep(0.001)
#_delay_ms(50);
IO.output(27,0)
#PORTD&= ~(1<<E);
pin=0
PORT(pin);
def send_a_character (character): #steps for sending a character to 16x2 LCD
pin=character
PORT(pin);
IO.output(17,1)
#PORTD|= (1<<RS);
IO.output(27,1)
#PORTD|= (1<<E);
time.sleep(0.001)
#_delay_ms(50);
IO.output(27,0)
#PORTD&= ~(1<<E);
pin=0
PORT(pin);
def send_a_string(string_of_characters):
string_of_characters = string_of_characters.ljust(16," ")
for i in range(16):
send_a_character(ord(string_of_characters[i])) #send characters one by one through data port
while 1:
while (IO.input(16)==0):
start = time.time() #store the start time of pulse output
while (IO.input(16)==1):
stop = time.time() #store the stop time
if(distance>400): #If distance is more than 400cm, just print 400+ on LCD
send_a_command(0x80 + 0);
send_a_string ("Dist= 400+ cm");
time.sleep(0.15)
RESULT: Hence the distance measurement is done by interfacing Ultrasonic sensor with raspberry pi .
APPARATUS REQUIRED:
PROCEDURE:
Connect the longer leg (anode) of the LED to a GPIO pin on the Raspberry Pi using a resistor.
Connect the shorter leg (cathode) of the LED to the ground (GND) pin on the Raspberry Pi.
Ensure that the Raspberry Pi is powered on.
Write a Python script to control the GPIO pin:
CODE
python
Copy code
import RPi.GPIO as GPIO
import time
RESULT:
Upon execution of the script, the LED should light up for 2 seconds and then turn off. This
demonstrates the basic functionality of interfacing an LED with a Raspberry Pi using GPIO pins and
programming in Python.
4. Raspberry Pi interact with online services through the use of public APIs and
SDKs
AIM:
To demonstrate the capability of Raspberry Pi in interacting with online services through the use of
public APIs and Software Development Kits (SDKs).
APPARATUS REQUIRED:
PROCEDURE:
Set up the Raspberry Pi with the required peripherals and ensure it has internet connectivity.
Identify and select online services with public APIs and SDKs that are relevant to the project (e.g.,
weather service, social media, cloud storage).
Install the necessary libraries and SDKs on the Raspberry Pi.
Develop a Python script on the Raspberry Pi to interact with the chosen online services using the
respective APIs and SDKs.
Implement functionalities such as fetching weather data, posting to social media, or uploading data to a
cloud storage service.
Test the script and debug if necessary.
Document the procedure and any challenges faced during the integration process.
Department of CSE-IoT III B-Tech I Sem 40 | P a g e
Internet of Things (IoT Lab) Aditya College of Engineering
CODE:
# Python script for interacting with a weather API
import requests
if response.status_code == 200:
weather_data = response.json()
return weather_data
else:
return None
# Example usage
api_key = 'your_openweathermap_api_key'
city = 'New York'
weather_info = get_weather(api_key, city)
print(weather_info)
RESULT:
The Raspberry Pi successfully interacts with online services through the use of public APIs and SDKs.
The results may include weather information, social media posts, or uploaded data to cloud storage,
depending on the chosen online services. The experiment demonstrates the versatility of Raspberry Pi
in connecting with external services and retrieving or sending data.
5. Using Arduino
a. Calculate the distance using distance sensor.
b. Basic LED functionality.
c. Calculate temperature using temperature sensor
AIM:
To design and implement a distance measurement system using an ultrasonic sensor interfaced with
an Arduino Uno.
APPARATUS REQUIRED:
PROCEDURE:
Connect the VCC pin of the ultrasonic sensor to the 5V pin on the Arduino Uno.
Connect the GND pin of the ultrasonic sensor to the GND pin on the Arduino Uno.
Connect the Trig pin of the ultrasonic sensor to digital pin 2 on the Arduino Uno.
Connect the Echo pin of the ultrasonic sensor to digital pin 3 on the Arduino Uno.
Connect the Arduino Uno to the computer using a USB cable.
Open the Arduino IDE on the computer.
CODE:
long duration;
int distance;
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
}
void loop(){
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
Serial.print("Distance in CM:");
Serial.println(distance);
delay(600);
}
RESULT: The Arduino Uno successfully interfaces with the ultrasonic sensor to measure the
distance of an object. The distance is displayed on the Serial Monitor in centimeters. The
experiment demonstrates the practical application of ultrasonic sensors for distance measurement
and the ability of Arduino Uno to interface with external sensors for various engineering purposes.
APPARATUS REQUIRED:
PROCEDURE:
Connect the longer leg (anode) of the LED to digital pin 13 on the Arduino Uno.
Connect the shorter leg (cathode) of the LED to the resistor.
Connect the other end of the resistor to the GND (ground) pin on the Arduino Uno.
Connect the Arduino Uno to the computer using a USB cable.
Open the Arduino IDE on the computer.
Write a program to control the LED state (ON or OFF) by toggling the digital pin 13.
Upload the program to the Arduino Uno.
Observe the LED turning ON and OFF based on the program logic.
CODE:
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
RESULT:
The LED connected to digital pin 13 on the Arduino Uno should alternately turn ON and OFF at 1-
second intervals. The experiment demonstrates the basic concept of interfacing an LED with
Arduino and controlling its state using a simple Arduino program. This foundational experiment is
often the starting point for more complex projects involving LEDs and other electronic components.
AIM:
To measure and display the temperature using a DHT11 sensor interfaced with an Arduino Uno.
APPARATUS REQUIRED:
PROCEDURE:
Connect the VCC pin of the DHT11 sensor to the 5V pin on the Arduino Uno.
Connect the GND pin of the DHT11 sensor to the GND pin on the Arduino Uno.
Connect the DATA pin of the DHT11 sensor to digital pin 2 on the Arduino Uno.
Connect a 10kΩ resistor between the VCC and DATA pins of the DHT11 sensor.
Connect the Arduino Uno to the computer using a USB cable.
Open the Arduino IDE on the computer.
Install the DHT sensor library in the Arduino IDE.
Write a program to read the temperature from the DHT11 sensor and display it on the Serial Monitor.
Upload the program to the Arduino Uno.
Observe the temperature readings on the Serial Monitor.
Department of CSE-IoT III B-Tech I Sem 47 | P a g e
Internet of Things (IoT Lab) Aditya College of Engineering
CODE:
#include <dht.h>
#include<LiquidCrystal.h>
#define DHT11_PIN 10
dht DHT;
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
Serial.println("Display Temperature and Humidity on Serial Monitor");
}
void loop()
{
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature");
Serial.print(DHT.temperature);
Serial.print(" Humidity:");
Serial.println(DHT.humidity);
lcd.setCursor(0,0);
lcd.print("TMP: ");
lcd.setCursor(0,1);
lcd.print("Hum: ");
lcd.setCursor(4,0);
lcd.print(DHT.temperature);
lcd.setCursor(4,1);
lcd.print(DHT.humidity);
delay(500);
}
RESULT:
The Arduino Uno successfully interfaces with the DHT11 sensor, reads the temperature data, and
displays it on the Serial Monitor. The temperature readings are updated every 2 seconds. The
experiment demonstrates the practical application of DHT11 sensors for temperature measurement and
the ability of Arduino Uno to interface with external sensors for real-world applications.
APPARATUS REQUIRED:
PROCEDURE:
Connect the VCC pin of the ultrasonic sensor to the 5V pin on the NodeMCU.
Connect the GND pin of the ultrasonic sensor to the GND pin on the NodeMCU.
Connect the Trig pin of the ultrasonic sensor to digital pin D1 on the NodeMCU.
Connect the Echo pin of the ultrasonic sensor to digital pin D2 on the NodeMCU.
Connect the NodeMCU to the computer using a USB to Micro-USB cable.
Open the Arduino IDE on the computer.
Install the necessary board and library support for NodeMCU in the Arduino IDE.
Write a program to read the distance from the ultrasonic sensor and print it to the Serial Monitor.
// Arduino code for Ultrasonic sensor interfacing with NodeMCU and Serial Monitor display
#include <ESP8266WiFi.h>
void setup() {
Serial.begin(115200);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
AIM:
To interface an LED with NodeMCU and design a program to make the LED blink.
APPARATUS REQUIRED:
PROCEDURE:
Connect the longer leg (anode) of the LED to digital pin D1 on the NodeMCU.
Connect the shorter leg (cathode) of the LED to a 220-ohm resistor.
Connect the other end of the resistor to the GND (ground) pin on the NodeMCU.
Connect the NodeMCU to the computer using a USB to Micro-USB cable.
Open the Arduino IDE on the computer.
Install the necessary board and library support for NodeMCU in the Arduino IDE.
Write a program to make the LED connected to D1 blink.
Upload the program to the NodeMCU.
Department of CSE-IoT III B-Tech I Sem 52 | P a g e
Internet of Things (IoT Lab) Aditya College of Engineering
Power the NodeMCU using an external power source.
Observe the LED blinking at regular intervals.
CODE:
RESULT:
The LED connected to digital pin D1 on the NodeMCU should blink at 1-second intervals. The
experiment demonstrates the basic concept of interfacing an LED with NodeMCU and controlling its
state using a simple program. This foundational experiment is often the starting point for more complex
projects involving NodeMCU and other electronic components.
7.
AIM:
To interface a DHT11 Temperature and Humidity sensor with an Arduino Uno and display the
measured values on an LCD (Liquid Crystal Display).
APPARATUS REQUIRED:
Arduino Uno
WORKING PRINCIPLE:
The DHT11 sensor communicates with the Arduino Uno using a single-wire digital protocol. It sends
temperature and humidity data to the Arduino, which then processes the information. The Arduino
controls the LCD through the LiquidCrystal library, displaying the temperature and humidity readings
in real-time.
PROCEDURE:
Connect the sensor's DATA pin to a digital pin (e.g., D2) on the Arduino.
Connect the LCD's SDA pin to a digital pin (e.g., D4) on the Arduino.
Connect the LCD's SCL pin to a digital pin (e.g., D5) on the Arduino.
CODE:
#include <LiquidCrystal_I2C.h>
#include <dht.h>
dht DHT;
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change the address (0x27) according to your LCD
void setup() {
lcd.begin(16, 2);
void loop() {
int chk = DHT.read11(D2); // Change the pin (D2) according to your setup
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(DHT.temperature);
lcd.print("C");
lcd.print("Humidity: ");
lcd.print(DHT.humidity);
lcd.print("%");
RESULT:
Upon uploading the code to the Arduino Uno, the LCD should display real-time temperature and
humidity readings obtained from the DHT11 sensor. The values will be updated every 2 seconds,
providing a continuous display of environmental conditions.
8.
Aim:
To design a street light automation system using an LDR (Light Dependent Resistor) sensor interfaced
with an Arduino Uno, with the goal of automatically controlling street lights based on ambient light
levels.
APPARATUS REQUIRED:
Arduino Uno
Relay module
Resistors
WORKING PRINCIPLE:
The LDR sensor's resistance changes with variations in ambient light. In the absence of sunlight (or
when it gets dark), the resistance of the LDR increases, signaling low light conditions. The Arduino
Uno reads the LDR value and, based on the programmed threshold, activates or deactivates the street
light using a relay module. The relay is used to control the high-power street light circuit.
PROCEDURE:
Connect the other leg of the LDR to the analog pin (e.g., A0) on the Arduino.
Connect the signal pin of the relay module to a digital pin (e.g., D7) on the Arduino.
Connect the VCC and GND pins of the relay module to the 5V and GND on the Arduino.
Connect the street light simulation (LED or lamp) to the relay module.
CODE
void setup() {
pinMode(LDR_Pin, INPUT);
pinMode(relayPin, OUTPUT);
void loop() {
} else {
RESULT:
When the ambient light decreases below the threshold value (e.g., it gets dark), the relay will be
activated, turning on the simulated street light. Conversely, when there is enough ambient light, the
9. AIM:
To interface an OLED (Organic Light Emitting Diode) display with an Arduino Uno and display
graphical information.
APPARATUS REQUIRED:
Arduino Uno
WORKING PRINCIPLE:
OLED displays are capable of showing graphical information by illuminating individual pixels. The
Arduino communicates with the OLED display using the I2C (Inter-Integrated Circuit) protocol. The
Arduino sends commands and data to the OLED, instructing it to display text, shapes, or custom
graphics on the screen.
PROCEDURE:
Connect the VCC pin of the OLED to the 5V pin on the Arduino.
Connect the GND pin of the OLED to the GND pin on the Arduino.
Connect the SDA pin of the OLED to the A4 (SDA) pin on the Arduino.
Connect the SCL pin of the OLED to the A5 (SCL) pin on the Arduino.
Download and install the "Adafruit_SSD1306" library for OLED displays in the Arduino IDE.
CODE
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_HEIGHT 64
void setup() {
if(!display.begin(SSD1306_I2C_ADDRESS, OLED_RESET)) {
for(;;);
delay(2000);
display.clearDisplay();
void loop() {
display.clearDisplay();
// Draw a rectangle
// Draw text
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(20, 40);
display.print("Hello, OLED!");
display.display();
RESULT:
Upon uploading the code to the Arduino Uno, the OLED display should show a rectangle and text. The
rectangle represents a simple graphic, and the text "Hello, OLED!" is displayed on the screen. This
experiment demonstrates the interfacing of an OLED display with an Arduino Uno and the ability to
showcase graphical information on the OLED screen.