Embedded System Internship
Embedded System Internship
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:
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 :
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:
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)
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.
6
Small Sized module to fit smartly inside your IoT projects
Example:
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 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.
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.
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
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.
Some of the GPIO pins are multiplexed with alternate functions like I2C, SPI, UART etc.
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
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
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.
This function is used to define Pin numbering system i.e. GPIO numbering or Physical
numbering.
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 as Output
GPIO.setup(channel, GPIO.OUT)
GPIO as Input
GPIO.setup(channel, GPIO.IN)
GPIO.output(channel, state)
8
e.g.
GPIO.output(7, GPIO.HIGH)
GPIO.input(channel)
e.g.
GPIO.input(9)
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(){
pullUpDnControl(switch_input, PUD_UP);
while (1){
if(digitalRead(switch_input))
else
9
RGB LED USING ARDUINO
Apparatus:
1. Universal Board
2. Arduino board
3. RGB LED
4. 12V Adaptor
5. Power jack
6. USB Cable
7. Jumper Wires
Hardware Procedure:
Software Procedure:
2. Click on file
3.Click on New
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);
digitalWrite(ledPin, LOW);
Precautions:
11
12
LDR INTERFACING WITH ARDUINO
Apparatus:
Universal Board
Arduino board
LDR sensor
12V Adaptor
Power jack
USB Cable
Jumper Wires
Hardware Procedure:
Hardware Procedure:
Software Procedure:
2. Click on file
3. Click on New
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:
15
LDR SENSOR USING RASPBERRY
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).
Software Procedure:
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:
18
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:
Software Procedure:
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>
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);
21
22
IR SENSOR USING RASPBERRY
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:
4. Click on Save
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:
24
IR SENSOR USING ARDUINO
Apparatus:
Universal Board
Arduino board
IR Sensor
12V Adaptor
Power jack
USB Cable
Jumper Wires
Hardware Procedure:
Software Procedure:
2. Click on file
3. Click on New
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
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:
26
27
DHT_11SENSOR USING RASPBERRY
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
Apparatus:
Universal Board
Arduino board
DHT11
12V Adaptor
Power jack
USB Cable
Jumper Wires
LCD
Hardware Procedure:
Software Procedure:
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
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);
33
Precautions:
34
ULTRASONIC WITH LCD USING ARDUINO
Apparatus:
Universal Board
Arduino board
Ultrasonic sensors
12V Adaptor
Power jack
USB Cable
Jumper Wires
LCD
Hardware Procedure:
Software Procedure:
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);
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:
38