Electronics

During the next few weeks, we will be learning how to use electronics with a raspberry pi, and how to code the raspberry pi to run an electronic circuit.

Click on the following tabs below to view what we have done in the previous session.

In the first week, we will learn how to build a basic electronic circuit using an LED, Resistor and a Pi.

Equipment

1x LED
1x Resistor 220Ω
2x M-F Jumper Leads
1x Breadboard
1x Raspberry Pi

Powering a single LED

  1. Connect the negative leg of the LED to a GND pin on the Pi
  2. Connect the positive leg of the LED to one leg of the resistor.
  3. Connect the other leg of the resistor to the +3.3V pin on the Pi

Circuit diagram

Controlling a LED with a Pi

  1. Make sure that the RPI-GPIO is set up the on the Pi
  2. Connect the negative leg of the LED to a GND pin on the Pi
  3. Connect the positive leg of the LED to one leg of the resistor
  4. Connect the other leg of the resistor to a GPIO pin on the Pi
  5. Write some code to control the GPIO pin your using

Circuit diagram

In this circuit, we are using GPIO17 or pin 11 and pin 9 for GND


Sample code

In this circuit, we are using GPIO17 or pin 11 and pin 9 for GND

 


Usefull images

Key Terms

  • LED   — Light Emitting Diode
  • GND  — Ground or 0V
  • V       — Volts
  • GPIO — General-Purpose Input/Output
  • Ω       — Ohms (to measure resistance)

If you need to recap on what we have learned during this week the PowerPoint presentation can be downloaded here

Challenge 1

Can you find out how to code and wire up a button to an LED light, so when the button is pressed and only pressed the light will start pulsing?

Challenge 2

Can you make the same LED pulse when the button is pressed until the button is pressed for a second time?

Equipment

1x tactile push button
1x resistor
1x breadboard
1x raspberry pi

Saying “Hello Dojo” with a button

  1. Connect one leg of the resistor to a 3.3V pin on the Pi
  2. Connect the other leg of the resistor to the button
  3. Connect finally connect the other side of the button a GPIO pin on the Pi
  4. To set up the GPIO pin as an input you will need to write the following code
    GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

    This will Set pin 10 to be an input pin and set initial value to be pulled low (off)

  5. Finally to write the code to print “Hello Dojo” when button is pressed
    while True: # Run forever
    if GPIO.input(10) == GPIO.HIGH:
    
    print("Button was pushed!")
    
    

Circuit diagram

Challenge 1

Can you make a traffic light sequence with 2 sets of lights and a pedestrian light?
Sequence:
Road 1 Green – Road 2 Red – Ped Red
Road 1 Red – Road 2 Green – Ped Red
Road 1 Red – Road 2 Red – Ped Green

Challenge 2

Can you make the road lights turn red and ped lights turn green when the button is pressed?


Challenge 3

Can you make the same traffic signals but with a ped button?
Sequence:
Loop
Road 1 Green – Road 2 Red – Ped Red
Road 1 Red – Road 2 Green – Ped Red
If button pressed
Road 1 Red – Road 2 Red – Ped Green

Weekly Presentations

Week 1 presentation  – download

Week 2 presentation – download

Leave a Reply

Your email address will not be published. Required fields are marked *