text:
Wikijunior:Raspberry Pi/Introduction to Electronics

Electricity is energy
Electricity is one form of energy and most energy originates from the sun.

The law of conservation of energy states that that energy can neither be created nor destroyed; rather, it can only be transformed or transferred from one form to another. Such as:

 * sunlight to electricity – solar panels
 * sunlight to heat energy – solar furnace
 * chemical energy to electricity – batteries

Conductors
Conductors are materials that allow electricity to flow through them easily. Electrons are tiny particles that orbit around the nucleus of an atom. In conductors, the electrons are loosely bound to the nucleus and can move freely. This means that when an electric current is applied to a conductor, the electrons can flow in the direction of the current.

Some examples of conductors include:

 * Metals such as copper, gold and aluminium
 * Water and other liquids that contain ions (charged atoms)
 * Graphite, a form of carbon

Conductors are used in many different ways, including:

 * To make electrical wires and cables
 * To make parts for electrical devices, such as appliances and computers
 * To make heating elements, such as those used in stoves and hair dryers

Insulators
Insulators are materials that do not allow electricity to flow through them easily. Electrons in insulators are tightly bound to the nucleus and cannot move freely. This means that when an electric current is applied to an insulator, the electrons cannot flow and the current is blocked.

Some examples of insulators include:

 * Plastic
 * Rubber
 * Glass
 * Wood
 * Air

Insulators are used in many different ways, including:

 * To coat electrical wires and cables to prevent electricity from leaking out
 * To make electrical insulators, such as those used in power lines and electrical outlets
 * To make thermal insulators, such as those used in homes and buildings to keep heat in during the winter and out during the summer

Semi-conductors
Semi-conductors are materials that have properties that fall somewhere between conductors and insulators. Their electrical conductivity can be controlled by adding impurities or by applying an electric field.

Semi-conductors are used in many different electronic devices, such as transistors, diodes, and integrated circuits. These devices are used in computers, smartphones, and other electronic devices.

Conductors vs. Insulators
Imagine that conductors are like motorways and insulators are like country roads. Electrons are like cars. On a motorway, cars can travel quickly and easily. On a country road, cars have to go slower and more carefully.

In a conductor, the electrons can move freely, like cars on a motorway. With insulators the electrons cannot move freely like cars on a country road.

Current, Voltage, Resistance and Power
There are 4 main units for measuring electricity. Each unit is named after a scientist who made significant discoveries related to it.

Water flowing through a pipe:

 * Voltage is like the water pressure in a pipe. The higher the voltage, the more water will flow through the pipe.
 * Resistance is like the width of the pipe. The narrower the pipe, the less water will flow through it.
 * Current is like the amount of water flowing through the pipe. The more current, the more water is flowing through the pipe.
 * Power is like the amount of work that is being done by the water. The higher the power, the more work is being done.

Ohm's law

Ohm's law states that the current (measured in Amps) is proportional (this means there is a consistent ratio) to the voltage (measured in Volts). From there, it is possible to calculate the resistance (measured in Ohms).

 * Voltage = Current × Resistance
 * Current = Voltage ÷ Resistance
 * Resistance = Voltage ÷ Current

Finding the current, voltage or resistance is easy. Just cover which of the three you are looking for with your hand! 🤚

Toy car example

For example: ×2 AA batteries (which provide 1.5 Volts each) power a toy car. The voltage of the battery is 3 Volts, the resistance of the toy car's motor is about 1 Ohm, and the current is about 3 Amps.

 * The actual current and resistance of the toy car's motor may vary depending on the specific motor.
 * The voltage of the batteries will decrease as they discharge. This means that the current will also decrease as the batteries discharge – this will make the car drive more slowly over time.
 * The toy car's motor will draw more current if it is moving faster. This is because the resistance of the motor will decrease as it heats up.

SI prefixes
Many of the units we use are defined and standardised by the Systems International (SI) institution in France including the Amp, the Volt and the Ohm.

The SI prefixes should be familiar as we use them every day for units such as the metre (m) and the gram (g). This prevents us from writing out a lot of zeros. Each prefix multiplies the unit (the capital letter prefixes) or divides the unit (the lowercase prefixes).

The Greek letter mu (μ) is used for micro. You may be familiar with a kilogram (1000 grams) or centimetre (0.01 metres).

Electronic components
Most of these components can be purchased inexpensively from hobbyist stores, eBay sellers or electronic component wholesalers such as RS Components and Farnell.

Breadboard

A breadboard is used to build and test electronic circuits without having to solder the components in place. They are reusable, and the components are also reusable after being used on a breadboard.

All the vertical lines (usually lettered A–E and F–J) are connected in columns. So electricity going into point 1A also arrives at 1B, 1C, 1D and 1E. But there are no connections across rows – so electricity going into point 1A does not arrive at 2A, 3A and so on.

Some breadboards also have extra rows at the top or bottom which are connected vertically, used for positive and negative. We are not using that type of breadboard, and if you are using one then ignore the rows at the top and bottom of your board. Sometimes, these rows are marked with plus + and minus − or are coloured red and blue.

Capacitor
A capacitor stores a small amount of electric charge, then when it is full it lets all the charge go.

 * If you connect it to a strong charge, it lets the charge go faster.
 * If you connect it to a weak charge, it takes longer to let the charge go.

The capacitor has a short and a long leg, and a stripe on one side. Like LEDs, they must be connected with the short leg and stripe to negative (ground).

DuPont jumper wire
A DuPont jumper wire is used to connect components to a breadboard and is compatible with the Raspberry Pi's GPIO pins.

The colours of the jumper wires don't matter, though it's recommended to use black for ground.

Light-emitting diode (LED)

A light-emitting diode (LED) emits light and is programmable meaning you can control them using software such as the GPIO on a Raspberry Pi. They also have other benefits:

 * they are much more energy efficient
 * they don't need to heat up first to produce light and most LEDs produce only a very small amount of heat
 * they are individually smaller than other lightbulbs
 * they are available in a wide variety of colours

Lower value (lower Ohm) resistors will allow more current through and will make the LED brighter; higher values will let less current through and make it dimmer.

Switch
A switch completes the circuit by allowing electricity to flow while it is pressed down. When released, the electricity stops.

There are three types of switches:

 * 1) A momentary switch requires something to continually press it down.
 * 2) A toggle switch is held down once pressed and requires something to unpress it.
 * 3) A reed switch is a glass tube with two bits of metal separated by a tiny gap. When there is a magnet nearby, the two bits of metal touch and allow electricity through. Be very gentle and careful with reed switches because the glass can break easily.

Photocell
A photocell or photoresistor, is a type of variable resistor which provides a different amount of resistance depending on how much light it detects. They let through more current when there is more light.

Piezo buzzer
A piezo buzzer makes a beep when electricity goes through it. It has two "leg" connectors; one long and one short. The long leg must be connected to positive, and the short leg must be connected to ground (negative).

Resistor

A resistor is a simple coil of wire that reduces the current in a circuit, for this reason, it can wired to a circuit any way around without breaking. Resistance itself is measured in Ohms (using the Greek letter Omega Ω) and the coloured bands on each resistor indicate how much resistance each resistor is capable of adding to a circuit.

You may recognise the symbol for a resistor used in circuit diagrams:

 * The American symbol for a resistor is a zig-zag shape representing a coil of wire.
 * The IEC symbol for a resistor is just a rectangular box, often the resistance is written inside of it. IEC symbols are a British Standard which is used throughout the United Kingdom.

Resistor colour bands
The colour bands on each resistor show exactly how much resistance it can provide. This includes tolerance which is good to know in case there is an unexpected change in the current.

 * 1st Band – the first significant figure of component value (left side).
 * 2nd Band – the second significant figure (some precision resistors have a third significant figure, and thus five bands).
 * Multiplier – the number of trailing zeroes, or power of 10 multipliers.
 * Tolerance – if present, indicates the value in percent (no band means 20%).

The example resistor above has red, violet, green and gold colour band rings. Let's find out how much resistance it can provide:

 * 1st Band – Red = 2
 * 2nd Band – Violet = 7
 * Multiplier – Green = ×100000 (×105)
 * Tolerance – Gold = ±5%

By referring to the table below we can see that the amount of resistance provided by this resistor is 2700000 Ohms or 2.7 MegaOhms (MΩ) with a tolerance of ±5%.

This resistor colour code table has been simplified from the Electronic colour code article on Wikipedia.

Raspberry Pi's General Purpose Input Output (GPIO) pins
Each Raspberry Pi model has a series of 40 pins that are referred to as General Purpose Input Output (GPIO) pins. GPIO pins can be used to power and control electronic components.

 * Board numbering – just starts from the bottom-left at 1, and works its way up and right, through to 40.

 * BCM numbering (Broadcom numbering) – is the way the Raspberry Pi's processor sees the pin connections.

You can run the  command in the  Terminal program on your Raspberry Pi for information about the GPIO pins (as well as the hardware specification of the particular Raspberry Pi model). Also, for more information see: https://pinout.xyz/pinout/pin40_gpio21/

Cotswold Jam also provided an A4 printout of GPIO pin references that you can put next to your Raspberry Pi:

How Semiconductors Work
This tutorial includes Diodes, LEDs and Transistors, gets Techy.
 * 1) http://engineering.nyu.edu/gk12/amps-cbri/pdf/Basic%20Electronics.pdf

Distance Learning – Tutorials

 * 1) http://www.instructables.com/id/Basic-Electronics/
 * 2) http://www.electronics-tutorials.ws/
 * 3) http://www.electronics-tutorials.com/index.htm

Wikibooks
Wikibooks has its own book on Electronics which goes into a lot more detail than this book does.


text:
Wikijunior:Raspberry Pi/Raspberry Pi LEGO® Burglar Alarm

Tutorial by Andrew Oakley Public Domain 2016-04-24 updated 2018-03-01 www.cotswoldjam.org

LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this tutorial nor Cotswold Raspberry Jam.

Getting started
This tutorial shows you how to make a burglar alarm that sounds when a LEGO® door is opened.

At the end of each line, you will usually have to press the Enter key. Your tutor should have prepared your Raspberry Pi for you and given you a bag of components. If not, see the section "Preparation" at the end.

Piezo buzzer
A piezo buzzer makes a beep when electricity goes through it.

It has two "leg" connectors; one long and one short.

 * The long leg must be connected to the positive
 * The short leg must be connected to the ground (negative).

Reed switch
A reed switch is a glass tube with two bits of metal separated by a tiny gap. When there is a magnet nearby, the two bits of metal touch and allow electricity through. A reed switch can be connected positive or negative on either side.

Jumper wires
Jumper wires (also called DuPont wires) are used to connect electronic components to the Raspberry Pi or a breadboard.

You should also have four female-to-female jumper wires.

A small magnet and a LEGO® door
A small magnet and a LEGO® door. Your tutor should have already stuck the reed switch to the inside top of the door frame with sticky tape and stuck the magnet to the inside top of the door.

If you have a burglar alarm at home, get a step-stool and look at the top of the door. I bet you have some white plastic bits – one on the door frame, one on the top of the door. These contain a reed switch and a magnet, just like this tutorial.

The circuit

The Raspberry Pi uses two sets of numbers to refer to the General Purpose Input Output pins (GPIO pins).

"Board numbering" just starts from the bottom-left at 1, and works its way up and right, through to 40.

"BCM numbering" (Broadcom numbering) is the way the Raspberry Pi's processor sees the pin connections.

We're going to program with GPIO Zero, which uses BCM numbering.

 * 1) Connect the reed switch to GPIO pin 9 (GND) and pin 7 (GPIO 4).
 * 2) Connect the short leg of the piezo buzzer to GPIO pin 14 (GND) and connect the long leg to GPIO pin 16 (GPIO 23).

Detecting the door opening
Power up your Raspberry Pi and go to the desktop.

From the menu, select Programming - Python 3. Then use File, New Window to create a new program.

Type in the following program, or alternatively you can use File, Open to open the  program in the python/burglar folder.

Use File, Save to save this program as burglar1.py and the run it by selecting Run menu, Run Module.

Close the door and then open it. You should see the words "Door opened" on the screen.

Not working? Check you’ve got:

 * Wires going to correct GPIO pins.
 * The reed switch is aligned with the magnet. Rotate it gently so that the contacts are pulled together by the magnet.
 * The reed switch hasn't got broken (ask your tutor for another if so).
 * No spelling mistakes, no missing brackets, and you’ve used round brackets instead of pointy, curly or square ones.

What is this program doing?
The first line tells the computer to learn about a new thing. Computers can learn from programs that other people have written, and we call these other programs "libraries". Our instructions tell the computer to learn about buttons, which can either be pressed or released.

A reed switch is a special type of button. It is "normally open" (released) and no electricity goes through it. When a magnet is nearby, it becomes closed (like a pressed button) and electricity flows from the GPIO4 pin to the ground pin.

This causes the program to wait until the reed switch is newly opened – it has to change from closed to open. If the door was already open at the start of the program, that doesn't count.

This prints a message to the screen.

Looping the program
Let's add a loop so that we can keep opening and closing the door.

Alternatively, you can load in the  program if you don't want to type it in.

The  command repeats a section of the program; the word   makes it repeat forever.

Indentation matters in Python. For example, you must type the two spaces in the lines after. Indentations like these define a block of code.

Python is picky about punctuation and capitals, too. The initial letter of  must be a capital, and the line   must end with a colon.

Use File, Save to save this program as burglar.py and then run it by selecting Run menu, Run Module. Try opening and closing the door.

Halt the program by selecting Shell menu, Restart shell.

The buzzer
Change the program to add in the buzzer. Alternatively, load the  file.

Note that we have imported the Buzzer object from the library, as well as the Button.

Next, we set the buzzer to work on GPIO23.

When the door has been opened, we use:

This command has three numbers, called parameters:

 * 1) The number of seconds to sound the buzzer (1)
 * 2) The number of seconds to keep the buzzer quiet (0, zero)
 * 3) The number of times to loop through sound and quiet periods (1, once only)

will give us a single 1-second beep. You could change it to sound really annoying!

Use File, Save to save this program as burglar3.py and then run it by selecting Run menu, Run Module.

The buzzer should now sound for one second when you open the door.

Halt the program by selecting the Shell menu, Restart shell.

Preparation
Download the sample program files from: http://www.cotswoldjam.org/downloads/2016-04

Glass reed switches break easily. Hold the legs while bending them, don't rely on the glass holding them. Use Sellotape® to ensure any shards do not escape if the switch breaks.

Cjam-burglar-tutorial-2018.pdf
The original PDF for this tutorial is available on Wikicommons:

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Wikijunior:Raspberry Pi/Raspberry Pi Star Wars Lightsaber

Tutorial by Andy Baker, instructions by Hal Motley

This tutorial is available in the public domain. In this tutorial you will connect a multi-colour LED to the Raspberry Pi to create a lightsaber like in Star Wars.

How lightsabers work
For this tutorial, the colour-changing LED represents a kyber crystal. In the Star Wars universe, lightsabers are powered by a kyber crystal which the Jedi attunes to their will using the Force. There are a wide variety of blade colours including:

 * Luke Skywalker – green
 * Obi-Wan Kenobi – blue
 * Mace Windu – purple
 * Rey Skywalker – yellow
 * Ahsoka Tano – white

Sith lords such as Darth Vader, Kylo Ren and Darth Maul have red lightsabers because they dominate the kyber crystals using the Force causing them to bleed.

There is a full list of lightsaber colours here: https://www.bossksbounty.com/films/every-lightsaber-color-in-star-wars

The kit

 * ×4 male-female GPIO jumper cables (also called DuPont cables, preferably of different colours)
 * ×1 breadboard (a small 5×5 breadboard works well, but any size is fine)
 * ×1 68 Ohm (blue grey black gold) resistor
 * ×1 4-pin colour-changing LED

Using a breadboard
Breadboards are used to prototype and test electronic components without needing to solder them.

Each hole is identified with a notation system using numbers horizontally across the breadboard and letters vertically down the breadboard.

Connecting the components

To setup the lightsaber, do the following:

Step 1: Power off your Raspberry Pi by shutting it down.

Step 2: Connect the colour-changing LED to the 4 holes in the top row (A13, A14, A15 and A16). Make sure that the longest pin (the ground) is lined up with the jumper wire to GPIO 39 (GND) so the LED is properly grounded.

Step 3: Connect the 68 Ohm resistor into the breadboard by placing one wire into hole B15 the other into B20 (the last hole of the second row) above the jumper wires.

Step 4: Connect the 4 jumper cables from the GPIO pin 33 (GPIO 13), pin 35 (SPI1 MISO), pin 37 (GPIO 26) and pin 39 (GND) (the last four bottom right pins, assuming the USB and Ethernet ports are to the right) to the bottom left four holes of the breadboard. I recommend trying to use the same coloured jumper wires that match the diagram exactly, though any colour combination can be used.

Step 5: Run each of the Python scripts in order, which are,  ,   and. Try altering the code and see if you can make your own colour combinations.

lightsaber.pdf
The original PDF for this tutorial is on Wikimedia Commons:


text:
Wikijunior:Raspberry Pi/Raspberry Pi Screaming Jelly Babies Tutorial

In this tutorial, you will be making a jelly baby scream! Alternatively, you could use a gummy bear if you live outside of the UK or Australia.

Your tutor should have prepared your Raspberry Pi’s SD card for you. If not, please read the last section “For Tutors”.

Conventions
At the end of each line, you will usually need to press the Enter key.

Log in and start IDLE
When you turn on your Raspberry Pi, after a few moments it will ask you to log in. You will need to type the username followed by the Enter key, then the password, followed by the Enter key.

Note that the password won’t appear on the screen when you type it.

From now on, you should assume that you always need to press the Enter key at the end of every line.

Once you have logged in, the screen will go black for a few moments, then the desktop should display and you should be able to move the pointer with your mouse. If not, enter:

Find the "IDLE" icon and double-click on it. If you find it difficult to double-click, you can right-click it and select "Open" instead.

You want IDLE and not IDLE3.

IDLE is a program for writing programs, using the Python version 2 programming language. The more advanced you become with Python, the more useful features you’ll use. However, it is possible to write programs without IDLE, using a text editor such as nano. There are other versions of this tutorial which use nano instead of IDLE.

IDLE3 is for version 3 of Python. This tutorial is written for version 2.

Your first program – Hello World
Type in the following program:

Save it using the File menu, Save, and then double-click into the python folder and then the jellybaby folder. Save the program as:

On the desktop, double-click the LX Terminal icon. A new black window will appear.

Switch into the python/jellybaby folder by entering:

Have a look at what files are in this folder by entering:

You should see your  program, some .wav sound files (those are the scream sounds we'll use later) and an examples directory (if you want to cheat, you'll find a fully working version of the screaming jelly baby program already there!).

Now run your program:

The computer should respond:

Let’s have a quick look at what we did there:

What is ?
means "superuser do". For many programs, this doesn’t matter, but in a minute we are going to use electronics attached to the Raspberry Pi's GPIO ports (General Purpose Input and Output), and you need to be the superuser to do that.

On the downside, running a program as a superuser allows you to do things which can break the computer – the superuser is like a superhero who can do anything. Since the Raspberry Pi is a very cheap computer, that doesn't matter too much, but on other expensive computers, you might want to be more careful with.

What is ?
tells the computer to run a program written in the Python programming language. is the name of your program.

Shutdown the Raspberry Pi
You should always turn off your Raspberry Pi before attaching wires to it. Make sure you tell the Raspberry Pi to shut down safely before you unplug the power.

You can either use the red power icon in the bottom-right corner of the desktop, or in the LXTerminal window (the black window) type:

 * is the superuser-do command again.
 * means to turn itself off.
 * means halt (as opposed to  which means restart)
 * means, well, right now! (If there were other people using your Pi over the network, you could say  instead of now, to give a five-minute warning).

Connect the jumper wires to the GPIO pins
The pins are in two rows. Even numbers are on the edge of the board and odd numbers are on the other row. You will need to count in 2s starting from 1 on the left, so the count goes 1, 3, 5, 7 and so on.

It's easy to make a mistake identifying pin 25 (GND), especially on the "Plus" models of Raspberry Pi which have 40 pins! It's a lot less hard on the old Model B and Model A which only have 26 pins – pin 25 (GND) is the one at the end on the right.

Step 1: Wait for the Raspberry Pi to turn itself off, then unplug the power cable.

Step 2: Unwind a metal paper clip so that it is a long straight-ish wire.

Step 3: Take a female-to-female jumper cable and push the unwound paper clip in one end.

Step 4: Do this twice, so you have two wires, both with an unwound paper clip in the end. Larger paperclips may be difficult to fit. Your tutor may have already put them in for you, or you might ask your tutor for some pliers to help push them in.

Step 5: Now attach the other ends of the jumper cables to pin 3 (I2C1 SDA) and pin 25 (GND) of the Raspberry PI's GPIO pins.

The GPIO Program – Version 1
Put the power lead back in, wait for the Raspberry Pi to turn on, then log in ( /  ; don't forget   if your desktop doesn't start automatically).

Start IDLE from the desktop (double-click), the load your old program by going to File menu, Recent Files and selecting.

Change the program so that it reads:

All the capitals really matter. You need to make sure that everything in capitals really is in capitals, and everything in lowercase really is in lowercase. This is called being case-sensitive.

The spaces under the  and   lines are also important. You need to press the spacebar to make sure they line up. These indentations are called blocks. Blocks of code can be repeated, or the program can decide to run or miss out a block. We're using four spaces to indent each block; some programmers prefer two or another number.

The  lines allow us to use other people's little programs inside our program. These little programs are called libraries. The time library lets us tell the computer to wait. The  library lets us use the GPIO pins. The  library lets us call other programs, such as the music player, but we’re not using that just yet.

tells us to repeat a block of code. tells the computer to always do something.

asks a question. The question being asked is whether the two wires are touching; is pin 3 (I2C1 SDA) connected to the electrical ground? Connecting an input pin to ground results in the value. Note the use of two equals signs. One equals sign is used to set a value, such as  means that every time the computer sees a it will know it has the value. Two equals signs are used to compare one thing with another.

means to wait for 1 second.

Save the program, then run it by starting LXTerminal from the desktop (double-click) then enter:

The program will print Hello World! and then it will wait.

Touch the paperclip wires together. You should see it say:

Release the wires, wait few seconds and then touch the wires together again. It should say  each time.

If it doesn't work, check your program has been typed in right, check you saved it, and check that your wires aren’t covered in anything that might be stopping the electricity.

When you've had enough, hold down the CTRL key and press C to stop the program. This is called a "break" or a "keyboard interrupt" – you're asking the computer to take a break, and you're interrupting the program using the keyboard. Sometimes you might see Ctrl and C written as CTRL-C or even ^C. You don't need to use the shift key – the C is actually a lower case c.

The GPIO Program – Version 2
Let’s change the program so that it makes a sound instead of just printing “Ouch!” on the screen. Change:

…to:

Make sure the speakers are plugged in, turned on and have the volume at least half way (some speakers do not have on/off buttons or volume).

Go to the LXTerminal window and run the program again.

Touch the wires together and you should hear a scream!

Wire up the Jelly Baby
Get a jelly baby and push the wires into it.

You need to make them cross over inside the jelly baby, but not quite touch.

Now, when you press down hard on the jelly baby, it will scream!

You might have to press quite hard – hard enough to push through the sticky middle of the jelly baby.

Pressing down hard means that the jelly baby will probably be useless after three or four presses. If you’re not diabetic or allergic to jelly babies, you could eat the jelly babies after they’re squished!

Further fun
Your program plays a scream for the musical note C. There are also scream sound files for the notes D and E. Try changing your program to use a different note. See if you and your classmates can play a tune such as Mary Had A Little Lamb (EDCDEEE,DDD,EEE,EDCDEEE,EDDEDC).

Find a list of GPIO pins (http://raspi.tv/download/RPi.GPIO-Cheat-Sheet.pdf). Can you connect more wires and have one Raspberry Pi wired up to two or three jelly babies at the same time, playing different notes?

Equipment – for each workstation

 * ×1 Raspberry Pi, any model, with monitor, mouse and keyboard
 * ×1 SD or Micro SD card with up-to-date Raspbian operating system
 * ×1 speaker or pair of speakers, powered (rechargeable mobile MP3 speakers are fine, as are proper PC speakers)
 * ×2 Female to Female jumper wires – recommended minimum length 20 cm (about 8 inches)
 * ×2 small metal paper clips (not plastic coated) (if you use large clips, you may need to use pliers to push them into the jumper wires)

Several jelly babies – allow at least 6 per workstation, although probably best to only hand them out one or two at a time!

Knowledge of which of your pupils are diabetic or allergic to jelly babies.

Prerequisites
Download and unzip the folder structure, scream sound samples and example program. To do this, from an internet-connected Raspberry Pi, log in ( /   ) and do:

This will create:

Note that there is an excellent diagram of GPIO pins available at: http://raspi.tv/download/RPi.GPIO-Cheat-Sheet.pdf

Written by Andrew Oakley of Cotswold Raspberry Jam www.cotswoldjam.org CC-BY-SA

Latest version always at: http://www.cotswoldjam.org/tutorials/

Based on “Make a Jelly Baby Scream!” by the Raspberry Pi Foundation, CC-BY-SA http://www.raspberrypi.org/learning/screaming-jellybaby/ https://creativecommons.org/licenses/by-sa/4.0/

Files
The original PDF for this tutorial is available on Wikimedia Commons:


text:
Wikijunior:Raspberry Pi/Raspberry Pi LED Birthday Candle

Tutorial by Andrew Oakley Public Domain 17 Apr 2015 www.cotswoldjam.org

Introduction
This tutorial shows you how to build a birthday candle based around an LED (light) and a photocell (light detector) using a Raspberry Pi computer.

You'll be able to "blow out" the LED – and it'll turn off and play a tune!

At the end of each line, you will usually have to press the Enter key.

Your tutor should have prepared your Raspberry Pi for you. If not, see the section "Preparation" at the end.

Light-Emitting Diode (LED)
The LED (Light-Emitting Diode) has a short leg and a long leg. If you feel around the rim, you'll also find a flat edge. The short leg and flat edge always connect to the negative (ground).

Resistor
The resistor can be connected any way around. We're using a 270 Ohm (red red brown) resistor but anything between 220–470 Ohms will work fine.

Light-dependent resistor (LDR)
The light-dependent resistor (LDR) which is also called a photocell or a photoresistor can be connected any way around. They let through more current when there is more light. We're using one that is rated between 2 and 20,000 Ohms but most photocells you find in hobby kits will work fine.

Capacitor
The capacitor has a short and a long leg, and a stripe on one side. Like LEDs, they must be connected with the short leg and stripe to negative (ground). We're using a 1 microfarad capacitor and you should too.

A capacitor stores a small amount of charge, then when it is full it lets all the charge go.

 * If you connect it to a strong charge, it lets the charge go faster.

 * If you connect it to a weak charge, it takes longer to let the charge go.

Jumper wires
Jumper wires (also called DuPont wires) connect electronic components to the GPIO pins. You should also have two short and one long jumper wire (all "female to female" – holes at both ends).

The circuit

Build up the circuit as follows. Place the components first, and the jumper wires last. Don't worry about the paperclips just yet.

Here's what the breadboard should look like before you plug in the jumper wires.

And here's the breadboard with the jumper wires attached.

Leg trimming
When components come out of the factory, they have long legs (wires). Your tutor may have already trimmed the legs of your components, in which case you do not need to do it again. If your components have long legs, then before you cut them, you should try out your circuit by connecting it to the Raspberry Pi and running the programs.

If and when you need to trim the legs, you can use kitchen scissors or a special wire snipping tool. Either way, be careful when cutting the legs of components:

 * Don't trim the legs so short that they don't stick into the breadboard holes.

 * For LEDs and capacitors, remember you can use the LED rim or capacitor stripe to tell positive from negative, even if you trim both legs the same length.

Connecting the Raspberry Pi
Connect the jumper wires as per the diagram.

The pins on the Raspberry Pi's GPIO port are numbered as follows. On older models, there will only be 26 pins, but they still start from 1 and 2 on the left side.

The top row has evens, the bottom row has odd numbers.

The test programs
Power up your Raspberry Pi, log in and go to the desktop. If you need to log in, the default username is  and the password is. If the desktop still does not appear, type  and press the Enter key.

From the menu, select Programming - Python 2 (not Python 3). Then use File, New Window to create a new program. Click File, Save As and go into the python/candle folder by double-clicking python and then double-clicking candle. Save as:

Lighting up the LED
Let's start by lighting up the LED. Type in the following program, or load it from mycandle1.py in the examples folder:

Save the program using File - Save. Now leave the Python window open, and start a terminal session by going to the main desktop Menu - Accessories - Terminal. You should see a black window open.

In the terminal, type:

You should see the LED light up for two seconds, and then the program will end. You can repeat the program by entering  again.

Let's have a quick look at what this program is doing.

The  command tells the computer to use bits of another program that have been written by someone else. These other programs are called libraries. We call in two libraries;  which lets us use the GPIO pins, and   which includes the   command which we use to wait for two seconds.

If the program gets stuck, hold down the CTRL key and press C. Then check your wiring and the spelling in your program.

If the program works, it will light the LED for a second, then start counting. It then says what the count was. A small count means light, a big count means dark.

Try running the program with your finger blocking the photocell. Try using bits of black card to put the photocell into shadow. If you're trying this in a well-lit room, the room lights might be more powerful than the LED – later we will make a blackout hood using paperclips and card.

In the program, you can see that we briefly (for 0.1 seconds) set  to an output and set the voltage low, just to clear any voltage on the connection, before we set it to an input with.

We then start counting. We have a new variable,, which we set to zero.

The program then loops around until it detects high voltage from the capacitor, adding one to the  count every time. When it detects high voltage, it ends the loop and prints out the value of the.

Hoods and flaps – detecting breath
We are going to use a little flap of card to detect breath. We're going to make a U-shaped hoop out of a paperclip, then hang a bit of card from it.

We'll place that hoop and card between the LED and the photocell, and make sure it can get blown out of the way when we blow on it.

We'll also put a hood over the photocell so that the only light it can see, will be from the LED. We'll use another two larger paperclip U-hoops to hold the card in place. Paperclips are quite handy with electronics breadboards as they fit firmly in the holes!

Have a good look at the following photo, and create your own hood and flap.

Your tutor may have already bent and cut your paperclips to size. If not, be careful of flying metal when you snip your paperclips to the right length.

The flap is made from:

 * A piece of black card approx. 2cm × 1cm
 * A paperclip hoop approx. 1.5cm tall and 1.5cm wide
 * Bend one end of the card gently (bend don't fold) over the hoop and use a very small amount of sticky tape to hold it loosely. Remember it has to be loose and delicate enough to swing when you blow it. It you tape it down too tight, it won't swing and it won't work.

The hood is made from:

 * A piece of black card approx. 4.5cm × 2cm
 * Two paperclip hoops approx. 2.5cm tall × 1.5cm across
 * Just gently bend the card and hold it in place with the hoops

The final program
The final program is based on the second test program:

 * It sets up the GPIO pins and lights the LED.
 * It does some "calibration" – it works out what the reading for "dark" is, when the flap is closed.
 * It loops around waiting for a new reading which is significantly lower than the calibration reading. This lower reading should mean there is much more light on the photocell – and that therefore the flap has been blown out of the way!
 * There is a variable  which controls how much lower the reading has to be for the program to detect the flap has been blown. By default it is set to 50% but you can change this. Remember you can use CTRL to stop your program if it gets stuck.
 * When the program detects light, it plays the tune "Good Morning To All" from 1893. This tune is out of copyright, but you may decide to sing along with some birthday-related lyrics at your own risk. This program is rather long to type in, so you can load it as  from the   folder if you prefer.

As before, run the program by switching to the terminal window and entering  or   depending on how you named it.

The program will run in a loop. To stop it, hold down the CTRL key and press C.

Preparation
If your tutor has not prepared your Raspberry Pi and equipment, or if you don't have a tutor, you can set things up by following these instructions before you start.

Equipment
You will need:

 * A Raspberry Pi running the Raspbian operating system. This tutorial suits all models to date, which includes the A, A+, B, B+ and 2B.
 * A solderless breadboard – we’re using a mini 170-point one, but any solderless breadboard will do.
 * An LED. We’re using a 5mm yellow one. It needs to be bright enough to trigger the photocell, so yellow, green or white will usually work better than red or blue.
 * A photocell, also known as a photoresistor. We’re using a 4mm 2–20k ohm one.
 * Four female-to-female jumper wires, at least 20cm long each.
 * Two short male-to-male jumper wires, about 2–6cm each. We’re using solid wire.
 * Three paperclips, cut into U-shapes.
 * Two small bits of black card; one about 4.5 × 2cm, and one about 2 × 1cm

Files
Please use an up-to-date installation of Raspbian. This tutorial was written in April 2015 and, at the time, the most recent recommended Raspbian image was dated 2015-02-16. You can create the folder structure and download the files by going to the terminal (Menu - Accessories - Terminal) and typing:

…where  is a minus sign followed by a capital letter O (not the numeral zero).

Cjam-led-candle-tutorial.pdf
The original PDF is on Wikimedia Commons:


text:
Wikijunior:Raspberry Pi/Raspberry Pi LEGO® Traffic Lights

Tutorial by Andrew Oakley Public Domain 26 Sept 2015 www.cotswoldjam.org

LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this tutorial nor Cotswold Raspberry Jam.

Introduction
This tutorial shows you how to build a set of traffic lights based around LEDs (lights) and a Raspberry Pi computer. The lights can be placed inside a LEGO® Technic brick and used with other LEGO® models.

Conventions
At the end of each line, you will usually have to press the Enter key.

Your tutor should have prepared your Raspberry Pi for you. If not, see the section "Preparation" at the end.

Components
The light-emitting diode (LED) has a short leg and a long leg. If you feel around the rim, you'll also find a flat edge. The short leg and flat edge always connect to the negative (ground). We use 5mm LEDs because they fit into LEGO® Technic holes.

The resistor can be connected any way around. Lower value (lower Ohm) resistors will allow more current through and will make the LED brighter; higher values will let less current through and make it dimmer. We're using a 270 Ohm resistor but anything between 220–470 Ohms will work fine. We will use one resistor connected to the ground to cover all 3 LEDs.

These three LEGO® bricks can be made into a traffic light, and the 5mm LEDs fit inside the holes of the Technic brick.

The part numbers for these bricks – which can be purchased second-hand on sites such as eBay or Bricklink.com – are:

 * 3701 – Technic, Brick, 1×4 with holes, black
 * 3460 – Plate, 1×8, grey
 * 3022 – Plate, 2×2, grey

Push the LEDs into the Technic brick so that the short legs of each LED are at the bottom.

You will need to connect the short legs to a single resistor and then to one of the Raspberry Pi’s ground pins. Your tutor may have made up a special "pigtail" cable to do this, or you may use a breadboard.

Ground (negative) wires
Pigtail cable Your tutor may have made up this cable using a DuPont crimper

It has three female ends on one side, which plug into the short legs of the LEDs, a resistor in the middle, and a single female end on the other side which plugs into pin 9 (ground) of the Raspberry Pi. A short bit of clear sticky tape wraps around the resistor to hold it in place.

Breadboard

Signal (positive) wires
Once you’ve got the resistor and ground connected to the LEDs’ short legs, you can test any LED by using a female-to-female jumper wire to connect the long leg to pin 1 (live 3.3 Volts) on the Raspberry Pi (assuming the Raspberry Pi is powered on).

However, we don’t want the lights on all the time; we need them to be controlled by a program. Disconnect pin 1 once you’re finished testing the lights.

To control the LEDs from our program, use female-to-female jumper wires to connect the long (positive) legs of the LEDs to the following pins on the Raspberry Pi:

 * Pin 11 — Red
 * Pin 13 — Yellow
 * Pin 15 — Green

The program
Power up your Raspberry Pi, log in and go to the desktop. If you need to log in, the default username is  and the password is. If the desktop still does not appear, type  and press the Enter key.

From the menu, select Programming – Python 3. Then use File, New Window to create a new program.

Type in the following program, or alternatively you can use File, Open to open the traffic1.py program in the python/traffic folder.

Use File, Save to save this program as. Here's what this program is doing:

This command teaches the Raspberry Pi about its GPIO pins, so it can turn the LEDs on and off, and about time, so we can tell it to wait for a few seconds between each colour.

Here we’re telling the computer to use call the pins by the numbers in the order they are laid out on the board (there is an alternative way of numbering them called BCM). Next we tell it not to warn us if the GPIO pins have already been used.

Now we're telling the Raspberry Pi which pins are used for which coloured LEDs. Note that we don’t have to state that we're using pin 9 for ground; it doesn’t matter.

Finally we tell the Raspberry Pi to prepare the red, yellow and green pins for output. If we were getting input, such as reading a switch, then this bit would look different.

This part of the program just gets everything ready. It doesn’t actually turn any of the LEDs on. We'll do that next.

Use File, Save As to save the program as. Don't worry it it tells you that the program already exists – save it anyway.

Lighting up one LED
Let's start by lighting up the yellow LED. At the bottom of the program, add these lines:

HIGH turns a light on. LOW turns it off.

Save the program as.

Now leave the Python window open, and start a terminal session by going to the main desktop Menu - Accessories - Terminal. You should see a black window open.

In the terminal, type:

You should see the yellow LED light up for two seconds, and then the LED will turn off and the program will end. You can repeat the program by entering  again.

Try changing the program to light up the red or green LED.

Flashing an LED on and off repeatedly
Now let’s change the program so that the last lines read:

Save this program as. Go back to the black terminal window and run it with:

The yellow LED should flash on and off every 2 seconds.

Exit the program by holding down the CTRL key and tapping the C key. This may leave the yellow light on! Don’t worry about that.

The full sequence
The full sequence for British traffic lights is:

 * Red (stop) — for a long time
 * Red and Yellow together (get ready to go) — for a short time
 * Green (go) — for a long time
 * Yellow on its own (get ready to stop) — for a short time

Let's change our program to do this full sequence:

That's it! Save this program as. Go back to the terminal window and run it with:

Exit the program by holding down the CTRL key and tapping the C key.

You can use the alloff.py program to turn all the lights off after you've stopped the program. Also there is the  program which uses some advanced techniques to turn off the lights when the program is stopped.

Further adventures
Here’s some ideas for other things you could do:

Run two sets of lights from one Raspberry Pi
You could use pins 12, 16 and 18 (plus pin 14 for ground) to control another set of lights.

For a T-junction you need 3 sets of lights. For a crossroads, 4 sets
On a Model B+ or Pi 2 you could use pins 36, 38 and 40 (plus pin 34 for ground) to control a third set of lights, or you could use two Raspberry Pis.

If you had more than one Raspberry Pi, how could you synchronise the lights? How could two Raspberry Pis communicate between each other?

How could you detect a toy car waiting at the lights?
Does your strategy work if it is a plastic LEGO® car or a metal toy car, or both? Does it matter if the car is heavy or light?

What about if it was a bicycle or a horse? How do traffic lights in the real world detect cycles and horses – do they have another strategy, or do they ignore that problem?

How could you run your program automatically when you turn on your Raspberry Pi?
Try searching for information on the  command: https://www.adminschoice.com/crontab-quick-reference

Preparation
The files for this tutorial can be found at: http://www.cotswoldjam.org/downloads/2015-09/

Please create a  folder under the home/pi directory, then unzip the files into that directory. This can be done in the LXTerminal:

Files
The original PDF for this tutorial is on Wikimedia Commons:


text:
Wikijunior:Raspberry Pi/Raspberry Pi Python GPIO Zero Distance Sensor

Tutorial by Jonathan Teague - Public Domain 28th Jan 2017 – www.cotswoldjam.org

This tutorial will cover using the popular HC-SR04 ultrasonic distance sensor, the Raspberry Pi and the  library to measure distances.

The kit
In your bag you will find the following components:

 * ×4 M-F Jumper leads (pin to socket)
 * ×1 R1 680Ω (blue grey brown) resistor
 * ×1 R2 470Ω (yellow violet brown) resistor
 * ×1 Mini-breadboard
 * ×1 HC-SR04 ultrasound sensor

Using a breadboard
Breadboards are used to prototype and test electronic components without needing to solder them.

Each hole is identified with a notation system using numbers horizontally across the breadboard and letters vertically down the breadboard.

Using the Raspberry Pi's GPIO pins

The Raspberry Pi has two ways of labelling the General Purpose Input-Output (GPIO) pins:

 * Board numbering – just starts from the bottom-left at 1, and works its way up and right, through to 40.
 * BCM numbering (Broadcom numbering) – is the way the Raspberry Pi's processor sees the pin connections.

Putting it together
Step 0: Make sure your Pi is shut down and the power lead disconnected.

Step 1: Take 1 jumper lead and plug the pin (male end) into B1 on the breadboard and the socket (female end) into pin 6 (GND) on the Pi.

Step 2: Take 1 jumper lead and plug the pin into B3 on the breadboard and the socket into pin 3 (GPIO 20) on the Pi. This is the connector that the Pi will use to trigger the distance measurer to take a measurement.

Step 3: Take the R1 680Ω (blue grey brown) resistor – the one with a blue colour line on and insert the legs into holes E1 and I2 on the breadboard – it doesn’t matter which way round the resistor is.

Step 4: Take the other resistor, the R2 470Ω (yellow violet brown) – with a yellow colour line on and insert the legs into holes D2 and H2 on the breadboard – again it doesn’t matter which way round.

Step 5: Gently bend the R1 resistor away from R2 so the legs in E1 and D2 won't touch each other (if they do it won’t damage anything, it just won’t work).

Step 6: Take 1 jumper lead and plug the pin into J2 on the breadboard and the socket into pin 1 (GPIO 21) on the Pi. This is the connector that the Pi will use to listen for the measurement.

Step 7: Take the last jumper lead and plug the pin into B4 on the breadboard and the socket into pin 2 (5V).

Step 8: Finally, plug in the HC-SR04. It has 4 pins and these need to go into A1, A2, A3 and A4. The back of the sensor with all the black ICs on should be facing the breadboard and the two silver sensors pointing away from the breadboard.

The program
Power up your Raspberry Pi. From the desktop menu, select Programming – Python 3 (IDLE). Then use File, New File to create a new program.

Type in the following program then use File, Save to save your program as the name of your choice (don’t forget to put .py on the end) in the  folder and then run it with Run menu, Run Module.

What does the program do?

The first line is a comment (it starts with #) and tells the operating system what language the program is written in, as you will run the program from Python yourself this is redundant (but good practice).

The  lines tell the computer to learn about new things. Computers can learn from programs that other people have written; we call these other programs "libraries". Our program needs the function called  from the   library which it will use to talk to the sensor and the function   from the time library so that we can insert pauses. A function is just some code located somewhere else that we can make use of to do something.

We then create an object we call  using the imported function. The parameters that we pass say that the  to invoke the sensor will be on GPIO pin 20; the   to listen for the reply will be on GPIO pin 21 and that the maximum distance that should be returned is 2.0 metres.

This  tells the program to run forever in a loop.

Then we get the current sensor reading by calling, multiply this by 100 (as the returned value is in mm); print out the value with only one digit after the decimal point, and finally go to sleep for a second before the   makes us go around again.

Additional notes
These notes are additonal to the main tutorial and explain the use of two resistors to make a "voltage divider" and give an example program that directly controls the sensor.

The Voltage Divider
The Raspberry Pi is a 3.3V device. The sensor used in this tutorial, an HC-SR04, is a 5V device. This means that the sensor needs 5V to power it and, crucially for the Pi, that the voltage levels that the sensor returns the results to the Pi are also at 5V. Connecting the sensor output directly to the Pi would almost certainly result in damage to the Pi.

This sort of situation is often found in the real world, you have two devices you wish to connect to each other but they operate at different voltages. There are several ways to solve this but one of the simplest, and the one used here, is to drop the voltage from 5V to just under the safe value of 3.3V by making a "voltage divider" out of two resistors.

The two resistors are placed in series across the source voltage and zero volts and the voltage at the point between the two resistors will be reduced in proporation with the values of the two resistors.

$VinR1⁄R1 + R2$

So substituting in the values for 5V as the Vin and the two resistors we have used, R1 = 680Ω and R2 = 470Ω we get:

$Vin680⁄470 + 680 = 2.95V$

This 2.95V is then safe to connect to the Pi.

A program to interface to the HC-SR04 directly
In the tutorial, we don't talk directly to the HC-SR04 but leave all that to the  functionality of the GPIO Zero library. This is convenient, but sometimes it's useful to know exactly what is going on and to be able to understand how to control devices directly.

In the  folder you will find a file   which shows how to trigger and read the HC-SR04 sensor directly and which uses the   library.

Here is the important bit that triggers the HC-SR04 to take a measurement and gets the result back, it's all contained in a function called :

What does this do?
Setting the  to , sleeping for 10uS then setting the   to   triggers the sensor to take a reading.

The code then sets a variable called  to the current time and goes into a tight loop while   is 0 (= low), every time round the loop it resets the variable.

Once  is 1 (= high) this first look will stop. At this point  contains the time when the Echo pin went high.

Now the code goes into a tight loop while  is high, every time round the loop setting the variable.

Finally, when the  goes low again the loop exits. At this point, start contains the time when the Echo went high and  the time when it went low again.

Now it's just some maths to work out how long the Echo pin was high for, multiply this by the speed of sound (the 34300) and divide by 2 (because the sound from the sensor went out and back) and we get the  value in centimetres (cm).

Distancesensor-gpiozero.pdf
The original PDF for this tutorial is on Wikicommons:

Distancesensor-gpiozero-additional.pdf
The original PDF for this tutorial is on Wikicommons:


text:
Wikijunior:Raspberry Pi/Raspberry Pi GPIO Zero Reaction Timer

Tutorial by Andrew Oakley Public Domain 1 Feb 2016 www.cotswoldjam.org

Introduction
This Python programming tutorial, shows you how simple it is to use an LED light and a button, with the new GPIO Zero library.

Conventions
At the end of each line, you will usually have to press the Enter key.

Your tutor should have prepared your Raspberry Pi for you and given you a bag of components. If not, see the section "Preparation" at the end.

Light-emitting diodes (LED)
The Light Emitting Diode (LED) is a light bulb with a short leg and a long leg. If you feel around the rim, you'll also find a flat edge. The short leg and flat edge always connect to negative (ground).

Resistor
The resistor can be connected any way around. Lower value (lower Ohm) resistors will allow more current through and will make the LED brighter; higher values will let less current through and make it dimmer. We're using a 270 Ohm resistor but anything between 220-470 Ohms will work fine.

Momentary switch
The switch can be connected any way around. When pressed, it allows electricity to flow; when released, the electricity stops. This kind of push-button is known as a "momentary press-to-make switch".

You should also have a breadboard and some jumper wires. You should have three long male-to-female wires (with a sticky-out bit at one end, and a sticky-in bit at the other end), and one short male-to-male wire (with sticky-out bits at both ends).

The circuit

Connect up the breadboard as shown.

Breadboards allow us to quickly prototype (i.e. test) electronic circuits. The board has a top section and a bottom section. All the vertical holes in each section are connected together so if you plug things into a vertical column, they'll make a connection.

The Raspberry Pi uses two sets of numbers to refer to the General Purpose Input Output pins (GPIO pins).

"Board numbering" just starts from the bottom-left at 1, and works its way up and right, through to 40.

"BCM numbering" (Broadcom numbering) is the way the Raspberry Pi's processor sees the pin connections.

GPIO Zero uses BCM numbering.

 * 1) Connect the short leg of the LED to a Ground connection.
 * 2) Connect the resistor to the long leg of the LED.
 * 3) Connect the other end of the resistor to pin 16 (GPIO 23).

The program
Power up your Raspberry Pi and go to the desktop.

From the menu, select Programming - Python 3. Then use File, New Window to create a new program.

Type in the following program, or alternatively you can use File, Open to open the  program in the python/reaction folder.

Use File, Save to save this program as led.py and the run it by selecting Run menu, Run Module.

You should see the LED light up for two seconds, and then turn off.

Not working? Check you’ve got:
 * The correct GPIO pins
 * The LED is the correct way round; short leg to ground (GND)
 * Components lined up on the correct vertical columns on the breadboard
 * No spelling mistakes, no missing brackets, and you’ve used round brackets instead of pointy, curly or square ones

What is this program doing?
The first two lines tell the computer to learn about a new thing. Computers can learn from programs that other people have written, and we call these other programs "libraries". Our instructions tell the computer to learn about LEDs from the GPIOZero library, and learn about sleeping from the time library.

We then create an LED object. We say that the LED is connected to GPIO 23.

Turn the LED on, wait for 2 seconds, then turn it off.

The circuit
Now add the button and connecting wires.

The short jumper wire should go from the same column as the existing ground wire, to the column connecting to one of the button's legs.

The remaining long jumper wire should go from the column with the other leg of the button, to pin 18 (GPIO 24) on the Raspberry Pi.

The program
In Python 3, use File, New Window to create a new program. Type in the following program, or alternatively you can use File, Open to open the button.py program in the python/reaction folder.

Indentation matters in Python. For example, you must type the two spaces before the word. Indentations like these define a block of code – hence the word.

Use File, Save to save this program as button.py and then run it by selecting Run menu, Run Module.

Hold down the button. It should say  in the Python 3 shell window.

Let go of the button. It should say. You can press and release the button many times.

Halt the program by selecting the Shell menu, Restart shell.

What is this program doing?
These are called functions. They define something that should happen, and they give that action a name. The code is indented to show it belongs to the function. The  function says   and the   function says.

Here we set up a button object and tell the computer that it is connected to GPIO 24.

We also tell the computer what to do, when the button is pressed or released.

This tells the computer to wait for events to happen, such as button presses.

Button and LED together
In Python 3, use File, New Window to create a new program.

Type in the following program, or alternatively you can use File, Open to open the  program in the python/reaction folder.

Use File, Save to save this program as led-button.py and the run it by selecting Run menu, Run Module.

Press the button and the LED should light up; release the button and it should turn off.

Halt the program by selecting Shell menu, Restart shell.

Reaction timer
In Python 3, use File, New Window to create a new program.

Type in the following program, or alternatively, you can use File, Open to open the  program in the python/reaction folder.

Use File, Save to save this program as  and then run it by selecting Run menu, Run Module.

The LED will flash four times, then on the fifth time, it will stay on until you press the button.

Try to press the button as quickly as possible when it comes on for the fifth time.

You will be shown your reaction time in seconds.

You can have as many goes as you like - try challenging a friend to see who has the fastest reactions. When you've had enough, halt the program by selecting Shell menu, Restart shell.

What is this program doing?
We've introduced several new concepts in the reaction program.

We're using a value which we call  to record when the fifth flash starts. We can then compare it to the time when the user presses the button, and that will tell us the reaction time.

Values which are given a name, like, are called variables, because the actual value they contain can vary.

Some variables are global. This means they can be used in any part of the program.

tells the computer to print a decimal fraction with 3 decimal places after the decimal point.

The number we're going to print is the value of time now, minus the value of time when we started the final flash. This is measured in seconds.

The  command is used here to pick a random number between 0.5 and 3. It will probably pick a decimal fraction rather than a whole number. The command is called  because if you call it enough times, you will get a uniform random distribution of numbers – you'll eventually get every possible number in that range.

This command tells the LED to blink for 0.1 of a second, then wait for 0.4 of a second and then repeat that 4 times.

The last value,, tells it to wait until it has finished before moving on to the next command. If you put  then it would start executing the next commands whilst carrying on blinking! We don't want that here.

You can find more about GPIO Zero commands at: http://pythonhosted.org/gpiozero

Preparation
You will need the following electronic components for this tutorial:
 * 1× Breadboard – mini 170 point
 * 1× LED – 5mm diffused through-hole, red
 * 1× Resistor – carbon film 270 Ohm through-hole
 * 1× Switch – 2 pin tactile push-button through-hole
 * 3× Male to Female jumper wires - 20cm
 * 1× Male to Male jumper wire – 10cm

The files for this tutorial can be found at: http://www.cotswoldjam.org/downloads/2016-01/

You will need Raspbian Jessie with Python 3, IDLE and GPIO Zero. Once you have Raspbian Jessie and an internet connection working, you can ensure all the other files are installed by going to Menu, Accessories, Terminal and typing:

The  may take a while – maybe half an hour if your system hasn’t been updated recently. Don’t worry if  tells you that you already have packages installed.

Files
The original PDF file for this tutorial is on Wikicommons:


text:
Wikijunior:Raspberry Pi/Raspberry Pi Voice Control

Tutorial by Andrew Oakley Public Domain 23 Sept 2017 www.cotswoldjam.org

Speech Synthesis
Start the Terminal by clicking the Raspberry menu in the top-right corner, select Accessories, then click on Terminal. A black box will appear. Type the following then press Enter:

You should hear a retro-sounding voice, like that used by Professor Stephen Hawking. Try making it say different phrases. Next, let's try using a better voice, used by Android smartphones:

Notice how pico2wave creates a .wav sound file, which we have to play separately with the aplay command.

Shall We Play A Game?
We can use speech synthesis to speak instead of printing text to the screen. Let's start by looking at a simple guess-the-number game that doesn't yet have speech.

From the Raspberry menu, select Programming, Python 3 (IDLE). Click File menu, Open and pick the python directory, voice subdirectory and the file:

Run the game program by clicking Run menu, Run module and play the game yourself.

Have a look at the program. See how it uses the  command to show text on the screen.

Close the program with File menu, Close. Now open the program  and run that.

You will hear instructions spoken instead of the text being shown on the screen.

Have a look at the  program. See how it creates a say function, that is used instead of the  command.

The say function looks complicated, but we don't need to worry about that because we can now just use say ("whatever we like") in the program. If you prefer, you could change the say function to use the older espeak speech synthesiser instead:

Speech Recognition
It's easy to synthesise (make up) speech, but it's much harder to recognise it – as in, have a computer listen to a human voice and understand the words being spoken.

The Raspberry Pi doesn't really have quite enough power to perform good speech recognition, especially not with hundreds of different languages and accents in the world.

We could train it to recognise our own voice, but that could take days or weeks.

Instead, we can use the Raspberry Pi to record some speech, and send that recording to more powerful computers somewhere else on the Internet.

In our examples, we will use Google's Voice Application Programming Interface (API). This is quite complex to set up, but if you're attending one of our workshops, we have done this setup for you, so you should be able to use it straight away.

Recording Audio
The Raspberry Pi does not have a built-in microphone, nor does it have a microphone socket. We are using a cheap USB microphone to record audio, and we have already set it up for our workshops.

From the Terminal (Raspberry menu, Accessories, Terminal), enter the following:

Press Enter then talk into the microphone for ten seconds (try a nursery rhyme). Next, play back the sound using:

You can change it to 5 seconds recording time by changing  to.

Transcribing Audio
"Transcribing" means to write down in words, something that has been said out loud. We will send our recording to Google's computers and they'll send back the words.

It will take a few seconds, then it should show the words you spoke.

If it didn't understand your speech, try talking louder and nearer to the microphone. You might also need to ask other people in the room to be a bit quieter.

The Guessing Game in Full
Going back to the IDLE window, close the program with File menu, Close. Now open the program  and run that with Run menu, Run module.

This time, the game will not only talk to you, but also listen to your answers. It will only wait 3 seconds after each question, though, so be prompt.

Have a look at the program. Notice how it will say back anything that isn't a number:

You can have fun making it say things. Don’t be rude!

If 2 seconds is too short for you, you can change this timeout by changing this line:

Change seconds=3 to seconds=5 or whatever you want. Making it very long would make the game quite boring, though.

Notice how we say "I'm thinking…" when we've finished recording, but before we send the recording off to be transcribed. The transcribing can take a little while, so we need to let the player know that the computer has stopped recording but is still working.

listen ("recording.wav") say ("I'm thinking...") guess=transcribe.transcribe_file("recording.wav")

Workshop setup
This section is for teachers who want to use this workshop independently of Cotswold Jam. As well as an internet connection, you will need a microphone. We used this cheap USB microphone from Amazon (ASIN: B01CQKCTSM).

In the .zip file that contained this document, you should also find other files which will need to be placed into the  directory. You may need to make this folder if it doesn't exist.

You can install the speech synthesiser programs and configure the USB microphone from the Terminal with:

Now run  and press F6 to select the USB mic, press F4 to select capture. Make sure it says "LR Capture" below the bar chart; use Space to toggle capture/mute on/off.

Press the Esc key to exit.

Getting Google Cloud Speech API working is really a job for a Linux and API expert. You can find instructions at https://cloud.google.com/sdk/docs/quickstart-debian-ubuntu but be warned, it is not trivial. In particular, you will need to apply for a Google Cloud account and enable voice services, which although comes with US$300 free credit (at the time of writing), requires a bank card to set up.

It may be easier to just download our ready-made Raspbian image; look under http://www.cotswoldjam.org/tutorials although it is likely that the credit on the included Cotswold Jam API key will have long since expired. You will need to put your own Google Voice API key into the  directory to replace our   file (which is called from  ). Note that our Raspbian image uses the headphone socket to play audio; you may need to right-click the desktop volume control to switch to HDMI output.

Voice-workshop.pdf
The original PDF for this tutorial is available on Wikimedia Commons:


text:
Wikijunior:Raspberry Pi/Contributing

The goal of this book is provide a useful free guide to the Raspberry Pi adapted from tutorials made by Cotswold Jam and others. The tutorials themselves are available at http://cotswoldjam.org/downloads. I have also archived these files on my GitHub and on the Wayback Machine.

To-do

 * Organise assets for Button Invaders
 * Suggestion for a Charlieplexed 7-LED "H"-shaped dice tutorial.
 * Suggestion for a game inspired by the Haynes electronics advent calendar such as Simon Says.
 * Raspberry Pi Zero cake tutorial with the printout
 * Introduction to Python tutorial
 * A No Pi! No Problem logo and wikibox which is similar to the current information and warning (uses prohibited symbol 🚫)?
 * All the images for the Cotswold Jam tutorials
 * Ensure all the source code files use h3 headings and line numbers
 * Introduction to the Raspberry Pi - the ports

Types of tutorials
There are 4 types of tutorial that Cotswold Jam taught:

 * Electronics tutorials use electronic components such as breadboards, resistors, LEDs, switches and jumper wires.
 * Minecraft: Pi Edition
 * Scratch tutorials teach the visual Scratch language which can be attempted on just about any platform (Windows, macOS, GNU/Linux, etc.).
 * Raspberry Pi OS is the new name for Raspbian, these tutorials are almost engtirely software based.

Of course, we can add others providing they are compatible with a Raspberry Pi and suitable for an 8-12 year old audience.

Additional content

 * Add tutorials – They can be obtained from: http://cotswoldjam.org/downloads. We also accept 3rd party tutorials as long as they are available under a compatible licence (public domain or CC-BY-SA). Such as: https://seattleraspberryjam.weebly.com/projects.html
 * No Pi, No Problem! – Add instructions where possible for the Raspberry Pi OS and Scratch tutorials for setting up these to work on a standard computer running Windows, macOS or a GNU/Linux distro such as Ubuntu. We need documentation for:
 * Installing Raspberry Pi OS natively on a desktop or laptop using a USB flash drive.
 * Installing Raspberry Pi OS as a virtual machine using Virtualbox.
 * Installing Ubuntu via Windows Subsystem for Linux (WSL) on Windows 10 and 11.
 * Forward compatibility testing – Test that all of these tutorials work on the latest Rasberry Pi models! The latest model is the Raspberry Pi 4, as of November 2022. Also that any Python 2 tutorials have been modified to work with Python 3.
 * Introductions for each section

Wording

 * Improve wording in the chapters – the guides should be adjusted to read like a book and less like standalone leaflets. The depth and quality of guides should be consistent across chapters.
 * Conform to our Manual of Style – the guides should be run through spell-checking software such as Grammarly and usage of symbols such as en dashes (–) and em dashes (—) should be consistent. I've started marking components and GPIO pins in bold to make them easy to see.
 * Rename chapters – some chapters have names which make sense for standalone leaflets, but are not useful book chapter names.

Add screenshots and diagrams to the tutorials
Upload them to the specially-made c:Category:Raspberry Pi tutorials on Wikicommons.

Create SVG diagramss
Ideally, all images that are not photographs nor screenshots should be SVG as per the Wikicommons guidelines – because they take up less file space and are infinitely re-scalable. Also Fritzing (see below) apparently exports to SVG.

Recreate some low-resolution diagrams/screenshots
Some images are low-resolution and may be unclear.

Fritzing diagrams for every electronics tutorial
Every electronics tutorial should have at least one Fritzing diagram. Preferably, multiple diagrams to help illustrate each step. Fritzing charges a minimum of €8 EUR (~$10 USD or ~£7 GBP) for binaries from their website, as of November 2022: https://fritzing.org/

New screenshots for Scratch 3
Scratch 3 was released in January 2019 and has a different user interface. Make sure that the Scratch cat mascot is not included as it's a registered trademark! See: c:Commons:Deletion requests/Files containing Scratch trademarks

Scratch has its own markup language called Scratchblocks which can be used to rapidly create SVG block diagrams. Ideally all diagrams should be recreated this way: https://scratchblocks.github.io/

title: Wikijunior:Raspberry Pi/Contributing


text:
Cookbook:Spaghetti

Spaghetti is a variety of pasta. It is Italian in origin, and its name refers to a length of string or twine. It is a very popular pasta shape and may be served in a variety of preparations.

Characteristics
Spaghetti are very long and thin, with a circular cross-section. It is typically made with durum semolina flour. Spaghetti is widely commercially available in dried form, although it is also available as a fresh pasta.

Recipes

 * Cookbook:Spaghetti alla Puttanesca
 * Cookbook:Spaghetti with Clams in White Wine Sauce
 * Cookbook:Black-Peppered Chicken Spaghetti
 * Cookbook:Salmon Spaghetti
 * Cookbook:Spaghetti alle Vongole
 * Cookbook:Spaghetti and Meatballs
 * Cookbook:Spaghetti Bake
 * Cookbook:Spaghetti alla Carbonara
 * Cookbook:Simple Spaghetti
 * Cookbook:Spaghetti and Beans
 * Cookbook:Stirfry Jollof Spaghetti
 * Cookbook:Spaghetti with Meat Sauce (Naporitan)
 * Cookbook:Spaghetti Aglio e Olio
 * Cookbook:Prawn and Vegetable Spaghetti
 * Cookbook:Native Jollof Spaghetti
 * Cookbook:Spaghetti with Bolognese Meat Sauce
 * Cookbook:Stir-Fry Chicken Spaghetti
 * Cookbook:Spaghetti a la Monegasque
 * Cookbook:Simple Italian Sausage Spaghetti Dinner
 * Cookbook:Pasta with Vegetables
 * Cookbook:Pasta with Sausage

title: Cookbook:Spaghetti


text:
Basics of fine-art photography/Creating works in narrative photography

Narrative photography is a genre which allows a photographer to test himself in the role of a "writer", creating works that silently tell to viewer the stories of depicted objects.

General information
Narrative photography may consist of several parts, where each subsequent image continues the previous one, but the classic version — when author's single work can tell a story that a person who has imagination will comprehend.

Ways of implementation
The genre overlaps with street, genre, documentary, and reportage photography described in the textbook. For creating an original works you need to be in a state of motion, moving between cities, countries, continents; always have a camera at the ready, because an interesting scene can appear to you unexpectedly. It is not difficult to guess that travelers, in particular supporters of hobo tourism, overcoming multi-kilometer routes of long intercontinental wanderings, involving many meetings with people of different views, religions and ethnic traditions, have more chances.

Consider the examples below.
 * 1) Anger. The reaction of an Ethiopian woman to the mzungu camera lens: Ethiopians don't like to be photographed, like the inhabitants of some other African countries.
 * 2) Escape. A similar case. The reaction of girls from the Ugandan hinterland to the camera in the hands of a white foreigner.
 * 3) Who settled in the pyramid? Local children look into pyramid of the ancient kingdom of Meroë, where a weird stranger lay down to rest.
 * 4) Branding. In the wilds of Tanzania, the Barabaig people brand a pet, not to show it to the traveler, but because it is necessary.
 * 5) Car accident. Two passenger buses were moving along the highway from Windhoek to Lusaka, the second one tried to overtake. The author of the photo was in the first, surviving vehicle.
 * 6) Queue. A crowd of people who want to go down from the Huangshan mountain range with the help of a cable car.
 * 7) Staring into the abyss. Five Laotian monks carefully and thoughtfully peer into the abyss of falling water. What are they thinking?
 * 8) Breakage on the way. Intercity bus stuck in the middle of the Papuan jungle. The author of photo was present as a passenger.
 * 9) Decay. The photo was taken in a suburban wasteland, wich turned into a spontaneous dump by locals. Disposes to philosophical reflections on the frailty of being.
 * 10) By surprise. (or Uninvited guest). A tiny village in the deep jungle of Pentecost Island. A sudden press of the camera shutter button. Didn't anticipate?
 * 11) 12. 13. 14. 15. Coconut fight. True photo story of how the author, with difficulty knocked down a coconut, and tried to open it with improvised means. Was published in the newspaper "Republic of Crimea" dated 13. 12. 2013. — No. 28 (1000).

From the description, we can make a logical conclusion that the creation of photographs in this genre requires time, effort and (preferably) moving around the planet.


text:
User talk:AuthorsAndContributorsBot

Minecraft resource gathering/Authors & Contributors and others
What are all these pages? Why do we need them? We have the page History if necessary.--Xania   talk 03:02, 3 November 2022 (UTC)
 * It's a new bot to help with authors and contributors pages for books. 14:00, 3 November 2022 (UTC)

How does this bot work - Part 1 ?
Hi, just wonder if the bot work as followed: MATLAB Programming book is created way back in 2010s and this bot is assumed to be created recently in 2022. Will it add the previous contributors for the book wayback from 2010's until 2022 ?

Also, MATLAB Programming books have multiple pages(20+ and counting), will it only recognize the contributors on main pages and not other pages ?

MrAlanKoh (discuss • contribs) 05:31, 6 November 2022 (UTC)
 * Hi, thanks for your interest in this bot. It gets the list of contributors from a tool called catanalysis (which is also used to check the activity level of a test wiki in the incubator). It will recognize the contributors of all pages. This is a link to the tool used on this book. It will exclude blacklisted editors (bots and vandalism-only account). The problem described in the user page of the bot is that if the book “Minecraft” was added to the list, it would recognize the contributors of “Minecraft resource gathering” as well, and my proposed solution wouldn’t recognize the contributors of the main page. However, with MATLAB Programming, there’s no such problem. Hope this helps. - 🇺🇦 Слава🇺🇦Україні 🇺🇦 Героям🇺🇦Слава🇺🇦 (talk)🇺🇦 13:18, 6 November 2022 (UTC)
 * I have run the bot and it has created MATLAB Programming/Authors & Contributors. You can add it to the table of contents or embed it in another page like in Guide to the Godot game engine/Contributors. - 🇺🇦 Слава🇺🇦Україні 🇺🇦 Героям🇺🇦Слава🇺🇦 (talk)🇺🇦 13:25, 6 November 2022 (UTC)
 * Ah thanks for your bot creations, Slava Ukraini Heroyam Slava 123, I think I have no more question regarding the bots for now. MrAlanKoh (discuss • contribs) 14:31, 8 November 2022 (UTC)

 * , you are welcome. :-) If any other questions arise, feel free to ask them, but a better place would be in my user talk page. - 🇺🇦 Слава🇺🇦Україні 🇺🇦 Героям🇺🇦Слава🇺🇦 (talk)🇺🇦 09:39, 9 November 2022 (UTC)

title: User talk:AuthorsAndContributorsBot


text: User talk:24.246.120.10

title: User talk:24.246.120.10


text:
User:AuthorsAndContributorsBot

This is a bot run by.

It is designed to automate the manual task of maintaining a users and contributors page. If you want to use this bot for your book, please make sure it has a user and contributors page using the following naming convention:. If it’s named differently, please move it. If you want to use this page for a one page book, please create a dedicated page for the list of authors and contributors and embed it in the main page of the book. Then, add the title of your book to the end of this list, separated by. Not a link, just a title. Also there’s a blacklist so that the bot won’t include bots and vandals in the list. If you notice a bot or vandalism-only account added to the list of authors and contributors, please add it to the blacklist. If the account in question has engaged in both vandalism and constructive editing, please do not add it. I might implement a system where blacklisted users can be whitelisted for certain books.

Warning: Proceed with caution while adding books with short titles. If the book Minecraft for example gets added to the list, it will also include all the contributors for the book Minecraft resource gathering. The correct way to add it is to add Minecraft%2F to the list. This will not include the contributors who contributors to the main page of the book though, that means that with single page books like Dad ‘n Me Walkthrough, it will completely break the list (I tried to maker the code add %2F to all titles while parsing, and this is the reason why I cancelled this feature). Don’t worry though, if you add Minecraft%2F to the list, the code will know that the page with the list of Authors and Contributors is Minecraft/Authors & Contributors, and not Minecraft%2F/Authors and Contributors.

Steps to setup a authors and contributors page

 * Add the book's name to this list. Each book name is seperated by a  and should not use links. The title is case-sensitive.
 * Add to the table of contents of your book a link to, or add the page to another as a template, as in Guide to the Godot game engine/Contributors.

Subpages

 * /List of books/
 * /blacklist/

title: User:AuthorsAndContributorsBot


text:
User:AuthorsAndContributorsBot/List of books

Minecraft resource gathering Programming in LOLGraphics 3.4 Fireboy and Watergirl in the Forest Temple Javagony Dad ‘n Me Walkthrough Practice Problems in LOLGraphics Micronations Guide to the Godot game engine MATLAB Programming How to Program a TI-83 Plus Minesweeper Windows Vista Windows XP Modern Meitei Ancient Meitei Classical Meitei How To Assemble A Desktop PC Mathematics of the Jewish Calendar World Cultures Ukrainian%2F Cocos Malay travel phrasebook Minecraft%2F Kittypet's Guide To Warrior Cats Simple Guide to Minecraft


text:
Fireboy and Watergirl in the Forest Temple/Authors & Contributors

This list is updated automatically by AuthorsAndContributorsBot. Please do not update it manually.


text:
Javagony/Authors & Contributors

This list is updated automatically by AuthorsAndContributorsBot. Please do not update it manually.

title: Javagony/Authors & Contributors


text:
Dad ‘n Me Walkthrough/Authors & Contributors

This list is updated automatically by AuthorsAndContributorsBot. Please do not update it manually.


text:
Lentis/Zoning Laws in the United States

Zoning is the process of a governmental body dividing the land it controls into various zones with intended uses. These zones can restrict restrict construction by building size, use case, aesthetic or density. Zoning laws in the United States grew to prominence in the early 20th century, and have since become controversial due to issues resulting from their implementation. This Chapter will provide an overview of U.S. Zoning law, analyze issues that have resulted from it, and discuss proposed solutions to these issues. = Overview of Zoning =

Origins of United States Zoning Law
The first modern zoning code was written for New York City in 1916, regulating the placement of factories and maximum size of buildings. These laws would begin to be emulated by many other jurisdictions in the following years, culminating in the passage of the Standard State Zoning Enabling Act, a model law that enabled the creation of zoning regulations by cities, towns, and states. These zones would often manifest as Exclusionary laws that only permitted the construction of specific types of buildings. This style of zoning would become known as Euclidean zoning, after the court case Euclid V. Ambler enshrined the right of municipalities to zone land.

Euclidean Zoning
Euclidean zoning separates land areas into specific use cases, such as residential, commercial, or industrial. These zones can be restricted further to tailor land usage, such as single family residential districts that prohibit the construction of townhomes and apartment buildings. Zones can also feature additional requirements, such as maximum building heights, minimum parking amounts, or green space requirements. It is viewed as the default zoning method in the United States. Euclidean Zones can be flat, in which only the specified use is allowed, or hierarchical, wherein use cases are tiered and higher tier use cases can be built in any lower tiered zone (such as building residential buildings in a commercial zone). In practice this distinction is often meaningless, as hierarchical zones are usually dominated by whichever tier of use case is found to be most profitable. Euclidean zoning gained popularity due to its ease of implementation, as zones are static, clearly defined, and easily applied to existing construction. Many of the issues that cities and towns struggle with in the United States are caused by poor use of Euclidean Zoning.

= Issues That Arise From Modern Zoning Law =

The Housing Crisis
The current housing crisis in the United States is caused by a severe imbalance between demand and supply of housing, which has drastically increased housing prices. Zoning and building restrictions are one contributing factor to the housing crisis. Policies that municipalities take that limit the growth of housing include setting limits on building heights, building densities, minimum lot sizes, minimum parking requirements, and the number of housing units that can be built per year. Many municipalities also simply zone a vast majority of their land for single-family housing, leaving very little for multi-family housing. For example, in California less than 25 percent of land in cities is available for multi-family dwellings, while about 75 percent of land in cities is zoned specifically for single-family dwellings.

The solution to the housing crisis requires increased construction of multifamily housing units, but this requires easing zoning restrictions where only single-family housing is allowed. Little medium-density, or "missing middle", housing is being developed, which is also touted as a way to alleviate the housing crisis. Medium-density housing are units that fall between large apartment complexes and single-family detached housing. Examples of missing middle housing include duplexes and triplexes, and low-rise apartment complexes.

Urban Sprawl and Car Dependency
Urban sprawl is defined as "any development pattern characterized by poor accessibility and automobile dependence." Common metrics for measuring sprawl include density of development, how land use is mixed, as well as how "centered" development is around some hub.

Many negative impacts have been associated with urban sprawl. Sprawl causes massive environmental costs, such as increased air pollution and fossil fuel consumption due to complete reliance on cars as a form of transportation. Sprawling development also requires large amounts of water to sustain and can cause collapses of biodiversity and the disruption of biospheres. Sprawling development is also a drain on municipal resources, since low-density development often generates a tax base insufficient to pay for the maintenance of infrastructure.

Sprawl has also been linked with urban decay in city centers when people left city centers to settle in low-density suburbs. This drain of people from city centers and impoverished neighborhoods has caused social and economic isolation for people who could not afford to move, which historically are racial minorities. This concentration of poverty is also linked to historical zoning practices, which were deliberately designed to prevent minorities from inhabiting the same neighborhoods as whites.

Related to the issue of urban sprawl is the emergence of car dependency in the United States. Low density, single-family zoning has been linked to increased automobile usage. Since single-family zoning causes urban sprawl and people have to move further away from centers of commerce and culture, they must travel, almost exclusively by car, to access various amenities. This is seen in studies showing that "proximity of a housing unit to a region’s central business district is the most potent factor in reducing its occupants’ driving." There is a high correlation between sprawl and car dependency: the lower the density, the more car-dependent it becomes.

The issue of Urban Sprawl is much more common in the United States compared to other developed nations. This is driven by U.S. zoning laws, which heavily limit denser forms of construction, prioritize low density single-family housing, and increase the distance between residential and commercial space.

See also: Lentis/Car Dependency in the U.S.

= Attempts to Change or Fix Zoning Laws = Due to the issues caused by modern Euclidean Zoning laws, a push for zoning reform has occurred throughout the United States. This has resulted in local, state and federal efforts to improve and reform modern zoning laws.

Elimination of Single-Family Housing in Minneapolis
In 2018, the city of Minneapolis adopted a proposal to eliminate single-family zoning, allowing higher density housing on previous single-family lots. Along with ending single-family zoning, the proposal contained four additional policy changes to mend the housing affordability crisis in the city. These included allowing the development of three-to-six story buildings near transit infrastructure, phasing out off-street parking minimums, a requirement for apartment developments to reserve 10 percent of units for moderate-income housing, and increased funding for affordable housing. Elements of this proposal are set to be achieved by 2040. Proponents of this plan contended it a key mechanism towards "increasing housing construction, reducing costs of living, and easing residential segregation" while laying the groundwork for similar plans across the country.

Federal Zoning Reform Incentives
In May of 2022, the White House announced the Housing Supply Action Plan with the goal of closing the housing supply gap within the next 5 years. Under this plan, the Administration outlined incentives for jurisdictions that have reformed zoning and land use policies with higher scores in certain federal grant processes. Through investments passed by Congress, the incentives will be financed through the expansion of the Low-Income Housing Tax Credit (LIHTC) program and the HOME Investment Partnerships Program (HOME). The LIHTC program provides credits to private investors to encourage development of affordable rental housing for low-income households while the HOME program allocates grants to fund building, buying, rehabilitating affordable housing, or providing rental assistance to low-income families.

Form-Based Codes
Unlike traditional zoning, form-based codes (FBCs) focus less on land use and more on achieving better-quality urbanism through the forms of buildings. While the concept of FBCs has been around for centuries, dating back to urban planning in Ancient Greece, China, and Rome, they became of modern public interest at the end of the 20th century as a reformative alternative for Euclidean zoning. Form-based codes consist of 5 main elements: 1. Regulating Plan, 2. Public Standards, 3. Building Standards, 4. Administration, 5. Definitions. The regulating plan is a map of the designated area highlighting locations where different building form standards apply. Public standards are public realm amenities such as sidewalks and furniture. Building standards are regulations that "control the features, configurations, and functions of buildings that define and shape the public realm." The administration element details guidelines for a streamlined application and project review process. The definitions component of a FBC plan is a glossary of technical terms to be used during the project development process. This is included to ensure precise use of necessary terminology. Fundamental benefits of form-based codes include fostering a stronger sense of community, promoting walkability, and aiding transit-friendly development. FBCs are an attractive alternative to contentious zoning reforms, such as the elimination of single family housing, because they are regulations that can accomodate small units and compact urbansim. Implementation of FBCs is flexible to ease the transition from traditional zoning ordinances. Cities across the United States have incorporated FBC regulations through three approaches of varying compliance: mandatory codes, parallel codes, and floating-zone codes or planned unit developments (PUDs). Per the Congress for the New Urbanism (CNU), form-based codes are a revolutionary opportunity to curtail conventional zoning regulations since they integrate historical character into development rather than necessitating strict separation of land use.

= Conclusion = As they currently stand, zoning laws in the United States harm the quality of life for many Americans. Their overly strict nature has caused increased car dependency and urban sprawl, reduced housing equity and availability, and limited the utility of public transit. Many of these issues have been recognized in recent years, and work is being done to improve zoning by utilizing alternative zoning methods, reducing the strictness of existing zoning, and providing incentives that encourage municipalities to re-evaluate zoning practices. There is still much to do to improve zoning throughout the United States, but current efforts are a good starting point.

= References =

title: Lentis/Zoning Laws in the United States


text:
Practice Problems in LOLGraphics/Authors & Contributors

This list is updated automatically by AuthorsAndContributorsBot. Please do not update it manually.