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

Embedded Systems Lecture 5 Board Based Embedded System

The document discusses board based embedded systems and provides examples using Arduino boards. It introduces Arduino boards, shows how to program them, and provides examples of blinking an LED and using serial communication. Code snippets are provided for basic Arduino programs structure and commands like pinMode, digitalRead/Write, analogRead/Write, and serial communication functions.

Uploaded by

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

Embedded Systems Lecture 5 Board Based Embedded System

The document discusses board based embedded systems and provides examples using Arduino boards. It introduces Arduino boards, shows how to program them, and provides examples of blinking an LED and using serial communication. Code snippets are provided for basic Arduino programs structure and commands like pinMode, digitalRead/Write, analogRead/Write, and serial communication functions.

Uploaded by

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

Hawassa University

Institute of Technology
Electrical and Computer Engineering

Board Based Embedded System

By:
Muluneh Hailu
Contents
• Introduction to Board Based Embedded Systems

• Arduino Board Programming • Raspberry pi Boards


➢Basic Ardunio Code ✓ Setup and Configuration of Raspberry pi Board
✓Digital Read and Write ✓ A bit About Python to Program Raspberry pi
✓Read Analog Signals ✓ Controlling GPIO pins
✓Serial Communication • NodeMCU Board
➢Interfacing Input/Outputs
✓Interfacing analog and digital sensors • How to Interface sensors and Wireless connectivity’s
✓Interfacing LED and Push button
✓Interfacing Bluetooth
✓Interfacing Wifi Module
✓Interfacing sensors for Monitoring Water
quality, Environmental air quality and soil
quality
✓Interfacing DC motor, Servo motor
Introduction to Board Based Embedded
Systems
• Embedded controller is a controller that is embedded in a greater system.
• One can define an embedded controller as a controller (computer) that is
embedded into some device for some purpose other than to provide general
purpose computing
• Types of Embedded Controller (Processor) Systems:
➢We can divide all embedded controller(processor)systems into four categories based
on their processing unit:
✓ASIC SoC Based Embedded System
✓Microprocessor Based Embedded System
✓Microcontroller Based Embedded System
✓Board Based Embedded System
Introduction to Board Based Embedded
Systems
• Board based: An alternative to designed embedded controller using
hardware that has already been built and tested.
✓The main advantage is the reduced work load and the availability of
ported software that can simply be utilized with very little effort.
✓The disadvantages are higher cost and in some cases restrictions in
the functionality that is available.
• Here are some of the most famous Educational and Research
Boards
✓Arduino Boards
✓Raspberry pi Boards
✓NodeMCU Board
Arduino
Embedded Board
Arduino
• Arduino is an open-source electronics prototyping platform
based on flexible, easy-to-use hardware and software.
• It's intended for designers, hobbyists, and anyone interested
in creating interactive objects.
• For the first time, it’s made in Italy
• Arduino is an open-source single microcontroller board based on flexible and easy-to-use
hardware and software.
• Basically, the hardware consists of an Atmel AVR processor, USB interface, onboard
programmer and input/output support.
• Based on Atmel microcontroller
• There are different version of Arduino, with additional components and analog/digital
ports.
• The software consists of a standard programming language compiler (C or C++), that
includes a special library called "Wiring" which makes the most common input/output
operations very easy, and the boot loader that runs on the board. You can find the
language code reference and documentation on the official Arduino website:
http://www.arduino.cc/
Arduino Boards
• Arduino can sense the environment by receiving input from a variety
of sensors and can affect its surroundings by controlling lights, motors,
and other actuators.
• The microcontroller on the board is programmed using the Arduino
programming language and the Arduino development environment.
• Arduino projects can be standalone or they can communicate with
software running on a computer.
• The boards can be built by hand or purchased preassembled; the
software can be downloaded for free.
• The hardware reference designs (CAD files) are available under
an open-source license, you are free to adapt them to your needs.
Arduino Duemilanove Schematic
Arduino Boards
• There are different kinds of Arduino boards with different size and
capability. Some of these boards are
➢ Arduino Uno
➢Arduino Due
➢Arduino Leonardo
➢Arduino Diecimila.
➢Arduino Mega
➢Arduino Nano
➢Arduino mini
➢Arduino Micro.
➢LilyPad Arduino
Arduino Uno
• The Arduino Uno is a board based on the ATmega328 microcontroller.
• It has 14 digital input/output pins (of which 6 can be used as PWM
outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB
connection, a power jack, an ICSP header, and a reset button.
Arduino Mega 2560
• The Arduino Mega 2560 is a microcontroller board based on the
ATmega2560 (datasheet). It has 54 digital input/output pins (of which
14 can be used as PWM outputs), 16 analog inputs, 4 UARTs
(hardware serial ports), a 16 MHz crystal oscillator, a USB connection,
a power jack, an ICSP header, and a reset button.
Other Arduino Boards Choices
• LilyPad Arduino
• The LilyPad Arduino is a microcontroller board designed
for wearables and e-textiles. It can be sewn to fabric and
similarly mounted power supplies, sensors and actuators
with conductive thread.

• Arduino Nano
• Arduino Nano is a surface mount breadboard embedded
version with integrated USB. It is a smallest, complete, and
breadboard friendly. It has everything that Diecimila has
(electrically) with more analog input pins and onboard +5V
AREF jumper. .
Getting Starting 1
• The Arduino board needs a standard USB cable for the programming
of the microcontroller and for getting power (the green power LED
should go on).
Getting Starting 2
• Download and install the open-source (http://arduino.cc/en/Main/Software)
Arduino environment software to write code and upload it to the Arduino board.
• It runs on Windows, Mac OS X, and Linux. The environment software is written
in Java.
Arduino - Get started
• Let’s start using the Arduino board:
• Download and Install the Arduino IDE software from the
like below https://www.arduino.cc/en/software
• Connect the Arduino board to the PC using the provided
USB cable.
• Launch the Arduino application and configure your setup
and the serial port.
Arduino Code
• The Arduino code consists of two parts:
➢the setup() and
➢the loop().
• The setup() function is called only when the Arduino is powered on or reset.
✓Use it to initialize variables, pin modes, start using libraries, etc.
✓The setup function will only run once, after each power up or reset of the
Arduino board.
• The loop() function runs continuously till the device is powered off. .
✓Code in the loop() section of your sketch is used to actively control the
Arduino board.
✓The main logic of the code goes here. Similar to while (1) for micro-controller
programming.
• Any line that starts with two slashes (//) will not be read by the
compiler, so you can write anything you want after it.
✓Commenting your code like this can be particularly helpful in explaining, both
to yourself and others, how your program functions step by step.
Bare minimum code
void setup() {
// put your setup code here, to run once:
}

void loop() {
// put your main code here, to run repeatedly:
}
Basic Commands for Arduino
• pinMode
✓A pin on arduino can be set as input or output by using pinMode() function.
• Example:
➢ pinMode(13, OUTPUT); // sets pin 13 as output pin
➢ pinMode(13, INPUT); // sets pin 13 as input pin
• Reading/Writing Digital Values
✓digitalWrite()
✓digitalRead()
• Example
➢ digitalWrite(13, LOW); // Makes the output voltage on pin 13 , 0V
➢ digitalWrite(13, HIGH); // Makes the output voltage on pin 13 , 5V
➢ int buttonState = digitalRead(2); // reads the value of pin 2 in button State
Analog to Digital Conversion
• What is analog ?
✓It is continuous range of voltage values (not just 0 or 5V)
• Why convert to digital ?
✓Because our microcontroller only understands digital.
• The Arduino Uno board contains 6 pins for ADC
➢10-bit analog to digital converter
➢This means that it will map input voltages between 0 and 5 volts into integer values
between 0 and 1023

Reading/Writing Analog Values


• analogRead(A0); // used to read the analog value from the pin A0

• analogWrite(2,128);
Serial Communication
• Serial is used for communication between the Arduino board and a computer or
other devices.
• All Arduino boards have at least one serial port (also known as a UART or
USART): Serial.
• It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer
via USB.
Basic Serial Communication Functions in Arduino
✓ Serial.begin(4800): used to initialize the speed of communication.
✓ Serial.available(): used to check weather there is communication or not.
✓ Serial.read(): use to reads or receive incoming serial data. it read only one
character.
✓ Serial.readString(): reads or receives characters from the serial data into a
string
✓ Serial.print(): used to write or send characters on communication port.
✓ Serial.println() used to write or send characters on communication port. At last
it send newline.
Blink LED
/*
Blink: Turns on an LED on for one second, then off for one second, repeatedly.
*/
int led = 13; // Pin 13 has an LED connected on most Arduino boards.
void setup()
{
pinMode(led, OUTPUT); // initialize the digital pin as an output.
}
void loop()
{
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Read a character and on/off a led
// Pin 13 has an LED connected on most Arduino boards.
int led = 13;
void setup()
{
pinMode(led, OUTPUT); // initialize the digital pin as an output.
Serial.begin(9600); // Open serial communications and wait for port to open:
while (!Serial) {; // wait for serial port to connect. }
Serial.print("Send me 0 to swich off the led and 1 to swich on: \n");
}
void loop()
{
if (Serial.available() > 0)
{
int thisChar = Serial.read(); // get any incoming bytes:
if(thisChar=='0'){
Serial.print("Led OFF: \'");
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
}
else{
Serial.print("Led ON: \'");
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
}
Serial.print("Send me 0 to swich off the led and 1 to swich on: \n");
}
}
Analog Read Serial
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and
ground.
*/
void setup()
{
Serial.begin(9600); // initialize serial communication at 9600 bits per second:
}
void loop()
{
int sensorValue = analogRead(A0); // read the input on analog pin 0:
Serial.println(sensorValue); // print out the value you read:
delay(1); // delay in between reads for stability
}
Read Analog Voltage
/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial
monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
*/
void setup()
{
Serial.begin(9600); // initialize serial communication at 9600 bits per second:
}
void loop() {
int sensorValue = analogRead(A0); // read the input on analog pin 0:
float voltage = sensorValue * (5.0 / 1023.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
Serial.println(voltage); // print out the value you read:
delay(1000);
}
Interfacing DC Motor
const int pwm = 3 ; //initializing pin 3 as pwm
const int in_1 = 8 ; void loop()
{
const int in_2 = 9 ;
//For Clock wise motion , in_1 = High , in_2 = Low
//For providing logic to L293d IC to choose the direction of the DC motor
digitalWrite(in_1,HIGH) ;
void setup digitalWrite(in_2,LOW) ;
{ analogWrite(pwm,200) ;
//we have to set PWM pin as output delay(3000) ; //Clockwise for 3 secs
digitalWrite(in_1,LOW) ; //For brake
pinMode(pwm,OUTPUT) ;
digitalWrite(in_2,LOW) ;
//Logic pins are also set as output delay(1000) ;
pinMode(in_1,OUTPUT) ; pinMode(in_2,OUTPUT) ; //For Anti Clock-wise motion - IN_1 = LOW , IN_2 = HIGH
} digitalWrite(in_1,LOW) ;
digitalWrite(in_2,HIGH) ;
/*setting pwm of the motor to 255 delay(3000) ;
we can change the speed of rotation digitalWrite(in_1,LOW) ; //For brake
by changing pwm input but we are only digitalWrite(in_2,LOW) ;
using arduino so we are using highest delay(1000) ;
value to driver the motor */ }
L293D
• L293D is a typical motor driver IC.
• L293D works on concept of H-bridge.
• In H-bridge, Voltage is allowed to be
flown in either direction because
voltage needs to change its direction to
make the motors to move in either
clockwise or anticlockwise.
• In single chip of L293D, there are two
bridges and so, two DC motors can
work here independently at the same
time.
• It provides bidirectional current up to
600mA.
H-Bridge
PWM
• PWM, or pulse width modulation is a technique which allows us to
adjust the average value of the voltage that’s going to the
electronic device by turning on and off the power at a fast rate.
• The average voltage depends on the duty cycle, or the amount of
time the signal is ON versus the amount of time the signal is OFF in
a single period of time.
PWM
• So By controlling the rms input voltage we can control the
speed of the motor
Arduino Libraries
• Libraries are a collection of code that makes it easy to connect to a sensor, display,
module, etc.
• For example, the built-in LiquidCrystal library makes it easy to talk to character
LCD displays. There are hundreds of additional libraries available on the Internet
for download.
• The built-in libraries and some of these additional libraries are in
http://arduino.cc/en/Reference/Libraries
Adafruit Motor Shield
• The Adafruit Motor Shield is a great and quick way to control DC motors, servos or
even stepper motors.
• It has the capability of controlling up to 2 stepper motors, 4 DC motors. and 2 servos
• To connect a DC motor, simply connect two wires to the terminals and then connect
them to either the M1, M2, M3, or M4. Then follow these steps in your sketch
✓ Make sure you #include <AFMotor.h>
✓ Create the AF_DCMotor object with AF_DCMotor(motor#, frequency), to setup the motor H-bridge
and latches. The constructor takes two arguments.
➢ The first is which port the motor is connected to, 1, 2, 3 or 4.
➢ frequency is how fast the speed controlling signal is.
➢ For motors 1 and 2 you can choose MOTOR12_64KHZ, MOTOR12_8KHZ, MOTOR12_2KHZ,
orMOTOR12_1KHZ. A high speed like 64KHz wont be audible but a low speed like 1KHz will use
less power. Motors 3 & 4 are only possible to run at 1KHz and will ignore any setting given
• Then you can set the speed of the motor using setSpeed(speed) where the speed ranges
from 0 (stopped) to 255 (full speed). You can set the speed whenever you want.
• To run the motor,
✓ call run(direction) where direction is FORWARD, BACKWARD or RELEASE
Interfacing Servo Motor
• Servo Motors are electronic devices that convert digital signal
to rotational movement.
• There are two sorts of servo motors: Standard servos that
their rotation is limited to maximum of 180 degrees in each
direction and Continuous Rotation Servos that can provide
rotation unlimitedly in both directions.
• A servo motor is a motor that pulses at a certain rate moving
its gear at a certain angle.
• It has three connections:
✓ the black is ground,
✓ the red is connected to 5V, and
✓ the white (yellow wire here) is set to the digital pin.
Library for controlling Servo motor.
• Arduino has the built-in library for controlling Servo motor.

#include <Servo.h> //Include the servo library

Servo servo_name; //The servo gets the name “servo_name”

servo_name.attach(8); //The signal line of the servo is on pin 8

servo_name.write(90); //Position with an angle of 90°


Standard Servo Motor Controller
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
// goes from 0 degrees to 180 degrees // in steps of 1 degree
for (pos = 0; pos <= 180; pos += 1)
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the
position
}
// goes from 180 degrees to 0 degrees
for (pos = 180; pos >= 0; pos -= 1)
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the
position
}
}
Exercise
• Design a servo motor control system using two push button.
The first push button is used to increment the motor shaft
angle by 30 degree up 180 degree. The other push button is
used to decrement the shaft angle by 30 degree up 0 degree.
Pin Symbol Pin Function
Interfacing 2x16 LCD with PIC16F877A Number
1 VSS Ground
• The 2x16 LCD has 2 lines with 16 chars on each
lines. 2 VCC +5v
• It supports all the ASCII chars and is basically 3 VEE Contrast adjustment (VO)
used for displaying the alpha numeric characters. 4 RS Register Select. 0:Command, 1:
• Each character is displayed in a matrix of 5x7 Data
pixels.
5 R/W Read/Write, R/W=0: Write &
• Apart from the voltage supply connections the R/W=1: Read
important pins from the programming
perspective are 6 EN Enable. Falling edge triggered
✓ the data lines(8-bit Data bus), 7 D0 Data Bit 0
✓ Register select,
8 D1 Data Bit 1
✓ Read/Write and
✓ Enable pin. 9 D2 Data Bit 2
10 D3 Data Bit 3
11 D4 Data Bit 4
12 D5 Data Bit 5
13 D6 Data Bit 6
14 D7 Data Bit 7/Busy Flag
15 A/LED+ Back-light Anode(+)
16 K/LED- Back-Light Cathode(-)
Pin Configuration of 2x16 LCD
• Apart from the voltage supply connections the important pins from the programming perspective are
✓ The Data lines(8-bit Data bus),
✓ The Register select,
✓ The Read/Write and
✓ The Enable pin.
• Data Bus:
✓ an alpha numeric lcd has a 8-bit data bus referenced as D0-D7.
✓ As it is a 8-bit data bus, we can send the data/cmd to LCD in bytes.
✓ It also provides the provision to send the the data/cmd in chunks of 4-bit, which is used when there are limited number of GPIO lines
on the microcontroller.
• Register Select(RS):
✓ The LCD has two register namely a Data register and Command register.
✓ Any data that needs to be displayed on the LCD has to be written to the data register of LCD.
✓ Command can be issued to LCD by writing it to Command register of LCD.
✓ This signal is used to differentiate the data/cmd received by the LCD.
✓ If the RS signal is LOW then the LCD interprets the 8-bit info as Command and writes it Command register and performs the action as
per the command.
✓ If the RS signal is HIGH then the LCD interprets the 8-bit info as data and copies it to data register. After that the LCD decodes the
data for generating the 5x7 pattern and finally displays on the LCD.
• Read/Write(RW):
✓ This signal is used to write the data/cmd to LCD and reads the busy flag of LCD. For write operation the RW should be LOW and for
read operation the R/W should be HIGH.
• Enable(EN):
✓ This pin is used to send the enable trigger to LCD. After sending the data/cmd, Selecting the data/cmd register, Selecting the Write
operation. A HIGH-to-LOW pulse has to be send on this enable pin which will latch the info into the LCD register and triggers the LCD
to act accordingly.
Liquid Crystal Library for Arduino
• #include <LiquidCrystal.h> :- is a library used for LCD.
• LiquidCrystal(): function sets the pins the Arduino uses to connect to the LCD.
Just put the Arduino pin numbers inside the parentheses in this order:
LiquidCrystal lcd(RS, E, D4, D5, D6, D7). RS, E, D4, D5, D6, D7 are the LCD pins.
• lcd.begin(): Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the
display.
lcd.begin(cols, rows)
Where: lcd: a variable of type LiquidCrystal
cols: the number of columns that the display has
rows: the number of rows that the display has
• lcd.print(): Prints text to the LCD
lcd.print(data)
Where: data: the data to print (char, byte, int, long, or string)
• lcd.Display(): Turns on the LCD display, after it's been turned. This will restore the text (and cursor) that was
on the display.
• lcd.NoDispaly() : Turns off the LCD display, without losing the text currently shown on it.
• lcd.clear(): This function clears any text or data already displayed on the LCD.
• lcd.setCursor(column, row): This function places the cursor (and any printed text) at any position on the screen.
SoftwareSerial Library
• The Arduino hardware has built-in support for serial communication on pins 0 and
1 (which also goes to the computer via the USB connection).
• The SoftwareSerial library has been developed to allow serial communication on
other digital pins of the Arduino, using software to replicate the functionality.
• First included the Arduino Software Serial Library using
#include <SoftwareSerial.h>
• Created the Soft Serial object and its parameters are
SoftwareSerial name_of_Serial(RX, TX)
• Initialize the speed of communication
name_of_Serial.begin(9600)
WiFi Module - ESP8266
• The ESP8266 is a small WiFi module built around the
ESP8266 chip that can connect your microcontroller to
the internet wirelessly for a very small cost.
• The pinout for the ESP8266’s pins are according to the
diagram:
✓RX: UART serial communication receive pin
✓GPIO 0: GPIO pin
✓GPIO 1: GPIO pin
✓GND: Connection to Ground
✓VCC: Connection to 3.3V Vcc (Vcc cannot exceed 3.3V!)
✓RESET: Reset pin (pull down to reset)
✓CH_PD: Chip enable and power down pin
✓TX: UART serial communication transmit pin
Interfacing ESP8266 With Arduino
Sending Data to Thingspeak Website Using
ESP8266
Temperature Monitoring
• Design an Arduino based system which read a temperature and
send it to ThingSpeak through wifi module.
The system uses linear LM35D for measuring the temperature. Detail
information about this sensor and Arduino Uno is provide at next slide.
Points to do:
• Draw the block diagram which shows the whole system
interconnection
• Write the Arduino code to implement the temperature control

22/07/2021 43
LM35D Specification
• LM35D is an analog, linear analog temperature sensor whose output
voltage varies linearly with change in temperature. LM35 is three
terminal linear temperature sensor from National semiconductors. It is
designed to measure from 0°C to 100°C. The sensitivity of LM35D is
10 mV/degree Celsius. As temperature increases, output voltage also
increases. E.g. 250 mV means 25°C.
• LM35D can be operated from a 5V supply. The pin out of LM35 is
shown in the figure below.

VCC: Supply Voltage 5V

Out: It gives analog output voltage which is proportional to the temperature (in degree Celsius).

GND: Ground

22/07/2021 44
DC Motor Controller
• Design DC Motor direction and Speed control system using Arduino
Uno. The system has one potentiometer and three push buttons. Two
of the push button used for rotating the motor CW and CCW. The third
push button used to stop the rotating motor. The speed of the motor is
controlled by tuning the potentiometer. Please use L293D motor driver
IC to interface the motor with the microcontroller.

• Points to do:
• Design a detailed and completed block diagram of the system.
• Write the Arduino code to implement the system

22/07/2021 46
Temperature Controlled Fun
• Design a simple temperature control system for small room using Arduino Uno
board. The task of the system is to maintain the room temperature at 250C at
any time. It achieves this by rotating the fun with different speed value. The
fun stays off when the temperature is below 250C. when the temperature is
above 250C and below 270C the fun starts rotate with small speed (1/3 of the
maximum speed). when the temperature is above 270C and below 300C the fun
starts rotate with medium speed (2/3 of the maximum speed). when the
temperature is above 300C the fun starts rotate with maximum speed. To
indicate the temperature is cold, LED is used which turns on when the
temperature is below 250C and off when the temperature is above 250C.

• The system uses linear LM35D for measuring the temperature. Detail
information about this sensor and Arduino Uno is provide at page 3.
• Please use a 5V DC motor for the fun.
• Points to do:
• Draw the block diagram which shows the whole system interconnection
• Write the Arduino code to implement the temperature control
LM35D Specification
• LM35D is an analog, linear analog temperature sensor whose output
voltage varies linearly with change in temperature. LM35 is three
terminal linear temperature sensor from National semiconductors. It is
designed to measure from 0°C to 100°C. The sensitivity of LM35D is
10 mV/degree Celsius. As temperature increases, output voltage also
increases. E.g. 250 mV means 25°C.
• LM35D can be operated from a 5V supply. The pin out of LM35 is
shown in the figure below.

VCC: Supply Voltage 5V

Out: It gives analog output voltage which is proportional to the temperature (in degree Celsius).

GND: Ground

22/07/2021 48
Automatic Door Controller
• Design Arduino Uno based automatic door opening embedded system
which is powered by 5V. This Design is used to sense any body movement
nearby the door using passive infrared sensor(PIR) to open and close the
door. Generally, a human body emits infrared energy which is detected by
the PIR sensor from a particular distance. This signal which is detected by
the sensor is fed to a Arduino Uno to function a door motor through motor
driver IC (L293D). When a body reaches the operating range of the PIR
sensor, it sends a signal to the Arduino to open and if the door is open after
30 second and no one is there close the door.
Please use a 5V DC motor.
Points to do:
• Design a detailed and completed block diagram of the System
• Write the Arduino code to implement the system

22/07/2021 49
PIR Sensor Specification
• PIR sensor detects a human being moving around within approximately
10m from the sensor. The PIR acts as a digital output so all you need to do
is listening for the pin to flip high or low. The motion can be detected by
checking for a high signal on a single I/O pin. Once the sensor warms up the
output will remain low until there is motion, at which time the output will
swing high for a couple of seconds, then return low. If motion continues the
output will cycle in this manner until the sensors line of sight of still again.
The PIR sensor needs a warm-up time with a specific end goal to capacity
fittingly. This is because of the settling time included in studying nature’s
domain. This could be anyplace from 10-60 seconds.
Pin Configuration
• PIR sensors have a 3-pin connection at the side or bottom. One pin will be
ground, another will be signal and the last pin will be power. Power is
usually up to 5V.

22/07/2021 50
PIR Sensor Specification
• PIR sensor detects a human being moving around within approximately
10m from the sensor. The PIR acts as a digital output so all you need to do
is listening for the pin to flip high or low. The motion can be detected by
checking for a high signal on a single I/O pin. Once the sensor warms up the
output will remain low until there is motion, at which time the output will
swing high for a couple of seconds, then return low. If motion continues the
output will cycle in this manner until the sensors line of sight of still again.
The PIR sensor needs a warm-up time with a specific end goal to capacity
fittingly. This is because of the settling time included in studying nature’s
domain. This could be anyplace from 10-60 seconds.
Pin Configuration
• PIR sensors have a 3-pin connection at the side or bottom. One pin will be
ground, another will be signal and the last pin will be power. Power is
usually up to 5V.

22/07/2021 51
Raspberry PI
Embedded Board II
Raspberry PI
• A low cost, credit-card sized computer.
• Plugs into a computer monitor or TV
• Uses standard keyboard and mouse
• Can browse the internet and play HD video
• Can also interact with the outside world!
• made by the Raspberry Pi Foundation, a UK charity that aims to educate people in computing
and create easier access to computing education.
• Early concepts started in 2006.
• Officially launched in 2012.
• There have been several iterations and variations of Raspberry pi model released since then.
What Raspberry Pi models have been released?
• There have been many generations of the Raspberry Pi line: from Pi 1 to 4,
• There has generally been a Model A and a Model B of most generations.
• Raspberry Pi 1 Model B (2012)
• Raspberry Pi 1 Model A (2013)
• Raspberry Pi 1 Model B+ (2014)
• Raspberry Pi 1 Model A+ (2014)
• Raspberry Pi 2 Model B (2015)
• Raspberry Pi Zero (2015)
• Raspberry Pi 3 Model B (2016)
• Raspberry Pi Zero W (2017)
• Raspberry Pi 3 Model B+ (2018)
• Raspberry Pi 3 Model A+ (2019)
• Raspberry Pi 4 Model A (2019)
• Raspberry Pi 4 Model B (2020)
• Raspberry Pi 400 (2021)
Features
• All models has a Broadcom system on a chip (SoC), which includes an ARM compatible central processing
unit (CPU) and an on-chip graphics processing unit (GPU, a Video Core IV).
• CPU speed ranges from 700 MHz to 1.2 GHz for the Pi 3 and on board memory range from 256 MB to 1 GB
RAM.
• Secure Digital (SD) cards are used to store the operating system and program memory in either the SDHC or
MicroSDHC sizes.
• Most boards have between one and four USB slots, HDMI and composite video output, and a 3.5 mm phono
jack for audio.
• Lower level output is provided by a number of GPIO pins which support common protocols like I²C.
• The B-models have an 8P8C Ethernet port and the Pi 3 and Pi Zero W have on board Wi-Fi 802.11n and
Bluetooth.
Getting Started- Hardware Requirements
To Start using Raspberry pi the following material are required
➢Raspberry Pi 3 B+ or newer.

➢ Keyboard and/or mouse.

➢Laptop or (HDMI cable with display monitor).

➢SD Card (8 GB+ recommended).

➢SD Card Reader.


Getting Started- Download Software
To Start using Raspberry pi the following software's are required
➢Download NOOBS – visit “www.raspberrypi.org” clicking on downloads.
➢Download SD Formatter – visit “www.sdcard.org” clicking on downloads.
Getting Started – Extract and Copy
1. Format your SD Card using the SD Formatter – More instructions
found online.
2. Extract NOOBS to a folder and drag and drop onto your newly
formatted SD Card.
Setup Raspberry Pi with Monitor, Keyboard and Mouth
• Insert the SD card to the Raspberry pi SD card interface
• Connect the Raspberry pi with Desktop monitor with HDMI cable
• Power on the Raspberry pi by connecting the power USB port
Set Up Raspberry Pi 4 Through Laptop/pc Using Ethernet
Cable(No Monitor, No Wi-Fi)
• Connect the Ethernet cable to your PC/laptop
and power up the pi with the type-C cable.
• Share the Network
✓ If you are using Windows 10 go to Control Panel--> Network and
Internet --> Network Connections, right-click on Wi-Fi
select properties, go to sharing section and check on “Allow other
network users to connect through this computer’s Internet connection”.
Make sure that Home network connection is Ethernet. Save and close
the window.
Set Up Raspberry Pi 4 Through Laptop/pc Using Ethernet
Cable(No Monitor, No Wi-Fi)
• Entering Pi Terminal Through ssh
✓ To access the terminal window of raspberry pi one can use
secure shell connection(ssh), in linux you can login using the
command 'ssh pi@ipaddress', in Windows10 you need a
external application, in this case lets login using PuTTY.
✓ In order to do that open the Bitvise SSH Client,
enter raspberrypi.local or the IP address(use Advanced IP
scanner to get the IP address) as host and leave 22 as default
port in the server section.
✓ Click Log in, a new dialog box will be opened enter
username as pi and the default password as raspberry. A
terminal pops up and you are now into the Raspberry Pi.

• Updating the Pi
✓ If this is your first time logging into pi make sure to update your pi by issuing the commands
below to update and upgrade pi@raspberrypi: sudo apt-get update

pi@raspberrypi:sudo apt-get upgrade


✓ To change the configurations or to Enable/Disable the interfaces, connections, camera, ssh., type
in pi@raspberrypi: sudo raspi-config
Set Up Raspberry Pi 4 Through Laptop/pc Using Ethernet
Cable(No Monitor, No Wi-Fi)
• Accessing Pi Desktop Remotely
✓ Go to terminal and type pi@raspberrypi: vncserver

✓ This should generate ip address, copy that. Now open VNC-Viewer on your desktop and enter the
address or paste it, after few seconds a window pops sharing the screen of the raspberry pi desktop.
Configuration
• When booting up for the first time you will get the blue “raspi‐config”
screen. Here you can configure your Pi with language and keyboard
settings for your desired region of the world. Use tab and arrow keys to
browse.
• Once configured to your liking go to <Finish> and Hit enter. This Will
Take You To The Command Prompt Where You Will Need To Type in
“startx” to start up the GUI (Graphical User Interface)
Basic Commands Lines
• Useful command lines to run from the terminal or command line
✓rasp-config –change your pi configuration settings.
✓startx- start the GUI(Graphical User Interface)
✓Ifconfig –Get the details of your Ethernet or wireless network adapter.
✓rpi-update-Update your Raspberry pi firmware.
✓lsusb-shows a list of usb devices.
✓Apt-get update & apt-get upgrade – Update or upgrade your pi software
✓ssh- connect your pi to other computer
✓sudo- run command as super user
✓Shutdown- this will shutdown your pi
✓nano-this is your text editor for changing or adding files. Save edit, create.
✓cat- read out files at the command line
✓passwd- change your user password
Raspberry PI Programming Languages
• The Raspberry Pi Foundation recommends Python
• Any language which will compile for ARMv6 can be used
• Installed by default on the Raspberry Pi:
✓C
✓C++
✓Java
✓Scratch -
✓Ruby
A Bit About Python
• Python is an interpreted, high-level, general-purpose programming
language that has been around since 1991.
• It is currently one of the most popular and fastest growing programming
languages.
• The "Pi" in Raspberry Pi stands for "Python Interpreter," reflecting the fact
that this is the recommended language on the platform.
• A nice feature of Python is that, being an interpreter, you can type in and
try commands interactively without needing to create a program.
• Being an interpreter there is no need to explicitly compile programs.
GPIO of Raspberry Pi
• The Raspberry Pi provides a set of GPIO (general purpose input/output) pins, allowing you to control electronic
components for physical computing and explore the Internet of Things (IoT).

• Any of the GPIO pins can be designated (in software) as an input or output pin and used for a wide range of purposes.
• Note: the numbering of the GPIO pins is not in numerical order; GPIO pins 0 and 1 are present on the board (physical
pins 27 and 28) but are reserved for advanced use (see below).
GPIO of Raspberry Pi
• Outputs
✓ A GPIO pin designated as an output pin can be set to high (3V3) or low (0V).
• Inputs
✓ A GPIO pin designated as an input pin can be read as high (3V3) or low (0V).
This is made easier with the use of internal pull-up or pull-down resistors.
Pins GPIO2 and GPIO3 have fixed pull-up resistors, but for other pins this
can be configured in software.
Control Raspberry Pi GPIO Pins from Python
RPi.GPIO
✓ Raspberry-gpio-python or RPi.GPIO, is a Python module to control the GPIO
interface on the Raspberry Pi. It was developed by Ben Croston and released
under an MIT free software license.
✓ The RPi.GPIO module is installed by default on recent versions of Raspbian
Linux. To use the module from Python programs, first import it using:
import RPi.GPIO as GPIO
• RPi.GPIO supports referring to GPIO pins using either the physical pin numbers on the GPIO
connector or using the BCM channel names from the Broadcom SOC that the pins are
connected to.
• For example, pin 24 is BCM channel GPIO8.
• To use physical board pin numbers, call:
✓GPIO.setmode(GPIO.BOARD)
• and to use the BCM channel numbers, use:
✓GPIO.setmode(GPIO.BCM)
Control Raspberry Pi GPIO Pins from Python
• To set up a channel as an input or an output, call either:
✓ GPIO.setup(channel, GPIO.IN)
or
✓ GPIO.setup(channel, GPIO.OUT)
✓ Where channel is the channel number based on the numbering system you specified when you
called setmode.
• To read the value of an input channel, call:
✓ GPIO.input(channel)
✓ It will return a value of 0, GPIO.LOW, or False (all are equivalent) if it is low and 1, GPIO.HIGH,
or True if it was at a high level.
• To set the output state of a GPIO pin, call:
✓ GPIO.output(channel, state)
✓ where channel is the channel number and state is the desired output level: either 0, GPIO.LOW, or
False for a low value or 1, GPIO.HIGH, or True for a high level.
• When you are done with the library, it is good practice to free up any resources used and
return all channels back to the safe default of being inputs. This is done by calling:
✓ GPIO.cleanup()
LED Blinking
• Connect the LED to the Raspberry Pi as shown below:
✓Positive pin of LED to Raspberry Pi pin 14
✓Negative end of LED to 100ohm resistor which is then connected to Raspberry
Pi ground(Placing the resistor is optional)
✓Then configure GPIO pins of board & do simple codes in python.
Python Code for Blinking LED
• LED blinking examples using raspberry pi
✓toggles an output pin on and off for 200 milliseconds, ten times.
• pi@raspberrypi: nano blink.py
#!/usr/bin/python3
import RPi.GPIO as GPIO
import time
led = 14
GPIO.setmode(GPIO.BOARD)
GPIO.setup(led, GPIO.OUT)
for i in range(10):
GPIO.output(led, GPIO.HIGH)
print(Led is on')
time.sleep(0.2)
GPIO.output(led, GPIO.LOW)
print(Led is off')
time.sleep(0.2)
GPIO.cleanup()
Raspberry Pi Analog output and software PWM
• RPi can generate software PWM on every one of its 26 GPIO pins.
• It can also generate hardware PWM signals at the:
✓ GPIO12 (board pin number 32)
✓ GPIO13 (board pin number 33)
✓ GPIO18 (board pin number 12)
✓ GPIO19 (board pin number 35).
• The hardware PWM uses the system timer of Broadcom SoC
and can generate a PWM signal with a maximum frequency of
19.2 MHz.
• This image shows the RPi channels where the hardware PWM is
available:
• The software PWM is available on all 26 of RPi’s GPIO and can
generate PWM frequencies from 1 Hz up to few kiloHertz.
• The duty cycle of the software PWM signals can be varied
between 0.0 and 100.0.
Raspberry Pi Analog output and software PWM
• To generate software PWM on RPi’s channels using the RPi.GPIO library.
• The GPIO.PWM() method
✓This function is used to create a PWM instance. It requires two arguments:
1. The channel number where the PWM signal has to be generated
2. The PWM signal frequency in Hertz. The instance must be created by assigning the method
to a variable.
✓This function/method has this syntax:
soft_pwm = GPIO.PWM(channel, frequency)
• The start() method
✓This method can be applied to an instance of the software PWM.
✓It takes only one argument: the duty cycle of the PWM signal.
✓soft_pwm.start(duty cycle)
• The stop() method
✓ This method can be applied to an instance of software PWM.
✓ It takes no arguments. When calling this method on an instance, the PWM signal is stopped at the
respective channel.
✓soft_pwm.stop()
Python for Analog output and software PWM
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(40, GPIO.OUT)
soft_pwm = GPIO.PWM(40, 1)
soft_pwm.start(50)
input(“Press return to stop: “)
soft_pwm.stop()
GPIO.cleanup()
Reading Analog Data with an RPi
• Many sensors out there use an analog voltage to convey their
measurement data. For example, photocells change their resistance
depending on how much light is falling on the sensor. By using a
voltage divider in our circuit, we can effectively measure the amount
of ambient light by measuring a voltage.
• The bad news is that Raspberry Pi does not come with any way to
measure an analog voltage.
• it's not capable of reading analog signals because it lacks an ADC
(Analog to Digital Converter) circuit.
• Wiring an ADC to the RPi is quite easy to do, but there is another
technique that can be used to read analog electrical signals or data:
ThingSpeak
• ThingSpeak allows you to aggregate, visualize, and analyze live data
streams in the cloud.
• ThingSpeak provides instant visualizations of data posted by your
devices or equipment.
• Execute MATLAB code in ThingSpeak, and perform online analysis
and processing of the data as it comes in.
• ThingSpeak accelerates the development of proof-of-concept IoT
systems, especially those that require analytics.
• You can build IoT systems without setting up servers or developing
web software.
Download the Adafruit DHT11 library
• In the terminal, type the following command.
✓git clone https://github.com/adafruit/Adafruit_Python_DHT.git
• Navigate to Adafruit_Python_DHT directory (folder).
✓cd Adafruit_Python_DHT
• Run the following commands in the terminal.
✓sudo apt-get install build-essential python-dev # python2
✓sudo apt-get install build-essential python3-dev # python3
• Run the following commands in the terminal.
✓sudo python setup.py install # python2
✓sudo python3 setup.py install # python3
DHT11, Raspberry Pi, and ThingSpeak to analyze the temperature and humidity.
Open the new Python file and name it as dht1234567.py like below.
sudo nano dht1234567.py import httplib, urllib
import time
Replace the following code. import Adafruit_DHT
sleep = 30 # how many seconds to sleep between posts to the channel
key = '****************' # Write API key
humidity, temperature = Adafruit_DHT.read_retry(11, 27) # GPIO27 (BCM no
tation)
#Report Raspberry Pi internal temperature to Thingspeak Channel
def thermometer():
•Set up the DHT11 humidity sensor on the Raspberry Pi. while True:
•GPIO pin is 27. headers = {"Content-typZZe": "application/x-www-form-
urlencoded","Accept": "text/plain"}
conn = httplib.HTTPConnection("api.thingspeak.com:80")
try:
params = urllib.urlencode({'field1': temperature, 'key':key })
# channel name is field1 or field 2
conn.request("POST", "/update", params, headers)
response = conn.getresponse()
print humidity
print temperature #print response.status, response.reason
data = response.read()
conn.close()
except:
print "connection failed"
break #sleep for desired amount of time
if __name__ == "__main__":
while True:
thermometer()
time.sleep(sleep)

You might also like