0% found this document useful (0 votes)
31 views

Embedded System Internship

The document provides an introduction to the Arduino Uno and describes its key components and pins. It explains functions of the power pins, analog and digital pins, serial communication pins, external interrupt pins, pulse-width modulation pins, and serial peripheral interface pins. It also describes the onboard LED pin, analog reference pin, and provides an example of blinking an LED using code.

Uploaded by

mangaimathi27
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Embedded System Internship

The document provides an introduction to the Arduino Uno and describes its key components and pins. It explains functions of the power pins, analog and digital pins, serial communication pins, external interrupt pins, pulse-width modulation pins, and serial peripheral interface pins. It also describes the onboard LED pin, analog reference pin, and provides an example of blinking an LED using code.

Uploaded by

mangaimathi27
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Introduction to Arduino Uno

To study the V-I characteristics of Gunn diode and to determine the thresholdvoltage.
Apparatus required: Arduino Uno

Theory:
Introduction to Arduino Uno

Vin: This is the input voltage pin of the Arduino board used to provide input supply from an
external power source.

1
5V: This pin of the Arduino board is used as a regulated power supply voltage and it is used to
give supply to the board as well as onboard components.

V: This pin of the board is used to provide a supply of 3.3V which is generated
from a voltage regulator on the board

GND: This pin of the board is used to ground the Arduino board.

Reset: This pin of the board is used to reset the microcontroller. It is used to Resets the
microcontroller.

Analog Pins: The pins A0 to A5 are used as an analog input and it is in the range of 0-5V.

Digital Pins: The pins 0 to 13 are used as a digital input or output for the Arduino board.

Serial Pins: These pins are also known as a UART pin. It is used for communication between
the Arduino board and a computer or other devices. The transmitter pin number 1 and
receiver pin number 0 is used to transmit and receive the data resp.

External Interrupt Pins: This pin of the Arduino board is used to produce the External
interrupt and it is done by pin numbers 2 and 3.

PWM Pins: This pins of the board is used to convert the digital signal into an analog by varying
the width of the Pulse. The pin numbers 3,5,6,9,10 and 11 are used as a PWM pin.

SPI Pins: This is the Serial Peripheral Interface pin, it is used to maintain SPI
communication with the help of the SPI library. SPI pins include:

1. SS: Pin number 10 is used as a Slave Select


2. MOSI: Pin number 11 is used as a Master Out Slave In
3. MISO: Pin number 12 is used as a Master In Slave Out
4. SCK: Pin number 13 is used as a Serial Clock

LED Pin: The board has an inbuilt LED using digital pin-13. The LED glows only when the
digital pin becomes high.

AREF Pin: This is an analog reference pin of the Arduino board. It is used to provide a
reference voltage from an external power supply.

2
Example :

Control LED using C

To turn on an LED, the Arduino needs to send a HIGH signal to one of it's pins. To turn
off the LED, it needs to send a LOW signal to the pin. You can make the LED flash by
changing the length of the HIGH and LOW states. Controlling by push button.

Program:

int swt = 13;

int led = 12;

void setup()

pinMode(13, INPUT);

pinMode(12, OUTPUT);

void loop()

if(digitalRead(swt) == 1)

digitalWrite(led, HIGH);

else{

digitalWrite(led, LOW);

Result:

3
Introduction to Node Mcu (ESP8266)

To study the V-I characteristics of Gunn diode and to determine the thresholdvoltage.
Apparatus required: Node Mcu (Esp8266)

Theory:
Introduction to Node Mcu (Esp8266)

Fig: Node Mcu Controller

NodeMCU is an open-source firmware for which open-source prototyping board designs


are available. The name "NodeMCU" combines "node" and "MCU" (controller unit). The
term "NodeMCU" strictly speaking refers to the firmware rather than the
associated development kits.
Both the firmware and prototyping board designs are open source.
The firmware uses the Lua scripting language. The firmware is based on the eLua project,
and built on the Espressif Non-OS SDK for ESP8266. It uses many open-source projects,
such as lua-cjson and SPIFFS. Due to resource constraints, users need to select the modules
relevant for their project and build a firmware tailored to their needs. Support for the 32-
bit ESP32 has also been implemented.
The prototyping hardware typically used is a circuit board functioning as a dual in-line
package (DIP) which integrates a USB controller with a smaller surface-mounted board
containing the MCU and antenna. The choice of the DIP format allows for easy prototyping
on breadboards. The design was initially based on the ESP-12 module of the ESP8266, which
is a Wi-Fi SoC integrated with a Tensilica Xtensa LX106 core, widely used in IoT
applications

4
 Pin1: VDDA is a power pin for analog power ranges from 2.5V to 3.6V.
 Pin2: LNA is an input/output pin specifically used for RF antenna interface. Chip
produces impedance of 39+j6 Ω.
 Pin3: VDD3P3 is a power pin to provide amplifier power ranges from 2.5V to 3.6V.
 Pin4: VDD3P3 is a power pin provide amplifier power ranges from 2.5V to 3.6V similar to
pin3.
 Pin5: VDD_RTC is categorized as a power pin and supply 1.1V but this pin is not
connected.
 Pin6: TOUT is an input pin functions as ADC pin to test the supply voltages of Pin3 and
Pin4 and the input voltages of TOUT pin6. These two functions cannot perform
simultaneously.
 Pin7: CHIP_EN I an input pin. When CHIP_EN pin is HIGH chip works properly when LOW
chip consumed an only small amount of current.
 Pin8: XPD_DCDC is an input/output pin which is used to wake up the chip from deep
sleep mode. Commonly it is connected with GPIO16.
 Pin9: MTMS is an input/output pin labelled as GPIO14 and it is used in SPI as clock pin
(SPI_CLK).
 Pin10: MTDI is an input/output pin labelled as GPIO12 and it is used in SPI as Master-In-
Slave-Out pin (SPI_MISO).

 Pin11: VDDPST is a power pin. It is a digital input/output power supply whose voltages
ranges from 1.8V to 3.6V. Similar to pin17.
 Pin12: MTCK is an input/output pin labelled as GPIO13 and it is used in SPI as Master-
Out Slave-In pin (SPI_MOSI) as well as used in UART as Clear To Send pin (UART_CTS).
 Pin13: MTDO is an input/output pin labelled as GPIO15 and it is used in SPI as Chip
Select pin (SPI_CS) as well as used in UART as Request to Send pin (UART_RTS).
 Pin14: GPIO2 is an input/output pin used as UART TX during flash programming.
 Pin15: GPIO0 is an input/output used as Chip Select pin2 in SPI (SPI_CS2).
 Pin16: GPIO4 is an input/output pin purely used for input and output purposes.
 Pin17: VDDPST is a power pin. It is a digital input/output power supply whose voltages
ranges from 1.8V to 3.6V. Similar to pin11.
 Pin18: SDIO_DATA_2 is an input/output pin labelled as GPIO9 and used to connect with
data pin 2 of SD card.
 Pin19: SDIO_DATA_3 is an input/output pin labelled as GPIO10 and used to connect with
data pin 3 of SD card.
 Pin20: SDIO_CMD is an input/output pin labelled as GPIO11 and used to connect with
command pin of SD card
 Pin21: SDIO_CLK is an input/output pin labelled as GPIO6 and used to connect with the
clock pin of SD card.

5
 Pin22: SDIO_DATA_0 is an input/output pin labelled as GPIO7 and used to connect with
data pin 0 of SD card.
 Pin23: SDIO_DATA_1 is an input/output pin labelled as GPIO8 and used to connect with
data pin 1 of SD card.
 Pin24: GPIO5 is an input/output pin purely used for input and output purposes.
 Pin25: U0RXD is an input/output pin labelled as GPIO3 and used as UART RX during flash
programming.
 Pin26: U0TXD is an input/output pin labelled as GPIO1 and used as UART TX during flash
programming. Also used as SPI Chip Select pin 1 (SPI_CS1).
 Pin27: XTAL_OUT is classified as an input/output pin and connected to the output of the
crystal oscillator.
 Pin28: XTAL_IN is classified as an input/output pin and connected to the input of the
crystal oscillator.
 Pin29: VDDD is a power pin provide analog power ranges from 2.5V to 3.6V.
 Pin30: VDDA is a power pin provide analog power ranges from 2.5V to 3.6V. Similar to
pin29.
 Pin31: RES12K is an input pin which is serial connected with 12 kΩ resistors and
connected to the ground.
 Pin32: EXT_RSBT is an input pin used to rest the chip by providing an external reset
signal which is active at a low voltage level.
 Pin33: GND is a power pin acts as a ground for the chip.

Node Mcu Specification

 Microcontroller: Tensilica 32-bit RISC CPU Xtensa LX106


 Operating Voltage: 3.3V
 Input Voltage: 7-12V
 Digital I/O Pins (DIO): 16
 Analog Input Pins (ADC): 1
 UARTs: 1
 SPIs: 1
 I2Cs: 1
 Flash Memory: 4 MB
 SRAM: 64 KB
 Clock Speed: 80 MHz
 USB-TTL based on CP2102 is included onboard, Enabling Plug n Play
 PCB Antenna

6
 Small Sized module to fit smartly inside your IoT projects

Example:

Control led using Nodemcu:


we will blink a led using NodeMCU 8266-12E Wi-Fi Board. We can blink an inbuilt internal led but
we are blinking an external led. We used the Arduino IDE to blink the on-board LED, the blue led in
the board was used to signal the execution of a particular procedure.
->To connect with webpage. First, you need to upload the sketch and go to serial monitor you get the
IP address.
->Copy the IP address and go and paste to browser.

Program:
#include <ESP8266WiFi.h>
#define LED D2 // LED at GPIO4 D2
const char* ssid = "Name"; //enter your wi-fi name
const char* password = "password"; //enter the wifi password
unsigned char status_led=0;
WiFiServer server(80);
void setup() {
Serial.begin(115200);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started at...");
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}

7
// Wait until the client sends some data
Serial.println("new client");
while (! client.available())
{
delay (1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
// Match the request
if (req.indexOf("/ledoff") != -1) {
status_led=0;
digitalWrite(LED, LOW);
Serial.println("LED OFF");
}
else if(req.indexOf("/ledon") != -1)
{
status_led=1;
digitalWrite(LED,HIGH);
Serial.println("LED ON");
}
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("");
client.println("<!DOCTYPE HTML>");
client.println("<HTML>");
client.println("<H1> LED CONTROL </H1>");
client.println("<br />");
client.println("<a href=\"/ledon\"\"> <button style='FONT-SIZE: 50px; HEIGHT: 200px;WIDTH:
300px; 126px; Z-INDEX: 0; TOP: 200px;'> LED ON </button> </a>");
client.println("<a href=\"/ledoff\"\"> <button style='FONT-SIZE: 50px; HEIGHT: 200px; WIDTH:
300px; 126px; Z-INDEX: 0; TOP: 200px;'> LED OFF </button> </a>");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}

8
// Wait until the client sends some data
Serial.println("new client");
while (! client.available())
{
delay (1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
// Match the request
if (req.indexOf("/ledoff") != -1) {
status_led=0;
digitalWrite(LED, LOW);
Serial.println("LED OFF");
}
else if(req.indexOf("/ledon") != -1)
{
status_led=1;
digitalWrite(LED,HIGH);
Serial.println("LED ON");
}
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("");
client.println("<!DOCTYPE HTML>");
client.println("<HTML>");
client.println("<H1> LED CONTROL </H1>");
client.println("<br />");
client.println("<a href=\"/ledon\"\"> <button style='FONT-SIZE: 50px; HEIGHT: 200px;WIDTH:
300px; 126px; Z-INDEX: 0; TOP: 200px;'> LED ON </button> </a>");
client.println("<a href=\"/ledoff\"\"> <button style='FONT-SIZE: 50px; HEIGHT: 200px; WIDTH:
300px; 126px; Z-INDEX: 0; TOP: 200px;'> LED OFF </button> </a>");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}

9
Raspberry pi

.
Introduction to raspberry pi

Raspberry Pi 3 Board

Raspberry Pi is a small single board computer. By connecting peripherals like Keyboard,


mouse, display to the Raspberry Pi, it will act as a mini personal computer.

Raspberry Pi is popularly used for real time Image/Video Processing, IoT based applications
and Robotics applications.

Raspberry Pi is slower than laptop or desktop but is still a computer which can provide all the
expected features or abilities, at a low power consumption.

1
Raspberry Pi Foundation officially provides Debian based Raspbian OS. Also, they provide
NOOBS OS for Raspberry Pi. We can install several Third-Party versions of OS like Ubuntu,
Arch Linux, RISC OS, Windows 10 IOT Core, etc.

Raspbian OS is official Operating System available for free to use. This OS is efficiently
optimized to use with Raspberry Pi. Raspbian have GUI which includes tools for Browsing,
Python programming, office, games, etc.

We should use SD card (minimum 8 GB recommended) to store the OS (operating System).

Raspberry Pi is more than computer as it provides access to the on-chip hardware i.e. GPIOs
for developing an application. By accessing GPIO, we can connect devices like LED, motors,
sensors, etc. and can control them too.

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 1 GB.

Raspberry Pi also provides on-chip SPI, I2C, I2S and UART modules.

There are different versions of raspberry pi available as listed below:

1. Raspberry Pi 1 Model A
2. Raspberry Pi 1 Model A+
3. Raspberry Pi 1 Model B
4. Raspberry Pi 1 Model B+
5. Raspberry Pi 2 Model B
6. Raspberry Pi 3 Model B
7. Raspberry Pi Zero

2
Raspberry Pi 3 On-chip Hardware

Some Hardware Components shown above are mention below:

1. HDMI (High-Definition Multimedia Interface): It is used for transmitting


uncompressed video or digital audio data to the Computer Monitor, Digital TV, etc.
Generally, this HDMI port helps to connect Raspberry Pi to the Digital television.
2. CSI Camera Interface: CSI (Camera Serial Interface) interface provides a connection
in between Broadcom Processor and Pi camera. This interface provides electrical
connections between two devices.
3. DSI Display Interface: DSI (Display Serial Interface) Display Interface is used for
connecting LCD to the Raspberry Pi using 15-pin ribbon cable. DSI provides fast High-
resolution display interface specifically used for sending video data directly from GPU
to the LCD display.
4. Composite Video and Audio Output: The composite Video and Audio output port
carries video along with audio signal to the Audio/Video systems.
5. Power LED: It is a RED colored LED which is used for Power indication. This LED
will turn ON when Power is connected to the Raspberry Pi. It is connected to 5V
directly and will start blinking whenever the supply voltage drops below 4.63V.
6. ACT PWR: ACT PWR is Green LED which shows the SD card activity

3
Raspberry Pi GPIO Access
Introduction

GPIO (General Purpose Input Output) pins can be used as input or output and allows raspberry
pi to connect with general purpose I/O devices.

 Raspberry pi 3 model B took out 26 GPIO pins on board.


 Raspberry pi can control many external I/O devices using these GPIO’s.
 These pins are a physical interface between the Pi and the outside world.
 We can program these pins according to our needs to interact with external devices. For
example, if we want to read the state of a physical switch, we can configure any of the
available GPIO pins as input and read the switch status to make decisions. We can also
configure any GPIO pin as an output to control LED ON/OFF.
 Raspberry Pi can connect to the Internet using on-board Wi-Fi or Wi-Fi USB adapter.
Once the Raspberry Pi is connected to the Internet then we can control devices, which
are connected to the Raspberry Pi, remotely.

GPIO Pins of Raspberry Pi 3 are shown in below figure:

Raspberry Pi 3 Model B GPIO Pins

Some of the GPIO pins are multiplexed with alternate functions like I2C, SPI, UART etc.

We can use any of the GPIO pins for our application.

4
Pin Numbering

We should define GPIO pin which we want to use as an output or input. But Raspberry Pi has
two ways of defining pin number which are as follows:

 GPIO Numbering
 Physical Numbering

In GPIO Numbering, pin number refers to number on Broadcom SoC (System on Chip). So,
we should always consider the pin mapping for using GPIO pin.

While in Physical Numbering, pin number refers to the pin of 40-pin P1 header on Raspberry
Pi Board. The above physical numbering is simple as we can count pin number on P1 header
and assign it as GPIO.

But, still we should consider the pin configuration diagram shown above to know which are
GPIO pins and which are VCC and GND.

Interfacing Diagram

Control LED using Raspberry Pi

Example

Now, let’s control LED using switch connected to the Raspberry Pi. Here, we are using Python
and C (Wiring Pi) for LED ON-OFF control.

5
Pin Numbering

We should define GPIO pin which we want to use as an output or input. But Raspberry Pi has
two ways of defining pin number which are as follows:

 GPIO Numbering
 Physical Numbering

In GPIO Numbering, pin number refers to number on Broadcom SoC (System on Chip). So,
we should always consider the pin mapping for using GPIO pin.

While in Physical Numbering, pin number refers to the pin of 40-pin P1 header on Raspberry
Pi Board. The above physical numbering is simple as we can count pin number on P1 header
and assign it as GPIO.

But, still we should consider the pin configuration diagram shown above to know which are
GPIO pins and which are VCC and GND.

Interfacing Diagram

Control LED using Raspberry Pi

Example

Now, let’s control LED using switch connected to the Raspberry Pi. Here, we are using Python
and C (WiringPi) for LED ON-OFF control.

6
Control LED using Python

Now, let’s turn ON and OFF an LED using Python on Raspberry Pi. Switch is used to control
the LED ON-OFF.

Python Program
import RPi.GPIO as GPIO #import RPi.GPIO module
LED = 32 #pin no. as per BOARD, GPIO18 as per BCM
Switch_input = 29 #pin no. as per BOARD, GPIO27 as per BCM
GPIO.setwarnings(False) #disable warnings
GPIO.setmode(GPIO.BOARD) #set pin numbering format
GPIO.setup(LED, GPIO.OUT) #set GPIO as output
GPIO.setup(Switch_input, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
if(GPIO.input(Switch_input)):
GPIO.output(LED,GPIO.LOW)
else:
GPIO.output(LED,GPIO.HIGH)

Functions Used:

RPi.GPIO

To use Raspberry Pi GPIO pins in Python, we need to import RPi.GPIO package which has
class to control GPIO. This RPi.GPIO Python package is already installed on Raspbian OS.
So, we don’t need to install it externally. Just, we should include library in our program to use
functions for GPIO access using Python. This is given as follows.

import RPi.GPIO as GPIO

GPIO.setmode (Pin Numbering System)

This function is used to define Pin numbering system i.e. GPIO numbering or Physical
numbering.

In RiPi.GPIO GPIO numbering is identified by BCM whereas Physical numbering is identified


by BOARD

Pin Numbering System = BOARD/BCM

E.g., If we use pin number 40 of P1 header as a GPIO pin which we have to configure as output
then,

7
In BCM,

GPIO.setmode(GPIO.BCM)

GPIO.setup(21, GPIO.OUT)

In BOARD,

GPIO.setmode(GPIO.BOARD)

GPIO.setup(40, GPIO.OUT)

GPIO.setup (channel, direction, initial value, pull up/pull down)

This function is used to set the direction of GPIO pin as an input/output.

channel – GPIO pin number as per numbering system.

direction – set direction of GPIO pin as either Input or Output.

initial value – can provide initial value

pull up/pull down – enable pull up or pull down if required

Few examples are given as follows,

 GPIO as Output

GPIO.setup(channel, GPIO.OUT)

 GPIO as Input

GPIO.setup(channel, GPIO.IN)

 GPIO as Output with initial value

GPIO.setup(channel, GPIO.OUT, initial=GPIO.HIGH)

 GPIO as Input with Pull up resistor

GPIO.setup(channel, GPIO.IN, pull_up_down = GPIO.PUD_UP)

GPIO.output(channel, state)

This function is used to set the output state of GPIO pin.

channel – GPIO pin number as per numbering system.

state – Output state i.e. HIGH or LOW of GPIO pin

8
e.g.

GPIO.output(7, GPIO.HIGH)

GPIO.input(channel)

This function is used to read the value of GPIO pin.

e.g.

GPIO.input(9)

Control LED using C (WiringPi)

We can access Raspberry Pi GPIO using C. Here, we are using WiringPi library for accessing
Raspberry Pi GPIO using C.

Before implementing LED blinking using wiringPi, you can refer How to use WiringPi library.

Program

#include <wiringPi.h>

#include <stdio.h>

int LED = 26;/* GPIO26 as per wiringPi, GPIO12 as per BCM, pin no.32 */

int switch_input = 21; /* GPIO21 as per WiringPi, GPIO5 as per BCM, pin no.29 */

int main(){

wiringPiSetup(); /* initialize wiringPi setup */

pinMode(LED,OUTPUT); /* set GPIO as output */

pullUpDnControl(switch_input, PUD_UP);

while (1){

if(digitalRead(switch_input))

digitalWrite(LED,LOW); /* write LOW on GPIO */

else

digitalWrite(LED, HIGH); /* write HIGH on GPIO */

9
RGB LED USING ARDUINO

To Interface RGB LED Using Arduino Uno board

Apparatus:

1. Universal Board
2. Arduino board
3. RGB LED
4. 12V Adaptor
5. Power jack
6. USB Cable
7. Jumper Wires

Hardware Procedure:

 LED pin is connected to Arduino Uno pin 9.


 Power jack is connected to the Arduino.
 USB connector is connected to Arduino Uno to monitor.
 Connect the 12V power supply to development board.
 Check the output from the development board.

Software Procedure:

1. Click on Arduino IDE

2. Click on file

3.Click on New

4. Write a Program as per circuit Pin connections

5. Click on Save

6.Click on Verify

7.Click on Upload the code into Arduino Uno by using USB cable.

10
Program:
const int ledPin = 9;

void setup() {

Serial.begin(9600);

pinMode(ledPin, OUTPUT);

void loop() {

byte brightness;

if (Serial.available()) {

brightness = Serial.read();

Serial.println(brightness);

if(brightness == '1')

digitalWrite(ledPin, HIGH);

else if(brightness == '0')

digitalWrite(ledPin, LOW);

Precautions:

 Take care about given power supply (12V).


 Jumper wires given carefully whenever given circuit connection.
Output: : RGB Led on / off is done by smart phone using Bluetooth module.

11
12
LDR INTERFACING WITH ARDUINO

To Interface LDR Using Arduino Uno board

Apparatus:

 Universal Board
 Arduino board
 LDR sensor
 12V Adaptor
 Power jack
 USB Cable
 Jumper Wires

Hardware Procedure:

Hardware Procedure:

 LCD pins connected to Arduino Uno pin 10,11,4,5,6,7.


 LDR pin is connected to the Arduino pin A0.
 RELAY pin is connected to the Arduino 8.
 Power jack is connected to the Arduino.
 USB connector is connected to Arduino Uno to monitor.
 Connect the 12V power supply to development board.
 Check the output from the development board.

Software Procedure:

1. Click on Arduino IDE

2. Click on file

3. Click on New

4. Write a Program as per circuit Pin connections

5. Click on Save

6. Click on Verify

7. Click on Upload the code into Arduino Uno by using USB cable.

13
Program:
#include<LiquidCrystal.h>
int relay = 8;
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
void setup()
{
lcd.begin(16, 2);
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
project_Name();
}

void loop()
{
int ldr_sensor_data = analogRead(A0);
lcd.setCursor(0,0);
lcd.print("LDR Data: ");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(9,0);
lcd.print(ldr_sensor_data);
if(ldr_sensor_data >150)
digitalWrite(relay, HIGH);
else
digitalWrite(relay, LOW);
delay(500);
}

void project_Name(){
lcd.setCursor(0,0);
lcd.print("LDR SENSOR ");
lcd.setCursor(0,1);
lcd.print("INTERFACING ");
delay(3000);
lcd.clear();
}

14
Precautions:

 Take care about given power supply (12V).


 Jumper wires given carefully whenever given circuit connection.
Output: Relay is ON when LDR value is greater than 150.

15
LDR SENSOR USING RASPBERRY

To Interface LDR Sensor using Raspberry microcontroller.

Apparatus:

 Universal Board
 Raspberry board
 Raspberry adapter
 HDMI to VJA Converter
 LDR Sensor
 12V Adaptor
 Power jack
 USB Cable
 Jumper Wires

Hardware Procedure:

 Connect Raspberry to the monitor through HDMI cable and connect Raspberry Adapter to the
Raspberry.
 Relay pin is connected to 21 pin of Raspberry.
 LCD Pins connected to Raspberry pins (26,19,13,6,5,0).

 Give the following connections to Raspberry.


 CLK = 11
 MISO = 9
 MOSI = 10
 CS = 8
 LDR Sensor pin is connected to CH0_PIN.
 Connect the 12V power supply to development board.
 Give Circuit Connections as per the code.
 Check the output from the development board.

Software Procedure:

1. Click on IDLE Programming Software


2. Click on new file
3. Write a Program as per circuit Pin connections

4. Click on Save
5. Click on Run module.

16
Program:
import time
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008
import Adafruit_CharLCD as LCD
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
relay = 21
lcd_rs = 26
lcd_en = 19
lcd_d4 = 13
lcd_d5 = 6
lcd_d6 = 5
lcd_d7 = 0
lcd_backlight = 4
lcd_columns = 16
lcd_rows = 2
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6,lcd_d7,
lcd_columns, lcd_rows, lcd_backlight)
GPIO.setup(relay,GPIO.OUT)
GPIO.output(relay, False)
CLK = 11
MISO = 9
MOSI = 10
CS = 8
mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
print('Reading MCP3008 values, press Ctrl-C to quit...')
while True:
value = mcp.read_adc(0)
adc_voltage=(value / 1023.0 * 3.3)
lcd.clear()
lcd.message('LDR_val ADC_vol\n')
lcd.message(str(value))
lcd.message(' ')
lcd.message(str(value / 1023.0 * 3.3))
print("LDR voltage: %.2f" % adc_voltage)
print('LDR value : %.2f' %(value))
if value > 120 :
GPIO.output(relay, True)
print('Relay ON')
else :
GPIO.output(relay, False)
print('relay OFF')
time.sleep(1)

17
Precautions:

 Take care about given power supply (12V).


 Jumper wires given carefully whenever given circuit connection.
Output: Automatic Street light is controlled using Raspberry microcontroller.

18
MQ2 Sensor Using Arduino Uno board

To Interface MQ2 Sensor Using Arduino Uno board

Apparatus:

 Universal Board
 Arduino board
 MQ2 Sensors
 12V Adaptor
 Power jack
 USB Cable
 Jumper Wires

Hardware Procedure:

Hardware Procedure:

 LCD connected to Arduino Uno pin 10, 11, 4, 5, 6&7.


 MQ2 sensor pin is connected to Arduino pin A0.
 Power jack is connected to the Arduino Uno.
 USB connector is connected to Arduino Uno to monitor.
 Connect the 12V power supply to development board.
 Check the output from the development board.

Software Procedure:

1. Click on Arduino IDE

2. Click on file

3.Click on New
4. Write a Program as per circuit Pin connections

5. Click on Save

6.Click on Verify
7. Click on Upload the code into Arduino Uno by using USB cable.

19
Program:
LCD DISPLAY
#include<LiquidCrystal.h>

LiquidCrystal lcd(10, 11, 4, 5, 6, 7);

void setup()
{
lcd.begin(16, 2);
project_Name();
}

void loop()
{
int mq2gas_sensor_data = analogRead(A0);
lcd.setCursor(0,0);
lcd.print("MQ2 Data: ");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(9,0);
lcd.print(mq2gas_sensor_data);
delay(500);
}

void project_Name(){
lcd.setCursor(0,0);
lcd.print("MQ2 GAS SENSOR ");
lcd.setCursor(0,1);
lcd.print(" by PSCMR ");
delay(3000);
lcd.clear();
}

SERIAL MONITOR
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);

20
Serial.begin(9600);
}

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);
}
Precautions:

 Take care about given power supply (12V).


 Jumper wires given carefully whenever given circuit connection.
Output: It can detect combustible gas and smoke. The output voltage from the Gas sensor increases
when the concentration of gas.
We get low data when gas is detected and gets high data when gas is not detected.

21
22
IR SENSOR USING RASPBERRY

To Interface IR Sensor using Raspberry microcontroller.

Apparatus:

 Universal Board
 Raspberry board
 Raspberry adapter
 HDMI to VJA Converter
 IR Sensor
 12V Adaptor
 Power jack
 USB Cable
 Jumper Wires

Hardware Procedure:

 Connect Raspberry to the monitor through HDMI cable and connect Raspberry Adapter to the
Raspberry.
 Buzzer pin is connected to 20 pin of Raspberry.
 IR Sensor pin is connected to 21 pin of Raspberry.
 Connect the 12V power supply to development board.
 Give Circuit Connections as per the code.
 Check the output from the development board.

Software Procedure:

1. Click on IDLE Programming Software

2. Click on new file

3. Write a Program as per circuit Pin connections

4. Click on Save

5. Click on Run module.

23
Program:
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
ir=21
buzzer=20
GPIO.setwarnings(False)
GPIO.setup(ir,GPIO.IN)
GPIO.setup(buzzer,GPIO.OUT)
while 1:
ir_state=GPIO.input(ir)
print(ir_state)
if ir_state==False:
GPIO.output(buzzer,GPIO.HIGH)
else:
GPIO.output(buzzer,GPIO.LOW)
sleep(0.5)
GPIO.cleanup()

Precautions:

 Take care about given power supply (12V).


 Jumper wires given carefully whenever given circuit connection.
Output: obstacle is detected with IR Sensor using Raspberry microcontroller.

24
IR SENSOR USING ARDUINO

To Interface IR Sensor Using Arduino Uno board

Apparatus:

 Universal Board
 Arduino board
 IR Sensor
 12V Adaptor
 Power jack
 USB Cable
 Jumper Wires

Hardware Procedure:

• IR Sensor pin is Connected to Arduino Uno pin of 2.

• buzzer pin is connected to Arduino Uno Pin of 3.

• Power jack is connected to the Arduino Uno.

• USB connector is connected to Arduino Uno to monitor.

• Connect the 12V power supply to development board.

• Check the output from the development board.

Software Procedure:

1. Click on Arduino IDE

2. Click on file

3. Click on New

4. Write a Program as per circuit Pin connections

5. Click on Save

6. Click on Verify

7. Click on Upload the code into Arduino Uno by using USB cable.

25
Program:

SERIAL MONITOR

const int IR_sensor = 2;

const int buzzer = 3;

void setup() {

pinMode(IR_sensor, OUTPUT);

pinMode(buzzer, OUTPUT);

void loop() {

if(digitalRead(IR_sensor) == LOW)

digitalWrite(buzzer, HIGH);

digitalWrite(buzzer, LOW);

delay(1000);

else

digitalWrite(buzzer, LOW);

Precautions:

• Take care about given power supply (12V).

• Jumper wires given carefully whenever given circuit connection.

Output: IR sensor is successfully detected the Obstacle by Arduino microcontroller.

26
27
DHT_11SENSOR USING RASPBERRY

To Interface DHT_11Sensor using Raspberry microcontroller.

Apparatus:
1. Universal Board
2. Raspberry board
3. Raspberry adapter
4. HDMI to VJA Converter
5. DHT_11 Sensor
6. 12V Adaptor
7. Power jack
8. USB Cable
9. Jumper Wires

Hardware Procedure:
 Connect Raspberry to the monitor through HDMI cable and connect Raspberry Adapter to the
Raspberry.
 DHT_11 pin is connected to 21 pin of Raspberry.
 LCD Pins connected to Raspberry pins (26,19,13,6,5,0).
 Give the following connections to Raspberry.
 CLK = 11
 MISO = 9
 MOSI = 10
 CS = 8
 Connect the 12V power supply to development board.
 Give Circuit Connections as per the code.
 Check the output from the development board.

Software Procedure:
1. Click on IDLE Programming Software
2. Click on new file
3. Write a Program as per circuit Pin connections
4. Click on Save
5. Click on Run module.

28
'''1.sudo apt-get update
2.sudo apt-get upgrade
3. git clone https://github.com/adafruit/Adafruit_Python_DHT
4. cd Adafruit_Python_DHT
5. sudo python setup.py install'''

Program:

LCD DISPLAY

import Adafruit_DHT
import time
import Adafruit_CharLCD as LCD
lcd_rs = 26
lcd_en = 19
lcd_d4 = 13
lcd_d5 = 6
lcd_d6 = 5
lcd_d7 = 0
lcd_backlight = 4
lcd_columns = 16
lcd_rows = 2
pin = 21
sensor = Adafruit_DHT.DHT11
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
lcd_columns, lcd_rows, lcd_backlight)
lcd.message('Temp Hum\n')
while True:
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
lcd.clear()
lcd.message('Temp Hum\n')
lcd.message(str(temperature))
lcd.message(' ')
lcd.message(str(humidity))
#print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))
print('temperature={} humidity={}'.format(temperature, humidity))
Precautions:
 Take care about given power supply (12V).
 Jumper wires given carefully whenever given circuit connection.
Output: Humidity and Temperature displayed on LCD and Serial monitor using Raspberry
microcontroller.

29
30
DHT11 WITH LCD USING ARDUINO

To Interface DHT11 Using Arduino Uno board.

Apparatus:

 Universal Board
 Arduino board
 DHT11
 12V Adaptor
 Power jack
 USB Cable
 Jumper Wires
 LCD

Hardware Procedure:

 LCD pins connected to Arduino Uno pin 10, 11, 4, 5, 6, and 7.


 DHT11 pin connected to the 2 pin of Arduino board.
 USB connector is connected to Arduino Uno to monitor.
 Connect the 12V power supply to development board.
 Power jack is connected to the Arduino Uno.
 Check the output from the development board.

Software Procedure:

1. Click on Arduino IDE


2. Click on file
3. Click on New
4. Write a Program as per circuit Pin connections

5. Click on Save
6. Click on Verify
7. Click on Upload the code into Arduino Uno by using USB cable.

31
Program:
LCD DISPLAY
#include <dht11.h>
#include<LiquidCrystal.h>

#define DHT11_PIN 2

LiquidCrystal lcd(10, 11, 4, 5, 6, 7);

const int buzzer = 13;


const int relay = 12;

dht DHT;

void setup()
{
lcd.begin(16, 2);
pinMode(buzzer, OUTPUT);
pinMode(relay, OUTPUT);
digitalWrite(buzzer, LOW);
digitalWrite(relay, LOW);
project_Name();
}

void loop()
{
int chk = DHT.read11(DHT11_PIN);
lcd.setCursor(4,0);
lcd.print("TMP: ");
lcd.setCursor(0,1);
lcd.print("Hum: ");
lcd.setCursor(9,0);
lcd.print(DHT.temperature);
lcd.setCursor(5,1);
lcd.print(DHT.humidity);
if(DHT.temperature > 40)
{
digitalWrite(relay, HIGH);
digitalWrite(buzzer, HIGH);
delay(500);
digitalWrite(buzzer, LOW);
delay(500);
}
else
{
digitalWrite(buzzer, LOW);
digitalWrite(relay, LOW);
}
delay(500);

32
}

void project_Name(){
lcd.setCursor(0,0);
lcd.print(" DHT 11 Sensor");
lcd.setCursor(0,1);
lcd.print(" by pscmr");
delay(3000);
lcd.clear();
}
SERIAL MONITOR

#include <dht.h>
#define dht_apin A0 // Analog Pin sensor is connected to

dht DHT;

void setup(){

Serial.begin(9600);
delay(500);//Delay to let system boot
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);//Wait before accessing Sensor

}//end "setup()"

void loop(){
//Start of Program

DHT.read11(dht_apin);

Serial.print("Current humidity = ");


Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");

delay(5000);//Wait 5 seconds before accessing sensor again.

//Fastest should be once every two seconds.

}// end loop

33
Precautions:

 Take care about given power supply (12V)


 Jumper wires given carefully whenever given circuit connection
Output: DHT11 sense the surrounding temperature and measure humidity in surrounding
air that temperature and humidity shown by LCD display.

34
ULTRASONIC WITH LCD USING ARDUINO

Aim: To Interface Ultrasonic Using Arduino Uno board

Apparatus:

 Universal Board
 Arduino board
 Ultrasonic sensors
 12V Adaptor
 Power jack
 USB Cable
 Jumper Wires
 LCD

Hardware Procedure:

 LCD pins connected to Arduino Uno pin 2,3,4,5,6,7.


 Ultrasonic trig pin connected to the A0 pin of Arduino board.
 Ultrasonic echo pin is connected to the A1 pin of Arduino board.
 USB connector is connected to Arduino Uno to monitor.
 Connect the 12V power supply to development board.
 Power jack is connected to the Arduino Uno.
 Check the output from the development board.

Software Procedure:

1. Click on Arduino IDE

2. Click on file

3.Click on New
4. Write a Program as per circuit Pin connections

5. Click on Save

6.Click on Verify
7.Click on Upload the code into Arduino Uno by using USB cable.

35
Program:
LCD DISPLAY
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

const int trigPin = A0;


const int echoPin = A1;

long duration;
int distance;

void setup() {
lcd.begin(16, 2);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
project_name();
}

void loop(){
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
lcd.setCursor(0, 0);
lcd.print("Distance: ");
lcd.setCursor(9, 0);
lcd.print(distance);
lcd.setCursor(0, 1);
lcd.print(" ");
delay(600);
}

void project_name()
{
lcd.setCursor(0, 0);
lcd.print("ULTRASONIC SENSR");
lcd.setCursor(0, 1);
lcd.print(" HC-SR04 ");
delay(2000);
lcd.clear();
}

36
SERIAL MONITOR
#define trigpin 13
#define echopin 12
void setup()
{
Serial.begin(9600);
pinMode(trigpin,OUTPUT);
pinMode(echopin,INPUT);
}
void loop()
{
long duration,distance;
digitalWrite(trigpin,LOW);
delayMicroseconds(2);
digitalWrite(trigpin,HIGH);
delayMicroseconds(10);
digitalWrite(trigpin,LOW);
duration=pulseIn(echopin,HIGH);
distance=(duration/2)/29;
if(distance>=200||distance<=0)
{
Serial.print("out of range");
}
else
{
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}

37
Precautions:

 Take care about given power supply (12V).


 Jumper wires given carefully whenever given circuit connection.
Output: Ultrasonic sensor detects the object distance.

38

You might also like