Unit 3 Design and Development
Unit 3 Design and Development
The design methodology defines a sequence of steps taking place in the development of the
design of IoT based application. The design should develop a robust, secure and scalable IoT
system. The sequence of IoT design steps are
Step 1: Purpose & Requirements Specification
Step 2: Process Specification
Step 3: Domain Model Specification
Step 4: Information Model Specification
Step 5: Service Specifications
Step 6: IOT Level Specification
Step 7: Functional View Specification
Step 8: Operational View Specification
Step 9: Device & Component Integration
Step 10: Application Development
Step 1: Purpose & Requirements Specification
The first phase in IOT system design methodology is to identify and define the purpose
and requirements of the system to be implemented. The system purpose, behaviour and
requirements (collecting data, collecting requirements, analysing the requirements, data
privacy and security, user interface requirements.) are finalized in this phase. For
example consider smart home system one of the requirements will be controlling the lights at
home by web application .Providing user authentication is another requirements
Step 2: Process Specification
The second phase in the IOT design methodology is to define the specification of the
process., the use cases used in of the IOT system are formally described and elaborately
defined based on and the purpose and requirement of the given specifications. The use cases
will describe your state and attribute of that particular actor or object in the system.
Step 3: Domain Model Specification
The third phase in the IOT design methodology is to define the Domain Model. The domain
describes about the concepts, entities and objects in the IOT system. The attributes of the
smart objects and relationships between objects are described in this model specification.
This model is independent of any specific technology or platform. The IOT system designers
understanding of the IOT domain is done for the user using this specification. It describes
about the physical entity and the virtual entity and the devices used. For example The
physical entity of the smart irrigation is soil, motor and pump .Soil moisture sensor and
buzzer are the devices of the domain.
Step 4: Information Model Specification
The fourth phase in the IOT design methodology is to define the Information Model.
Information Model defines the structure of all the information. This model does not describe
the specifics of how the information is represented or stored rather it defines the attributes
and relationship in terms of the class diagram.
Step 5: Service Specifications
The fifth phase in the IOT design methodology is to define the services used by the system.
Service specifications define the services in the IOT system, service types, service
inputs/output, service endpoints, service schedules, service preconditions and service effects.
These services change their state and behaviour of the system. For example change the state
of ON or OFF in the motor.
Step 6: IOT Level Specification
The sixth step in the IOT design methodology is to define the IOT level for the system. These
involve sensors and cloud .All devices of the IoT system are deployed namely sensors,
actuators and the smart objects
Step 7: Functional View Specification
The seventh phase in the IOT design methodology is to define the Functional View. The
Functional View (FV) defines the functions of the IOT systems grouped into various
Functional Groups (FGs) in the domain model. Functionalities and interactions are performed
with each other domains. Namely the database functionalities,communication,web
application functionalities and their interactions are recorded and m onitored.
Step 8: Operational View Specification
The eighth phase in the IOT design methodology is to define the Operational View
Specifications. Various options pertaining to the IOT system deployment and operation are
defined, such as, service hosting options, storage options, device options, application hosting
options, etc.communications services uses protocols uses such as REST, TCP,IPV6 and Http
and the application server app engine and device management(aurdino device management).
Step 9: Device & Component Integration
The ninth phase in the IOT design methodology is the integration of the devices and
components.for example in case of smart irrigation it will integrate the components like water
pump,aurdino board and the sensor devices.
An embedded system is computer hardware system which has the software embedded in it.
An embedded system can be an independent system or it can be a part of a large system. An
embedded system is a microcontroller or microprocessor based system which is developed
for performing a specific task. For example, a fire alarm is an embedded system; it will sense
only smoke.
An embedded system has three components −
Hardware.
Application software.
Real Time Operating system (RTOS) that supervises the application software ,it
assigns the processor run a process as per scheduling .RTOS defines the way the
system works. It sets the rules during the execution of application program. A small-
scale embedded system may not have RTOS.
Ordinary microprocessors that use separate integrated circuits for memory and
peripherals, microcontrollers that have on-chip peripherals, reducing power
consumption, size and cost.
Microcontroller (CPU) is an intelligent device that computes the tasks assigned by the
user and is used to build small applications for a specific purpose.
DSP processor removes the unwanted noise signals and provides the improvements in
the audio and video processing
Micrcontroller for embedded computing with IoT devices:
IoT devices are cheap; therefore the microcontroller needs to be chosen so that it’s should be
used efficiently by the application. The microcontroller specifications that determine the best
part for your application are
Bit depth: This is the data path width which influences the speed and accuracy with
which microcontrollers can do computations.
Memory: The amount of RAM and Flash in a microcontroller decides the code size and
complexity the component. Large memories have larger die area and component cost.
GPIO: These are the microcontroller pins used to connect to sensors and actuators in the
system. Serial communication, A/D, and D/A converters and their functionalities with the
devices are maintained.
Power consumption: Power consumption is critically important for battery-operated
devices and it typically increases with microcontroller speed and memory size
The Internet of Things is an embedded microprocessor controlled system connected directly or
indirectly to the internet .
The three important techniques s of the IoT are embedded programming, network
technology and information technology.
The embedded system of a device collects data from a sensor and sends it to the cloud
using a wifi module — basically, it means that you can turn your embedded device
into an IoT device by simply giving it Internet access.
Embedded devices application areas:
Aerospace and Defence (flight control systems, actuation, air and thermal management,)
Smart Homes(Home Security system, Setup Box, Television, Microwave Oven, Air
Conditioner, Refrigerator).
Disadvantages of microprocessor
• As the peripherals are integrated into a single chip, the overall system cost is very less
• The product is of small size compared to micro processor based system
• The system design now requires very little efforts
• As the peripherals are integrated with a microprocessor the system is more reliable
• Though microcontroller may have on chip ROM,RAM and I/O ports, addition ROM,
RAM I/O ports may be interfaced externally if required
• On chip ROM provide a software security
• Easy to upgrade
• Cost per unit
• Availability of software development tools such as assemblers, debuggers, C
compilers, emulator, simulator, technical support and wide availability and reliable
sources of the microcontrollers
8051 4k 128 2
8031 - 128 2
8032 - 256 3
si
FIG3.7: 8051 DETAILED ARCHITECTURE.
● An 8051 microcontroller has the following 12 major components:
Synchronization among internal operations can be achieved with the help of clock
circuits which are responsible for generating clock pulses. During each clock pulse a
particular operation will be carried out, thereby, assuring synchronization among operations.
There are two pins XTAL1 and XTAL2 which form an oscillator circuit which connect to a
resonant network in the microcontroller.
The circuit also has 4 additional pins -
Program Status Word or PSW is a hardware register which is a memory location which holds
a program's information and also monitors the status of the program this is currently being
executed
. PSW (Program Status Word)
● Generally, the instruction of the result of a program is stored in a single bit register
called a 'flag'. There are7 flags in the PSW of 8051. Among these 7 flags, 4 are math
flags and 3 are general purpose or user flags.
The 4 Math flags are:
• Carry (c)
• Auxiliary carry (AC)
• Overflow (OV)
• Parity (P)
The 3 General purpose flags or User flags are:
• FO
• GFO
• GF 1
10. Data Pointer (DPTR):The data pointer or DPTR is a 16-bit register. It is made up of two
8-bit registers called DPH and DPL. Separate addresses are assigned to each of DPH and
DPL. These 8-bit registers are used for the storing the memory addresses that can be used to
access internal and external data/code.
There are mainly two kinds of buses - Data Bus and Address Bus
Data Bus: The purpose of data bus is to transfer data. It acts as an electronic channel using
which data travels. Wider the width of the bus, greater will be the transmission of data.
Address Bus: The purpose of address bus is to transfer information but not data. The
information tells from where within the components, the data should be sent to or received
from. The capacity or memory of the address bus depends on the number of wires that
transmit a single address bit
3.4 System On Chip (SOC)
SOC defines the electronic devices to be smaller and more powerful.Our smart
phone,tablets,wearables all uses the system on chip.SOC defines electronic systems that
integrate a Microcontroller Unit (MCU) as one of its components. It runs on a single MCU
and can be 8, 16, 32 bits. It has General Purpose Inputs/Outputs (GPIO), Firmware which
loads it in the MCU's permanent memory (SDRAM). The most used board for the past few
years is Arduino, Atmel, and Arduino IDE, One more SOC which became famous later, the
Node-MCU or ESP-01 or ESP8266 which is smaller, cheaper and lower power consumption
Arduino Uno. Memory is high; processor is fast in execution, in built Wi-Fi but less GPIO.
Industrial Microcontroller (PLC and RTU):
There are two types of industrial Microcontrollers. The Programmable Logic Controller and
the Remote Terminal Unit. Robotics and the fault diagnostic s in the
A Programmable Logic Controller (PLC) is a gigantic microcontroller which works similar to
a microcontroller, with higher speed, performance, and reliability. Microcontroller is termed
low power CPU or computer with some output registers wired to pins. This is utilized for
small local area.
A Remote Terminal Unit (RTU) is a microprocessor-controlled electronic device that
interfaces objects in the physical world to a central control system by sending data to the
system. The state of connected objects can be altered based on control messages received
from the central control system. This is utilized by large geographical area not confined to
small area.
Single Board Computer (SBC). A single-board computer (SBC) is a complete computer built
on a single circuit board, with a microprocessor(s), memory, input/output (I/O) and other
features required of a functional computer Unlike a desktop personal computer, single board
computers don’t have any expansion slots for peripheral functions. The first true single-board
computer was born in 1976 called the "dyna-micro" was based on the Intel C8080A, and also
used Intel's first EPROM, the C1702A.
The idea behind the SOC is to reduce energy , save costs, and to reduce the space With an
SoC dsign it possible for us to create a plenty of the gadgets. they are frequently used in
systems related to Internet of Things, embedded systems, smart phones and smart cars
The application of SoCs in the real world scenario is enormous. our smartphone is a good
example of how a system on chip operates. Cell phone is used you to browse the internet,
view videos, listen to audio, take photos, play games, text message,etc. None of this would be
possible without having multiple components such as a graphics card, internet support,
wireless connections, GPS, and many other elements. SoC technology is also being used in
smaller sized Personal Computers and laptops to reduce power consumption and improve the
performance of the tablet or notebook by using a singular chip to manage all the various
aspects of the system.
GPU: Graphical Processing Unit in order to help visualize the interface and work at rapid
speed for processing of huge data.
electronic components: voltage regulators, phase lock loop control systems and oscillators,
clocks and timers, analog to digital and digital to analog converters, etc.
SoC Advantages
The benefits of using an SoC are: power saving, space saving and cost reduction
SoCs is an efficient as systems as their performance is maximized per watt
Systems on chip also minimize the latency and improve the speed of data transfer.
SoC Vs CPU
CPU used to be the primary and most significant part of the entire computing system,the CPU
is only part of the equation that ultimately adds up to being a system on chip. SoC packs
twice the power and capability of CPU.. The CPU depends on several other external
hardware whereas an SoC has space for all you want to add on its negligible chip. Compared
to CPUs, SoCs also use shorter wiring with smart energy. The upgrading and repairing the
problems of SoC is a difficult process.
Figure 3.11: Simplified block diagram of the basic building blocks of the IoT
Sensors:
Sensor is a device, or a subsystem whose purpose is to sense the medium and send the
information to other system in digital format .digital information is being utilised by all other
intelligent machines. A sensor is always connected to the other electronic systems.
Sensors are embedded with the smart objects use and it can sense beyond the traditional
fields of temperature, pressure or flow measurement. It can be embedded in airplanes and
aerospace, cars, medicine, robotics and many more applications. There are different types of
sensors, measuring chemical & physical properties, electric, electrochemical, optic of the
environment.
Active sensors requires external powersupply, passive sensor do not require external
power supply.
Invasive sensor is involved in the environment whereas non invasive is external to the
environment
Contact sensors require physical touch with the field.
Absolute sensors measure the exact value and relative sensors measure the variable
reference value.
Table 3.1 Sensors types:
Motion sensor and This measures the movement of the human or Radar
occupancy objects in specified area whereas occupancy
measures the person signal when he is static
Force sensor It measures the physical force applied to it. Strain gauge
Works based on the threshold
Tactile sensor
Processors:
Processors are the brain of the IoT system. Their main function is to process the data acquired
from the sensors .Processors extract information from the data in a efficient way. Processor,
provides intelligence to the data. Processors operate on the real-time data and can be easily
controlled by applications. Processor encrypts the data and it is highly secured. Embedded
hardware devices, microcontroller etc are the ones that process the data because they have
processors attached to it.
Gateways:
Gateways are the one which is responsible for delivering the data to the destination.It routes
the processed data and send it to the receiving nodes for proper utilization.The
communication of data between the sender node and the receiving node takes place only with
the help og gateways. Network connectivity is enabled by the gateway for the data transfer
and exchange of information on the network to the data. LAN, WAN, PAN etc are examples
of network gateways.
Applications:
Applications is end layer of an IoT system. Applications are essential for the user to work
on the data collected from the sensor . These cloud based applications are built to emphasize
the data analytics and business intelligence. Applications are monitored and controlled by
users.Various services are also delivered to end users with the help of the
application..Examples of applications are: home automation apps, security systems, industrial
control hub etc.
In Figure 2, the extreme right block forms the application end of the IoT system.
Voltage Regulator
The function of the voltage regulator is to control the voltage given to the Arduino board
and stabilize the DC voltages used by the processor and other elements.
Crystal Oscillator
The crystal oscillator helps Arduino in dealing with time issues. How does Arduino
calculate time? The answer is, by using the crystal oscillator. The number printed on top
of the Arduino crystal is 16.000H9H. It tells us that the frequency is 16,000,000 Hertz or
16 MHz.
Arduino Reset
You can reset your Arduino board, i.e., start your program from the beginning. You can
reset the UNO board in two ways. First, by using the reset button (17) on the board.
Second, you can connect an external reset button to the Arduino pin labelled RESET (5).
Analog pins
The Arduino UNO board has six analog input pins A0 through A5. These pins can read
the signal from an analog sensor like the humidity sensor or temperature sensor and
convert it into a digital value that can be read by the microprocessor.
Main microcontroller
Each Arduino board has its own microcontroller (11). You can assume it as the brain of
your board. The main IC (integrated circuit) on the Arduino is slightly different from
board to board. The microcontrollers are usually of the ATMEL Company. You must
know what IC your board has before loading up a new program from the Arduino IDE.
This information is available on the top of the IC. For more details about the IC
construction and functions, you can refer to the data sheet.
ICSP pin
Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino consisting of
MOSI, MISO, SCK, RESET, VCC, and GND. It is often referred to as an SPI (Serial
Peripheral Interface), which could be considered as an "expansion" of the output.
Actually, you are slaving the output device to the master of the SPI bus.
Power LED indicator
This LED should light up when you plug your Arduino into a power source to indicate
that your board is powered up correctly. If this light does not turn on, then there is
something wrong with the connection.
TX and RX LEDs
On your board, you will find two labels: TX (transmit) and RX (receive). They appear in
two places on the Arduino UNO board. First, at the digital pins 0 and 1, to indicate the
pins responsible for serial communication. Second, the TX and RX led (13). The TX led
flashes with different speed while sending the serial data. The speed of flashing depends
on the baud rate used by the board. RX flashes during the receiving process.
Digital I/O
The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide PWM (Pulse
Width Modulation) output. These pins can be configured to work as input digital pins to
read logic values (0 or 1) or as digital output pins to drive different modules like LEDs,
relays, etc. The pins labeled “~” can be used to generate PWM.
AREF
AREF stands for Analog Reference. It is sometimes, used to set an external reference
voltage (between 0 and 5 Volts) as the upper limit for the analog input pins.
fig:3.14 arduino board
Starting clockwise from the top center:
Analog Reference pin (orange)
Digital Ground (light green)
Digital Pins 2-13 (green)
Digital Pins 0-1/Serial In/Out - TX/RX (dark green) - These pins cannot be used for
digital i/o (digitalRead and digitalWrite) if you are also using serial communication
(e.g. Serial.begin).
Reset Button - S1 (dark blue)
In-circuit Serial Programmer (blue-green)
Analog In Pins 0-5 (light blue)
Power and Ground Pins (power: orange, grounds: light orange)
External Power Supply In (9-12VDC) - X1 (pink)
Toggles External Power and USB Power (place jumper on two pins closest to desired
supply) - SV1 (purple)
USB (used for uploading sketches to the board and for serial communication between
the board and the computer; can be used to power the board) (yellow)
Microcontrollers in Arduino
ATmega328P (used on most recent boards)
Digital I/O Pins 14 (of which 6 provide PWM output)
Analog Input Pins 6 (DIP) or 8 (SMD)
DC Current per I/O Pin 40 mA
Flash Memory 32 KB
SRAM 2 KB
EEPROM 1KB
(datasheet)
ATmega168 (used on most Arduino Diecimila and early Duemilanove)
Digital I/O Pins 14 (of which 6 provide PWM output)
Analog Input Pins 6 (DIP) or 8 (SMD)
DC Current per I/O Pin 40 mA
Flash Memory 16 KB
SRAM 1 KB
EEPROM 512 bytes
(datasheet)
ATmega8 (used on some older board)
Digital I/O Pins 14 (of which 3 provide PWM output)
Analog Input Pins 6
DC Current per I/O Pin 40 mA
Flash Memory 8 KB
SRAM 1 KB
EEPROM 512 bytes
Digital Pins in Arduino
In addition to the specific functions listed below, the digital pins on an Arduino board can be
used for general purpose input and output via the pinMode(), digitalRead(), and digitalWrite()
commands. Each pin has an internal pull-up resistor which can be turned on and off using
digitalWrite() (w/ a value of HIGH or LOW, respectively) when the pin is configured as an
input. The maximum current per pin is 40 mA.
• Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. On the
Arduino Diecimila, these pins are connected to the corresponding pins of the FTDI USB-to-
TTL Serial chip. On the Arduino BT, they are connected to the corresponding pins of the
WT11 Bluetooth module. On the Arduino Mini and LilyPad Arduino, they are intended for
use with an external TTL serial module (e.g. the Mini-USB Adapter).
•External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low
value, a rising or falling edge, or a change in value. See the attachInterrupt() function for
details.
• PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function. On
boards with an ATmega8, PWM output is available only on pins 9, 10, and 11.
•BT Reset: 7. (Arduino BT-only) Connected to the reset line of the bluetooth module.
• SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication,
which, although provided by the underlying hardware, is not currently included in the
Arduino language.
• LED: 13. On the Diecimila and LilyPad, there is a built-in LED connected to digital pin 13.
When the pin is HIGH value, the LED is on, when the pin is LOW, it's off.
Analog Pins in Arduino
In addition to the specific functions listed below, the analog input pins support 10-bit analog-
to-digital conversion (ADC) using the analogRead() function. Most of the analog inputs can
also be used as digital pins: analog input 0 as digital pin 14 through analog input 5 as digital
pin 19. Analog inputs 6 and 7 (present on the Mini and BT) cannot be used as digital pins.
•I2C: 4 (SDA) and 5 (SCL). Support I2C (TWI) communication using the Wire library
(documentation on the Wiring website).
Power Pins in Arduino
•VIN (sometimes labelled "9V"). The input voltage to the Arduino board when it's using an
external power source (as opposed to 5 volts from the USB connection or other regulated
power source). You can supply voltage through this pin, or, if supplying voltage via the
power jack, access it through this pin. Note that different boards accept different input
voltages ranges, please see the documentation for your board. Also note that the LilyPad has
no VIN pin and accepts only a regulated input.
•5V. The regulated power supply used to power the microcontroller and other components on
the board. This can come either from VIN via an on-board regulator, or be supplied by USB
or another regulated 5V supply.
•3V3. (Diecimila-only) A 3.3 volt supply generated by the on-board FTDI chip.
•Reset. (Diecimila-only) Bring this line LOW to reset the microcontroller. Typically used to
add a reset button to shields which block the one on the board.
3.7 Arduino Board IDE Programming
Arduino IDE
Once the software has been installed on your computer, go ahead and open it up. This is the
Arduino IDE and is the place where all the programming will happen.
1. Menu Bar: Gives you access to the tools needed for creating and saving Arduino
sketches.
2. Verify Button: Compiles your code and checks for errors in spelling or syntax.
3. Upload Button: Sends the code to the board that’s connected such as Arduino Uno in
this case. Lights on the board will blink rapidly when uploading.
4. New Sketch: Opens up a new window containing a blank sketch.
5. Sketch Name: When the sketch is saved, the name of the sketch is displayed here.
6. Open Existing Sketch: Allows you to open a saved sketch or one from the stored
examples.
7. Save Sketch: This saves the sketch you currently have open.
8. Serial Monitor: When the board is connected, this will display the serial information
of your Arduino
9. Code Area: This area is where you compose the code of the sketch that tells the board
what to do.
10. Message Area: This area tells you the status on saving, code compiling, errors and
more.
11. Text Console: Shows the details of an error messages, size of the program that was
compiled and additional info.
12. Board and Serial Port: Tells you what board is being used and what serial port it’s
connected to.
The general coding is very similar to that of C/ C++ except for a few special functions to
access the board and the initialisation also varies.
Code:
void setup(){
// open a serial connection to display values
Serial.begin(9600);
//set up the Pin of the Led
pinMode(ledPin,OUTPUT);
}
void loop(){
sensorVal = analogRead(sensorPin);
potentiometerVal = analogRead(potentiometerPin);
GENERATIONS OF RASPBERRY PI
All models feature a Broadcom system on a chip (SoC) with an integrated ARM-
compatible central processing unit (CPU) and on-chip graphics processing unit (GPU).
Raspberry Pi 1 Model B (2012),
Raspberry Pi 1 Model B+(2014).
Raspberry Pi 2(2015),
Raspberry Pi Zero (2015)
Raspberry Pi Zero W (2018)
Raspberry Pi 3 Model B ( 2016)
Raspberry Pi 3 Model B+ (2018)
Raspberry Pi 4 Model B (2019)
Install the OS
his involves connecting a keyboard, mouse, and monitor. With this
setup, you are likely best served by installing Raspbian with
Desktop, which gives you a full graphical user interface (GUI) to work
with. This is the best option if you want an experience similar to
working with other operating systems (OS), such as Windows,
macOS, or other popular Linux flavors, like Ubuntu.
IDLE
IDLE is the default Python editor that has been available on Raspbian for
many generations. The good news is that it has a built-in interpreter,
which allows you to run commands one at a time to test code. The bad
news is that it doesn't show line numbers, and it only works with Python
(but you're only here for Python anyway, right?).
Open IDLE by selecting the Raspberry Pi logo in the top-left, and click Programming
> Python 3 (IDLE). You should be presented with the Python interactive interpreter.
Click File > Save As... to save your code to a Python file (don't forget the .py
suffix!). Click Run > Run Module to run your program.
Geany
Geany is a great, beginner-friendly IDE that works with many different
languages. However, it does not start up with a Python interactive
interpreter. You can open Geany up by click on the Raspberry Pi logo in the
top-left, and
selecting Programming > Geany. Write your code in the file editor pane.
configure your pi
sudo raspi-config
Use Python 3
By default, Raspbian (Stretch version April 2018 and earlier) uses Python
2. However, versions 2 and 3 come installed by default. We just have to
make 1 minor pytho
change so that the Pi uses Python 3 whenever we n into a terminal.
type In a terminal window, enter the following
command:
python –version
nano ~/.bashrc
alias python='/usr/bin/python3'
Raspberry Pi Pinout
One of the things that makes the Raspberry Pi better for learning electronics than most other
computers is its ability to control the voltage on several of its easily accessible pins. If you
hold your Pi facing up in portrait mode (as shown in the photo below), on the right side, you
will see a header with 40 pins. This header contains outputs for 3.3V, 5V, Ground, and lots of
General Purpose Input/Output (GPIO) pins!
Note that pin 1 is on the top left of the header, as shown in the photo. With pin 1 in this
position, we can see what each of the pins is used for:
Hardware Connections
You can connect the Raspberry Pi to the LED and button directly, or you can go through
the SparkFun Pi Wedge to make the connections easier on a breadboard. The important thing
is to note that we are using the GPIO numbers in our code (listed as Gx on the Pi Wedge,
where x is the GPIO number). These GPIO numbers are shown in the yellow boxes in the
GPIO Pinout diagram above.
Connect GPIO12 (pin 32) to the 330Ω resistor, and the resistor to the LED
Connect GPIO4 (pin 7) to the button
Make the power (3.3 V) and ground (GND) connections as shown in the Fritzing
diagram
Having trouble seeing the diagrams? Click on them to see the full-size version!
If you have a Pi Wedge, it can make connecting to external hardware on a breadboard easier.
If you don't, you can still connect directly to the Raspberry Pi with jumper wires.
Connecting through a Pi Wedge:
Connecting directly to the Raspberry Pi:
Note
Code Part 1: Blinking an LED
Depending on your version of Raspbian, you may or may not have to install the RPi.GPIO
package (e.g. Raspbian Lite does not come with some Python packages pre-installed). In a
terminal, enter the following:
import time
import RPi.GPIO as GPIO
# Pin definitions
led_pin = 12
# Suppress warnings
GPIO.setwarnings(False)
# Blink forever
while True:
GPIO.output(led_pin, GPIO.HIGH) # Turn LED on
time.sleep(1) # Delay for 1 second
GPIO.output(led_pin, GPIO.LOW) # Turn LED off
time.sleep(1) # Delay for 1 second
Save the file (I named my file blink.py). Run the code from the terminal by entering:
python blink.py
You should see your LED begin to blink on and off every second:
Once you've gotten bored of watching the LED, end the program by pressing ctrl + c.