IOT lab ManualArduino_IOTArduino_IOTArdu

deepikayadav216323 66 views 86 slides Sep 19, 2024
Slide 1
Slide 1 of 86
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86

About This Presentation

Arduino_IOT


Slide Content

Experiment - 1

Functional Testing of Devices

You are going to take a first look at Raspberry Pi! You should have a Raspberry Pi computer

infront of you for this, The computer shouldn't be connected to anything yt

USB ports — these are used to connect a mouse and keyboard. You can also connect

other components, such as a USB drive

SD card slot you can slt he SD card in here. This is where the opera

software and your files ae stored

Ethemet port — this is used 10 connect Raspberry Pi to a network with a cable
Raspberry Pi can also connect 1 a network via wireless LAN,

Audio jack — you can connect headphones or speakers hc

J+ HDMI por — this is where you connect the monitor (or projector) that you are using
to display the output from the Raspbery Pi. If your monitor has speakers, you can also
use them 10 hear sound,

Micro USB power connector — this is where you connect a power supply. You should
always do this lat, afer you have connected all your other components
GPIO pons — these allow you to connect electronic components such as LEDs and

butions to Raspberry Pi

If you have an SD card that doesn't have the Raspberry Pi OS operating system on it yet, orif
Iyou want to reset your Raspberry Pi, you can easily install Raspberry Pi OS yourself. To do
so, you need a computer that has an SD card port — most laptop and desktop computers have
The Raspberry Pi OS operating system via the Raspberry Pi Imager

Using the Raspberry Pi Imager isthe easiest way o install Raspberry Pi OS on your SD card
Note: More advanced users looking to install a particular operating system should use this
[guide oinsaling operating system images.

|Donntoad and launch the Raspberry Pi Image

Visit the Raspberry Pi downloads page

$ mene cn mo

Click onthe ink fo sry Piln system

[===]

When the download finishes, lic ito launch th install

Bun o ct ne mn en mon

Using the Raspberry Pi Imager
Anything thats stored on the SD card will be overwritten during formatting. your SD card
currently has any files on ite. fom an older version of Raspberry Pi OS, you may wish to
[ack up these files First 10 prevent you from permanently losing them,

[When you launch the installer, your operating system may try to block you from running it

Windows protected your PC

this pops up. cick on BEN an then ETE

Follow the instructions t install and un the Raspberry P Ima

Insert your SD card into the computer or laptop SD card slot

In the Raspherry Pi Imager, select the OS that you want to instal and the SD card you

would like to instal it on
Note: You will need to be connected tothe internet thefts time For the the Raspberry Pi
Imager to download the OS that you choose, That OS will then be stored for future offline
use. Being online for later uses means thatthe Raspberry Pi imager will always give you th

$

Raspberry Pi

i's HDMI port

shelled HDMI.

ngle HDMI pon.

up on the Raspberry Pi which indicates that Raspberry Pi is

appear in he top left-hand comer of your creen

After few seconds the Raspberry Pi OS desktop will appear

Finish the setup

[When you start your Raspberry Pi fr the first time, the Welcome to Raspberry Pi applic

J+ Click Nexto stat the setup

ind lick Next

Change Password

clicking Next

Select WiFi Network

Note: if your Raspberry Pi model doesn't have wireless connectivity, you won't see this

Next lt the wizard check for updates to Raspbian and install them (his might take a

Update Software

Click Done or Reboot to finish the setup.

Note: you will only need to reboot if thats necessary to complete an up

Setup Complete

Now is time to take a tour of your Raspberry Pi.
Do you see the raspberry symbol in the top left-hand comer? That's where you access the
‘menu: click on ito find los of applications
Click on Accessories, and then cick on Text Edito

oe

Your il has been saved to your Raspberry i's SD card
Close the text editor by clicking the X in the top right-hand comer of the window
Return 10 the menu, click on Shutdown, and then click on Reboot,

When Raspherr Pi has rebooted, your text file should sill be there on the desktop
Raspberry Pi runs a version of an operating system called Linux (Windows an

macOS are other operating systems). This operating system allows you to make thin

happen by typing in commands instead of clicking on menu options. To try this ou

ick on the Terminal symbol at he top of the screen

and then press Enter onthe keyboard

Now type this command to change directory tothe Desktop:
fod Desktop
You have to press the Enter key alter every cı

[Can you see the text file you create
Close the terminal window by licking on the X

4 on the desktop so the Raspberry P will be tidy for the

Wastebasket

Browsing the web

You might want to connect your Raspberry Pi tothe intenet. If you didn't plug in an ethernet

cable or connect toa WiFi network during the setup, then you can connect n

Click the icon wit red crosses inthe top right-hand comer of the seen, and select your
network from the drop-down menu. You may need 10 ask an adult which network you

should choose

Type in the password for your wireless network, or ask an adult type it for you, then

lick OK

When your Pi is connected tothe intemet, yo symbol instead of

|Configuring your Raspberry Pi

ne Raspberry Pi Configuration application found in Preferences on the menu.

fe Network at Boot — selecting this option will cause your Raspberry Pi to wait until a
network connection is available before stating
+ Splash Screen — choose whether or not 10 show the splash (startup) screen when your
Rasperry Pi boots
J+ tnerfaces
You can link devices and components to your Raspberry Pi using a lt of differen types of
connections. The Interfaces tab is where you tum these diferent connections on or off, so
nat your Raspberry Pi recognises that you've linked something toi via a particular type of

Camera — enable the Raspberry Pi Camera Module
SSH allow remote access to your Raspberry Pi from another computer using
ss

VNC — allow remote access tothe Raspberry Pi Desktop from another computer

using VNC

SPL enable the SPI GPIO pins

12C — enable the 12C GPIO pins
Serial — enable the Serial (Rx, Tx) GPIO pins

Wire — enable the 1-Wire GPIO pin

Remote GPIO — allow access to your Raspberry Pi’s GPIO pins from another

IF you need to do so for a particular project you want to work on, you can change the
performance settings of your Raspberry Pi inthis tb,
[Waming: Changing your Raspbemy Pi’s performance settings may result in it behavin

erratically or not workin

J+ Overclock — change the CPU speed and voltage o increase performance

J+ GPU Memory — change te allocation of memory given 10 the GPU

This ab allows you to change your Raspberry Pi setings to be specific to a country or
location,

+ Locale — set the language, country, and character set used by your Raspberry Pi

Keyboard — change your keyboard layout

WiFi Country — se the WiFi country cod

To connect a Raspberry Pi 1 a laptop display, you can simply use an Ethernet cable. Th
Raspberry Pis desktop GUL (Graphical User Interface) can be viewed through the laptop]
[display using a 100 Mbps Ethemet connection between the two, There are many software
programs available that can establish a connection between a Raspberry Pi and your laptop.
[We used VNC server software to connect the Pi to our laptop. Installing the VNC server on
your Pi allows you to see the Raspberry Pi’s desktop remotely, using the mouse and keyboard
as if you were sitting right in front of your Pi. I also means that you can put your Pi
lanywhere ele in your home and still contol it, Alo, the internet can be shared from your
laptop's WiFi over Ethernet, This also lets you access the intenet on the Pi and connect it to

Before moving to connect your Raspberry Pi to your laptop display. you need an SD card
with the OS preinstaled, or install Raspbian on a blank SD card. You will find lts of blogs

Ian tuorials on preparing an SD card forthe Raspberry Pi. If you are a beginner, you can

simply click hereand know more about this, This will show how to install the OS for the

Raspberry Pi. You can also buy SD cards with the Raspbian and NOOBS operating systems
preinstalled. would suggest you install the latest full Raspbian OS image from the offical

|Raspberrs Pi website sit is having VNC Server in the OS package

After seting up your SD Card, insert it into the Raspberry Pi. Next, connect your power
Iatapıer tothe Raspberry Pi to power it. Also, connect your Raspberry P to the laptop via an

theme cable and connect a Keyboard and mouse toi

Note: You need screen and a mouse after booting a new OS into Pi forthe first time as by
led in Pi. Without SSH disabled, we cannot enable the

leur r¥ Configuration.

[Sharing Internet Over Ethernet

This step explains how you can share your laptop intemet with the Raspberry Pi via Ethemet
cable. In Windows: To share the interet with multiple users over Eihemet, go to Network

d Sharing Center. Then click on the WiFi network

[Click on Properties (shown below), then go to Sharing and click on “Allow other network
users to connect”. Make sur that the networking connection is changed to the connection of

Ihe Raspberry Pi. In my ease, ii E

By default, the laptop will ive a dynamic 1P co the Raspberry Pi, Thus, we have 10 find out

As shown above, the IP assigned to my Pi is 192.168.137.144, To check the IP assigned to

Ihe connected Ethemet device, do the following. Considering thatthe IP assigned to your Pi

is 192.168.137.144 and the subnet mask is 255.288.255.0

‘Open the command prompt.

Ping at raspherryp.msho

Here, itis 192.168.137.154, Note this somewhen

PuTTY Configuration and VNC on Ras

In the Host Name, enter the IP Address we noted from the command
Ensure that the Connection Type is SSH.

Hit Enter or click on Open to proceed.

Now, a new window will open. It looks like a normal terminal window ofthe computer but
itis Raspberry P's terminalwindow accessible on your laptop.

lis display login as

Enter pi asthe usemame,

Enter the password you set for dhe Raspberry i, The default password is raspberry

IF the password is correct, the Pi wil load and you will acess the terminal window of the
Pi

Now, you need to sar the VNC Server, Enter af sudo vneserver

This ist initialize the VNC Server on he Raspher

erver and VNC Viewer on Laptop

Raspberry is ready to connect using VNC. We just need to install the VNC server on

ine laptop.

load UNC Client and install Now, download the VNC Viewerand install it on the
laptop.
(Open the VNC Server and the VNC Viewer now

In the VNC Viewer, click on File > New Connection

Enter IP Address and in Options > Pict

Click OK. Now, double click onthe IP Address.

Enter pl in Usemame and your Pis password (default is raspberry).

Click on Remember Password so that you don't have to enter his next time

Click on OK.

As you hit enter and all the things are correct, the Raspberry Pi Desktop will load in a new

[vindow. You can go into full-screen mode by clicking on the options available above on

Ihe window

[GPIO Pins:

00-00-00:

0000 : 000

own in above figure, thee are output pins for the PL. But when you look atthe second]
igure, you can sce not all 40 pin out can be programmed to our use. These ae only 26 G

pins which can be programmed, Thes rom GPIO2 to GPIO2,

These 26 GPIO pins can be programmed as per need. Some of these pins also perform

some special functions, we will discuss about hat Inter, With special GPIO put aside, we]

Ihave 17 GPIO remaining (Light green Cin).

Each of these 17 GPIO pins can deliver a maximum of 1SmA current, And the sum of

currents from all GPIO cannot exceed SOmA. So we can draw a maximum of mA in vera

from each ofthese GPIO pins. So one should not tamper with th unless you know

what you ae doing

Here we are using Raspherry Pi 2 Model B with Ra

Hardware and Software requirements are previously discussed, you can look it up in

sry Pi Introduction, ober than that we ned

1. On the desktop, go the Start Menu and choose forthe PYTHON 3, as shown in
[below

3. After that, click on Nev File in File Menu, You will see a new Window open,

iy onthe desktop

5. After that write the program for binky as
Ion “RUN” on "DEBUG" option

BD O

Ifthe program has no errors in it, you will see a ">>>", which means the program is executed
successfully. By this time you should see the LED blinking three times. If here were any
errors inthe program, the execution teils o comet it, Once the error is corrected execute the

Experiment — 4

Interfacing Chronos «2430.

The £Z:430 Chronos development kit from Texas Instruments represents great value for
[money and provides a wristwatch with a wirelesscnabled microcontroller, accelerometers
land temperature and barometric pressure sensors, and a USB programmer and RF access

point. In this post I take a look at what it takes to get it up and running with a Raspberny Pi

The Chronos RF access point simply presents itself as a serial port to the operating system
land drives are included in Linux, and so any heavy lifting in enabling communications

between the watch and host has already been done for us

withthe access point plugged into the Raspberry Pi USB we just need to install a few

[acpendencis in oder to run the TI supplied demonstration software and a simple example

Python script. Assuming that you are running Debian Linux this can be achieved usi

IS sudo apt-get instal python-serialtl8.5 RAS x dotoo!

[Chronos Control Center

[Chronos Control Center is a GUL tool that provides a selection of applications which
demonstrate the capabilities of the 62430 Chronos. The Linux version ofthe software must
Ihave been developed with x86 architecture in mind as i's provided as a binary installer eater
Ian a tar archive. However, since i's TeVTK based it should run on just about any
platfornvarchitecture for which this software is available I's trivial o repackage it so that is
Ino architectre-specific, and this just requires access to an InteVAMD Linux machine on

which to un the following commands:

[Suncip slac38Sazip

S /Chronos-Serup

[Sar sen cet -/evas InstrumenteZ430-Chronos

Jobviously if you installed the software o a location other than the default as par of the

second step, you will need o use that location forthe second argument in the third step, The

lcetgz archive can then be copied to the Raspberry Pi and unpacked toa suitable location,

IConrot Center software running. with the access point enabled and the watch set
lo ACC mode and with RF enabled. Realtime data from the watch accelerometers is
displayed, and by selecting Mouse On its also possible to use the watch to control the
Raspberry Pi mouse pointer through gesture, As can be scen the Control Center provides a

[number of other simple applications that can be selected via the tabs at the top.

Setting the time via a Python script

It should be possible o write host-based applications for the Chronos in just about any
language that provides access 10 seria devices. When using the Python language this is

achieved via the pySerial library, and with aessonably short script its possible to

configure the serial por, send the commands required to start up the RF access point, and
linen get the Raspberry Pi system time, format this into packets, transmit them to the watch

and se the time accordingly:

Note that if you do wish to make use of the linked scrip you will need to change the line hat

configure the serial port parameters 0 rea

ser = serial Serialldev/nyACMO,115200.imeow=1)

her the Chronos eZ430 and Raspberry Pi opens up all sors of exciting possibilities,

data can be sourced from the watch sensors or the Internet, processed and pushed in
ther direcion. With the relatively powerful processing capabilities of the Raspberry Pi
being made use of, and its hardware capabilities fuer extended via the GPIO port. As such
it would seem like a winning combination for low cost experimentation with wearable and
ubiquitous computing. And with a Title enhanced suppor from within the Python language, it

is easy to see how the Chronos could become an incredibly fun accessory 10 Raspberty Pi

leased learning in schools

Experiment -

sure the intensity of light in a room using a single photocell and a capacitor connected à
[e raspberry pi witha bit of code in python

what is Phoocell?

a

The Photocel i alight sensor in which the resistance varies ac o the intensity o
hight, The resistance reduces when it is in brighter suroundings. We have 10 set up
hold value for the measurements of the intensity because it
asurements. Ihe measurements are below the threshold then itis
Role of a Capacitor
A Capacitor is an electrical component that can store electrical energy temporarily. I
Jmcasured in Farads which is characterized by capacitance. The capacitor cons
[conductor that can hold the electric charge and when itis fully charged the capacité

[ischarging. This Kind of alternative behavior is used to generate AC

[When the switch is pressed the current starts flowing and the capacitor starts charging up.
hen the voltage at its end reaches the voltage ofthe battery

circuit, no current flows th

GPIO Pin 6 (Ground)

We need 10 measure the resistance of the photoresist, The Raspherry pi acts as the bat

lwhereas the GPIO pin 1 provides 3.3 V to the photoresisto. Make the GPIO pin 12 as the
bidiectional pin input and output pin). When the capacitor is charging it will take some

ch a voltage high. GPIO pin 6 is grounded which is connected

ive side ofthe capacitor (short end). Check how long it takes for the input pin to

become high and use the result to calculate the resistance of the photocell

[Code

measuring the light intensity using a photocell
import RPLGPIO as GPIO aime. import the librar
DEBUG=1
GPIO seimode(GPIO BOARD)
GPIO.setwarings(False)
RCpin): # function tar
GPIO.setupRCpin.GPIO.OUT)
GPIO ouputtRCpin,GPIO LOW)
# time to discharge capacitor
GPIO sctup(RCpin.GPIO.IN)
ile (GPIO.npunRCpin)
#the loop will run il
reading += 1
# measuring time which in tum is measuring
return rea

while Truc
print RCtime(12) #ealling the function

Battery Voltage Indicator using Arduino and LED Bar Graph

Baweries come with a certain voltage limit and ifthe voltage goes beyond the prescribed

limits white charging or discharging, the life of the battery get affected or reduced, Whenever

we use a battery powered project, sometimes we need 10 check the battery voltage level,
whether i is needed to be charged or replaced. This circuit will help you to monitor the
voltage of your battery. This Arduino battery voltage indicator indicates the status of
Ibatery by glowing LEDs on a 10 Segment LED Bar Graph according to the battery

also shows your batter on the LCD connected tothe Arduino.

vent LED Bar Graph
LCD (6

Potentiometr-10k

Resistor (1000hm-10:3300hm)
Battery tobe tested)
Connecting wire

Circuit!

LED Bar G

The LED bar graph comes in industrial standard size witha low power consumption, The bar is
estegoriz for luminous intensity. The produc itself remains within RoHS compliant version I
has forward voltage of up to 26v. The power dissipation per segment is 65m, The operating
temperature ofthe LED bar graph is -40°C to 80°C. There are many application forthe LED bar
raph ke Audio equipment, Instrument panels, and Digital readout display

[Pin Diagram

Anode| [Cathode „,

Pin | Function
Anode a Cathode j
Anode b Cathode i
Anode c Cathode h
Anode d Cathode g
Anode Cathode f
Anode f Cathode e
Anode g Cathode d
Anode h Cathode
Anode i Cathode b
Anode j Cathode a

attery Voltage Indicator
Indicator just read the value from Arduino Analog pin and convert it into a

[digita value by using the Analog to Digital Conversion (ADC) formula, The Arduino Uno
ADC is of 10-bit resolution (so the integer values from 0 = 2°10 = 1024 values). This means
ina i will map input voltages between O and 5 volts into integer values between 0 and 1023,
if we multiply input anlogValue 24), the value of input volag
rn here how to use ADC input in Arduino. Then d ae is y the LED

Experiment - 8

Displaying RSS News Feed On Display Interface
Displaying the RSS news feed headlines on a LCD display connected to device. This ca
[be adapted to ot er or other information website. Python can be

lusea to acquire data from the

Keeping up to date with the latest news is tough and sometimes we need a litle help. RSS
feeds provide great way to quickly digest lots of news quickly, Sure you could visi
or have an RSS reader on your computer, but what if you could havea simple, de

ye feed for example, and display the top five headlines on an LCD screen

1 this project you will need

4 x Female to female jumper

sudo pip install pte feedparser

the RCH pberny Pi Configuration

from sped import LCD
irom time impor sleep
import feedparser

import texwrap

6. Create an object, called “tom” which will sore the RSS feed data from Tom's
Hardware

kom = fecdparser parse “hups:/www.somshardware.comvuk/feedsall")

Create a connection to the LCD and then pause the code for 1 second
ed = LCDO

50

|. Use a for loop to repeat code five times. Ifyou want more han 5 headlines, change the (5)
lo a higher number

fori in rangers)

9. Print the entries from the Tom's Hardware RSS feed. The value of à is increment

10. Create an object called split and use that to save 16 character chunks ofthe RSS feed
The chunk size is set bythe 16 character screen size ofthe LCD,

spit =textwrop.wraptes, 16)

11. Create an object called split and use that to save 16 character chunks of the RSS f
The chunk size is se by the 16 character screen size ofthe LCD.

12. Print “Tom's Hardware” (or the name of your news source

LCD screen,

icatexu"Fomis Hardware", 1)

13. Create another for loop to print the contents ofthe spit object to the LCD seres

Jed.text(pltil. 2)
sleep(0.5)

14. Add a one second pause before clearing the LCD screen.

sleep)

e.ctean)

15. Save the code as TomsRSSFeed.py

Experiment - 9

A Raspberry Pi within an Ethemet network can be used as a wireless access point, creating

secondary network, The resulting new wireless network is entirely managed by the Raspberry
i.
work to wireless clients, consider instead setting

I you wish to extend an existing Ethernet

A routed wireless access point can be created using the inbuilt wireless features of the

Raspberry Pi 4. Raspberry Pi 3 oF Raspberry Pi Zero W, orby using a suitable USB wireless

dongle hat supports acces point mode. Itis possible that some USB dongles may need slight

Jchanges to their stings I you are having trouble with a USB wireless dongle, please check

ine

This documentation was tested on a Raspherry Pi 3B running a fresh installation of Raspheery

Pi OS Buster

Ensure you have administrative access to your Raspberry Pi. The network setup will
be modified as part of the installation: local access, with screen and keyboard
connected to your Raspherr Pi is recommended

Connect your Raspberry Pi tothe Eihemet network and boot the Raspberry Pi OS.
Ensure the Raspberry Pi OS on your Raspberry Pi is ind reboot if packages
were installed in the process,

Take note of the IP configuration of the Ethemet network the Raspberry Pi is

In this document, we assume IP network 10.10.0.024 is configured on the

Ethemet LAN, and the Raspberry Pi is going to manage IP

network 192.1684,0/24 for wireless clients
Please select another IP network for wireless, e. 192.168.10.0724 if 1P|

network 192.1684.0/24 is already in use by your Ethernet LAN.

In onder to work as an acces point, the Raspberry Pi needs 1 have the hostapd access point
software package installed

sudo apt install bostapd

Enable the wireless access point service and st it to start when your Raspberry Pi boots:

sudo systemet unmask hostapd

sudo systemetl enable hostapd
In order 10 provide network management services (DNS, DHCP) to wireless clients, th
Raspberry Pi needs to have the dnsmasq software package installed

Finally, install nefiter-persstet and its plugin iptabes-persistent This wily helps by

[saving firewall rules and restoring them when the Raspberry Pi boots:

sudo DEBIAN FRONTEND=nonintractive apt install -y_netfilte-persistent iptables

[Sofware installation is complete

The Raspberry Pi will run and manage a standalone wireless network. It will also route
lberween the wireless and Ethernet networks, providing interet access 10 wireless clients. I
you prefer, you can choose t skip the routing by skipping the section “Enable routing and IP

nasquerading” below, and run the wireless network in complete isolation.

The Raspbemy Pi runs a DHCP server for the wireless network; this requires static IP

configuration for the wireless interface € wlan ) in the Raspberry Pi, The Raspberry Pi also

dress in the network: 192.168.4.1

sudo nano fte/dheped.cont

Go 0 the end ofthe file and add the following

interface wland
state ip_address=192.1684.1/24

hook wpa_supplicant

This section configures the Raspberry Pi to let wireless clients access computers on the main
ethernet) network, and from there the internet. NOTE: If you wish o block wireless clients
rom accessing the Ethernet network and the intenet, skip this section

To enable routing, i. to allow tafe 1 low from one network tothe other in he Raspberry

sudo nano fetesyset d/routed-ap conf

lps www aspherypi.ore/documentation/contiguration/wirelessaovess-point-routed md
# Enable [Pvt routing
neti ip_forward=

Enabling routing wil allow hosts from network 192,1684.0/24 to reach the LAN and the

main router towards the internet. In order to allow traffic between clients on this frei
lwicless network and the internet without changing the configuration of the main router th
Raspberry Pi can substitute the IP address of wireless clients with is own IP address on the
LAN using a “masquerade” firewall rule
+ The main router will see all outgoing traffic from wireless clients as coming from the
Raspberny Pi, allowing communication withthe inem
+ ‘The Raspberry Pi will receive all incoming traffic, substitute the IP addresses back,
and forward traffic tothe original wireless client

This process configured by adding a single firewall rule inthe Raspberry Pi:

sudo iptables «nat -A POSTROUTING -0 ch -j MASQUERADE

Now save the current firewall rules for IPv (including the rule above) and Pv tobe loads

Filtering rules are saved to the directory /eteiptables/. If in the future you change the

[Configure the DHCP and DNS services for the wireless network

The DHCP and DNS services are provided by dnsmasq . The default configuration file

Rename the default configuration file and edita new one

sudo my /ete/dnsmasq conf /ete/dnsmasq.conf orig

Add the following tothe file and save it
inteface=wlan0 # Listening interface
dhep-range=192.168.4.2,192.168.4.20255.255.255.0.24h
# Pool of IP addresses served via DHCP
domainzwlan # Local wireless DNS domain
address=/gw.wlan/192.168.4.1

# Alias for this router

The Raspberry Pi will deliver IP addresses between 192.168.4.2 and 192.168.4.20 , with a

ease time of 24 hours 1o wireless DHCP clients. You should be able to reach the Raspberry

I fetetdnsmasg cont ) or the for details

[counties around the world regulate the use of telecommunication radio frequency bands 10
ensure interference-ree operation. The Linux OS helps users comply with these rules by

allowing applications o be configured with a wo-leter “WiFi country code”, eg. US for

[computer used in the United States
Inthe Raspbemy Pi OS, 5 GHz wireless networking is disabled uni a WiFi country code has
Ibsen configured by the user, usually as par of the intial installation process (see wireless
configuration pages in this seston For details

To ensure WiFi radio is not blocked on your Raspberry Pi, execute the following command:

sudo kil unblock wlan

This setting wil be automatically restored at boot time, We will define an appropriate

[Create the hostapd configuration file located at /tcostapd/hostapd.conf to add the
various parameters for your new wireless network

sudo nano /ee/hostapdfbostapdconf

Add the information below tothe configuration file, This configuration assumes we are using

channel 7, with a network name of NameOFNetwork, and à

password AardvarkBadgerHedgehog | Note thatthe name and password should not have

|quotes around them, The passphrase shouldbe between and 64 characters in length,

country_code
imterface=wland
ssid=NameOtNetwork
hu_modesg
channel=7

auth ales
ignore_broadeast_ssid=0
wpa

‘wpa passphrase=A ardvarkBadgerHedgehog
wpa_key_mgmt=WPA-PSK
‘wpa. pairwise=TKIP

the Tine counuy codo ures the computer 1 use the comect wireless

frequencies in the United Kingdom, Adapt this line and specify the two-eter ISO code of

your country. Se for alist of two-letter ISO 3166-1 country codes.

To use the 5 GHz band, you can change the operations mode

rom hw_mode=g to hw_mode=a Possible values for hw_mode are
IEEE 802.114 (S GHz) (Raspberry Pi 3B+ onwards)

IEEE 802.11b 2.4 GHz)
=IEEE 802.11g 2.4 GHz)

hat when changing the hw_mode , you may need to also change the channel

for ais of allowed combinations

Now restart your Raspbemy Pi and verify that the wireless access point bes

[Once your Raspberry Pi has restated, search for wireless networks with your wireless client

The network SSID you specified in file /eteostapd/hostapd conf should now be present,

If SSH is enabled on the Raspberry Pi, it should be possible to connect 10 it from your
vieles client as follows, assuming the pi account is present: ssh pi@ 192,168.41 or ssh
[email protected]

IF your wireless client has access to your Raspberry Pi (and the interne if you set up

| Experiment - 10 |

update

[Test the web server

By default, Apache puts a test HTML fie in the web folder. This default web page is «

Jwhen you browse to hup./localhos on the Pi itself, or hutp//192.168.1.10 (what

Pis IP address is) from another computer on the network, To find the Pis IP

shout finding your IP address),

ype hostname -1 atthe command ine (or cad m

Browse o the default web page ether on the Pi or from another computer onthe network and

Apache2 Debian Default Page

debian

This means you have Apache working!

[Changing the default web page

This default web page is just an HTML file on the filesystem, I is located

at armes html

Navigate 0 this directory in a terminal window and have a ook at whats inside

total 12
drwxe-xe-x 2 root root 4096 Jan 8 01:29
druxr-xr-x 12 root root 4996 Jan 8 01:28

rw-r--p-- 1 root root 177 Jan 8 01:29

This shows hat by default there is one file in varhwww/htmi/ called index.html and it à

rook user (as is the enclosing folder). In order to eit the file, you need to
menti {0 your own usemame, Change the owner of the fil
fault pi user is assumed here) using sudo chown pi index.hml

You can now try editing his file and then refreshing the browser to

HTML you can put your own HTML files and other assts inthis directory and

erve them as a website on your local network

|Additional - install PHP

To allow your Apache server to process PHP files, you'll need o install the latest ve:

PHP and the PHP module for Apache. Type the following command to install the

php Libapache2-mod-php -y

index php
Pr o ca]

<?php echo “hello world"; >

and refresh your b namic but
PHP. Tr

<?php echo date(Y-mvd Hii

Experiment — 11

Webcam Server

Rather than using the Raspberry Pi you can use a standard USB]
[webcam to take pictures and video on the Raspberry Pi
Note that the quality and configurability of the camera module is highly superior to

la standard USB webcam.

First, instal the webcam package:

al fs

If you are not using the default pi user account, you need to add your username 10)

the video group, otherwise you will see ‘permission denied’ errors

sudo usermod a -G video <u

To check that the user has been added to the group correctly, use|

the groups command.

Enter the command fswebcam followed by a filename and a picture will bel

taken using the webcam, and saved to the filename specified:

This command will show the following information:

Opening Kehren,
Trying source module al.
fev ideoD opened
No input was specified, using the ist
Adjusting resolution from 384x288 to 35
Capturing frame
Comupt JPEG data: 2 extraneous byes before marker Oxdt
Captured frame in 0.00 seconds
Processing captured image.

Weting JPEG image to imagejog

Note the small default resolution used, and the presence of a banner showing the

imestamp.

ISpecify resolution

The webcam used in this example has a resolution of 1280 x 720 so to specify the

[resolution I want the image to be taken at, use the -r fla

This command will show the following information:

Opening ievivideod,

[dexivideoo opened.
No input was specified, using the fist.
Capturing frame
Comupt JPEG data: 1 extrancous byes before mark:
Captured frame in 0.00 seconds
Processing captured image

Writing JPEG image to image? jpg

Picture now taken atthe full resolution of the webcam, with the banner present

[Specify no banner

Now add the -no-anner fla

mer 1280x

[which shows the following information:

Opening idevivideod,
Trying source module vi.
idexivideoo opened
No input was specified, using the ist.
Comupt JPEG data: 2 extraneous bytes before marker 0xd6
(Captured frame in 0.00 seconds
Processing captured image
Disabling banner

Writing JPEG image 1 image jpg

Now the picture is taken at full resolution with no banner,
Bad Pictures
ou may experience poor quality pictures with a USB webcam, such as this

[accidental artiste piece

¡Some webcams are more reliable than others, but this sor of issue may occur with

[poor quality webcams, IF the problem persists, ensure your system is up 10 dat

Also try other webcams, but you'll get the best performance from the Raspberry

Bash seript

You can write a Bash script which tal

a picture with the webcam. The script

& Ihomelpilwedcam directory, So creat
webcam subdirectory first with:

webcam

ample

Y Gon %d_ HAM

Iswebcam -r 1280x720

no-banner /home/pi/webcaníSDATE jpg

[This script will take a picture and name th

ile with a timestamp. Say we saved it
cams

e would first make th

+x webcam.sh

Then run with

webcam sh

[Which would run the commands in the fie and give the usual output:
Opening ievivideod,
[dexivideoo opened

No input was specified, using the fist.
Capturing fram

xtrancous bytes before mark

Captured fran

Writing JPEG image 10 omelpilwebcam/2013:06-07.2338 jpg

You can use cron to schedule taking a picture at a given interval, such as every

minute to capture a time-lapse

First open the cron table for editin

crontab -e

This will either ask which editor you would like 10 use, or open in your default editor. Once

[you have the file open in an editor, add the following ule taking a picture every

ring to the Bash script from above)

homelpi/webcamsh 2> 81

[Save and exit and you should see the m

ame filename. This

Ensure your script does not save each picture taken with the

[will overwrite the picture each time
Tags