TeCoEd (Teaching Computing Education)
  • Home
    • Freelance
    • Book
    • Downloading
  • Python
    • Learn Python >
      • Python Modules
    • PyGame Zero
    • Python Programs >
      • Higher or Lower
      • Magic Calculator
      • Password Checker
      • Python Pit
    • What's News App
    • Pixels to Cells
    • Python Mosaics
    • Python OCR
    • L-1-AM
    • Web Scraping >
      • Scraping Trains
    • Weather App
    • Snakes and Windows
    • Python Web Server >
      • Flask
    • Python Picks
  • Ras Pi
    • All About the Pi
    • Getting Started
    • Remote Desktop and VNC
    • Static IP Address
    • Sonic Pi >
      • 3.14
    • Twitter Feed >
      • Tweepy
    • Android & Pi >
      • Advanced Apps
      • Odds
    • A.I on the the Pi
    • CRON
    • Pick Your Own
  • Pi Hardware
    • Pi HATS >
      • Sense Hat Hacks
      • AstroPi HAT
      • Unicorn-HAT >
        • Unicorn Alphabet Disco
        • Uni Codes / Programs
      • Skywriter
      • Piano HAT
    • STS Pi
    • Pi Camera >
      • Pi-Cam, Python & Email >
        • Time Lapse
      • Pi Noir
    • Pipsta >
      • Flask, Input & Printers
    • Raspberry Pi Power >
      • Energenie IR power
    • Pibrella
    • Distance Sensor
    • LCD Screen
    • Pi-Tooth
    • Robot Arm
    • PiGlow
    • PiFM
    • Accelerometer
    • PiFace >
      • Installing PiFace >
        • Python Commands
  • Pi-Hacks
    • Drone Hacks
    • Pi Glue Gun Hack
    • Blinkt!
    • Sonic Pixels
    • R2D2
    • Get to the chopper
    • Astro Bird
    • Twitter Translator
    • Hacking a Robot
    • Nature_Box >
      • Best Nature Photos
    • Wearable Tech >
      • Project New York
      • P.N.Y Part 2 Health
      • P.N.Y Part 3 Games
      • P.N.Y Part 4 Translation
    • Dino-Tweet
    • Other Links
  • Pi-Hacks 2
    • The Joker
    • Hologram Machine
    • Google Vision: Camera Tell
    • Yoda Tweets
    • Pi Phone
    • Darth Beats
    • Twitter Keyword Finder
    • Crimbo Lights Hack
    • Xmas Elf
    • Halloween 2016
    • Halloween Hack 2015
    • Socrative Zombie
    • Voice Translation
    • The Blue-Who Finder
    • GPIO, Twitter
    • Pi Chat Bot >
      • Dictionary Definitions
    • PiGlow & Email
    • Pibrella Alarm System
    • SMS with Python >
      • Spooking a Mobile
  • Pi-Hacks 3
    • LED Dance Suit
    • Ferminal
    • Crypto Tracker
    • David Bowie
    • Lamp Prank >
      • TEST
    • Yoda FM
    • Retro Player
    • LED Pixel Art
    • TARDIS
    • Battleships
    • LED Board
    • Night Vision
    • Enviro+ Weather
  • Minecraft
    • Minecraft API
    • Minecraft Sweeper
    • PiGlove: Minecraft Power Up
    • Minecraft Photo-booth
    • Rendering Pixels
    • Speed Cube
    • Lucky Dip
  • Computing
    • Why Computing?
    • Can You Compute
    • micro:bit
    • Coding Resources
    • Learn to Code >
      • Coding with iPads
      • Apps Creation Tools
      • sKratchInn
      • Sound Editing
    • Cheat Sheets
    • Theory
    • HOUR OF CODING
    • BEBRAS Computing Challange
    • Computer Facts
    • Free Software and Links
  • Contact Me
  • Random Hacks
    • Movile

THE SOCRATIVE ZOMBIE


As a teacher I am always looking for new ways to support students to learn and develop understanding. One of my students made a zombie head which I rescued  from the display cabinet.  Imagine a zombie that sensed you were in the room and asked you questions about your learning? First, let's make it ask for some Brains!

1. Getting Started


This simple hack makes use of a PIR which can be purchased here for about £2.99.  The sensor is sensitive enough to detect changes in the temperature as a person or animal works past or near. Using a Python script the 'motion' can be used used to trigger an event, such as turning on an LED, moving a part or even speaking and asking a question.

2. Wiring Up


The wiring of the PIR is very simple and uses only three of the GPIO pins.  The PINS stated here are the physical pin numbers on the Raspberry Pi not the GPIO numbers.  The +5V pin on the PIR connects to PIN 2 on the GPIO board, the OUT connects to PIN 26 and the Ground connects to PIN 6.  

3. The Test Program 


Next step is to create the program to respond to the event that  is triggered by the PIR sensor.  First update the Raspberry Pi software and then start a new Python window:

In the LXTerminal:
sudo apt-get update
sudo idle

Then type the following code this is originally from ModMyPi and will test that the sensor is working:

import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

PIR = 7
GPIO.setup(PIR, GPIO.IN)

print "Ready to find you"
time.sleep(2)

def Motion_Sensing(PIR):
    print "We see you"

try:
    GPIO.add_event_detect(PIR, GPIO.RISING, callback=Motion_Sensing)
    while 1:
        time.sleep(100)
except KeyboardInterrupt:
    print "Quit"
    GPIO.cleanup()


Program Code


Picture
Final Code
File Size: 1 kb
File Type: py
Download File


4. The GPIO PINs


Picture
When the previous code is run, you should see the words "We see you" displayed in the terminal window each time the sensor is triggered.  If not there may be a few areas to check.

1) Ensure that the wires are connected correctly, the Pi is orientated so that the audio jack is on the left hand side and the USB ports are at the end, the SD card is nearest to you.  

2) PIN 26 on the GPIO is the the trigger, since we are using the BCM settings the PIN is referenced as PIN 7 in the code.

3) The PIR has two dials that can be changed to adjust the settings of the PIR.  The first is to adjust the sensitivity which will make the PIR trigger more or less.  The second dial adjusts the rest time between the sensor stopping and then restarting again. This is originally set around a few second delay.


5. Adding Sound and an LED


Once the Sensor is triggered the next step is to return a response or output for the user to see, the Zombie has to react!.  The Zombie calls out a demand for brains or scream.  Collect a number of wav files and numbers them 1 to 10.  Using Python create a variable that picks a random number between 1 and 10, ie it picks a random wav file to play.  PyGame has the facilities to play the wav file, call the pygame mixer and then locate the wav file which is saved in the /home/pi/ folder.. 

list_of_sounds = str(random.randint(1,9))
pygame.mixer.init(frequency=22050,size=-16,channels=4)
sound = pygame.mixer.Sound("/home/pi/" + list_of_sounds + ".wav")
sound.play()


Finally add an LED to PIN 11 (GPIO 17) and add it to the code with GPIO.setup(17, GPIO.OUT). To flash the LED use the code below to turn the PIN on and off,

GPIO.output(17, True)
time.sleep(0.3)
GPIO.output(17, False)


The final part is to set up a Cron job to start the Program when ever the Raspberry Pi is booted up - click here for the instructions  

........CLICK HERE TO SEE THE LEGEND OF THE ZOMBIE............

Powered by Create your own unique website with customizable templates.