├── code ├── 1-helloworld.py ├── 2-led-buzzer.py ├── 3-temperature.py ├── 4-light.py ├── 5-movement.py └── 6-alarm.py ├── images └── CamJam-EduKit-2-small1.jpg ├── CamJam EduKit 2 - Sensors Worksheet 4 - Light.pdf ├── CamJam EduKit 2 - Sensors Worksheet 6 - Alarm.pdf ├── CamJam EduKit 2 - Sensors Worksheet 5 - Movement.pdf ├── CamJam EduKit 2 - Sensors Worksheet 3 - Temperature.pdf ├── CamJam EduKit 2 - Sensors Worksheet 1 - Introduction.pdf ├── CamJam EduKit 2 - Sensors Worksheet 2 - LEDs and Buzzer.pdf ├── README.md ├── .gitignore └── LICENSE /code/1-helloworld.py: -------------------------------------------------------------------------------- 1 | # CamJam EduKit 2 - Sensors 2 | # Worksheet 1 - Hello World! 3 | 4 | print("Hello World!") 5 | -------------------------------------------------------------------------------- /images/CamJam-EduKit-2-small1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CamJam-EduKit/EduKit2/HEAD/images/CamJam-EduKit-2-small1.jpg -------------------------------------------------------------------------------- /CamJam EduKit 2 - Sensors Worksheet 4 - Light.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CamJam-EduKit/EduKit2/HEAD/CamJam EduKit 2 - Sensors Worksheet 4 - Light.pdf -------------------------------------------------------------------------------- /CamJam EduKit 2 - Sensors Worksheet 6 - Alarm.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CamJam-EduKit/EduKit2/HEAD/CamJam EduKit 2 - Sensors Worksheet 6 - Alarm.pdf -------------------------------------------------------------------------------- /CamJam EduKit 2 - Sensors Worksheet 5 - Movement.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CamJam-EduKit/EduKit2/HEAD/CamJam EduKit 2 - Sensors Worksheet 5 - Movement.pdf -------------------------------------------------------------------------------- /CamJam EduKit 2 - Sensors Worksheet 3 - Temperature.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CamJam-EduKit/EduKit2/HEAD/CamJam EduKit 2 - Sensors Worksheet 3 - Temperature.pdf -------------------------------------------------------------------------------- /CamJam EduKit 2 - Sensors Worksheet 1 - Introduction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CamJam-EduKit/EduKit2/HEAD/CamJam EduKit 2 - Sensors Worksheet 1 - Introduction.pdf -------------------------------------------------------------------------------- /CamJam EduKit 2 - Sensors Worksheet 2 - LEDs and Buzzer.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CamJam-EduKit/EduKit2/HEAD/CamJam EduKit 2 - Sensors Worksheet 2 - LEDs and Buzzer.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CamJam Edukit 2 2 | 3 | ![CamJam EduKit 2](./images/CamJam-EduKit-2-small1.jpg) 4 | 5 | The code contained within this repository is for use with the CamJam Edukit 2 - Sensors, created by the organisers of The Cambridge Raspberry Jam (http://camjam.me), an event for fans of the Raspberry Pi. 6 | 7 | The kit costs only £8 including UK VAT, and is available from [The Pi Hut](http://thepihut.com/collections/camjam-edukit) 8 | -------------------------------------------------------------------------------- /code/2-led-buzzer.py: -------------------------------------------------------------------------------- 1 | # CamJam EduKit 2 - Sensors 2 | # Worksheet 2 - LEDs and Buzzer 3 | 4 | # Import Python libraries 5 | import time 6 | from gpiozero import LED, Buzzer 7 | 8 | # Set up the LEDs and Buzzer 9 | red = LED(18) 10 | blue = LED(24) 11 | buzzer = Buzzer(22) 12 | 13 | print("Lights and sound on") 14 | red.on() 15 | blue.on() 16 | buzzer.on() 17 | 18 | # Pause for one second 19 | time.sleep(1) 20 | 21 | print("Lights and sound off") 22 | red.off() 23 | blue.off() 24 | buzzer.off() 25 | -------------------------------------------------------------------------------- /code/3-temperature.py: -------------------------------------------------------------------------------- 1 | # CamJam EduKit 2 - Sensors 2 | # Worksheet 3 - Temperature 3 | 4 | # Import Libraries 5 | import time 6 | from w1thermsensor import W1ThermSensor, Unit 7 | 8 | sensor = W1ThermSensor() 9 | 10 | # Print out the temperature until the program is stopped. 11 | while True: 12 | temp_c = sensor.get_temperature(Unit.DEGREES_C) 13 | temp_f = sensor.get_temperature(Unit.DEGREES_F) 14 | 15 | print(temp_c, " Celsius") 16 | print(temp_f, " Fahrenheit") 17 | 18 | time.sleep(1) 19 | -------------------------------------------------------------------------------- /code/4-light.py: -------------------------------------------------------------------------------- 1 | # CamJam EduKit 2 - Sensors 2 | # Worksheet 4 - Light 3 | 4 | # Import Libraries 5 | import time 6 | from RPi import GPIO 7 | 8 | # Set up the GPIO Mode 9 | GPIO.setmode(GPIO.BCM) 10 | GPIO.setwarnings(False) 11 | 12 | # The Light Sensor pin number 13 | PIN_LIGHT = 27 14 | 15 | 16 | def read_ldr(): 17 | ldrcount = 0 # Sets the count to 0 18 | GPIO.setup(PIN_LIGHT, GPIO.OUT) 19 | GPIO.output(PIN_LIGHT, GPIO.LOW) 20 | time.sleep(0.1) # Drains all charge from the capacitor 21 | 22 | GPIO.setup(PIN_LIGHT, GPIO.IN) # Sets the pin to be input 23 | 24 | # While the input pin reads 'off' or Low, count 25 | while GPIO.input(PIN_LIGHT) == GPIO.LOW: 26 | ldrcount += 1 # Add one to the counter 27 | 28 | return ldrcount 29 | 30 | 31 | while True: 32 | print(read_ldr()) 33 | time.sleep(1) # Wait for a second 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | *.egg-info/ 23 | .installed.cfg 24 | *.egg 25 | 26 | # PyInstaller 27 | # Usually these files are written by a python script from a template 28 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 29 | *.manifest 30 | *.spec 31 | 32 | # Installer logs 33 | pip-log.txt 34 | pip-delete-this-directory.txt 35 | 36 | # Unit test / coverage reports 37 | htmlcov/ 38 | .tox/ 39 | .coverage 40 | .coverage.* 41 | .cache 42 | nosetests.xml 43 | coverage.xml 44 | *,cover 45 | 46 | # Translations 47 | *.mo 48 | *.pot 49 | 50 | # Django stuff: 51 | *.log 52 | 53 | # Sphinx documentation 54 | docs/_build/ 55 | 56 | # PyBuilder 57 | target/ 58 | *.ini 59 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 CamJam-EduKit 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /code/5-movement.py: -------------------------------------------------------------------------------- 1 | # CamJam EduKit 2 - Sensors 2 | # Worksheet 5 - Movement 3 | 4 | # Import Python header files 5 | import time 6 | from gpiozero import MotionSensor 7 | 8 | # Set a variable to hold the GPIO Pin identity 9 | pir = MotionSensor(17) 10 | 11 | print("Waiting for PIR to settle") 12 | pir.wait_for_no_motion() 13 | 14 | print("PIR Module Test (CTRL-C to exit)") 15 | 16 | 17 | try: 18 | # Variables to hold the current and last states 19 | current_state = False 20 | previous_state = False 21 | 22 | # Loop until users quits with CTRL-C 23 | while True: 24 | # Read PIR state 25 | current_state = pir.motion_detected 26 | 27 | # If the PIR is triggered by movement. 28 | if current_state is True and previous_state is False: 29 | print(" Motion detected!") 30 | # Record previous state 31 | previous_state = True 32 | # If the PIR has returned to ready state 33 | elif current_state is False and previous_state is True: 34 | print(" No Motion") 35 | previous_state = False 36 | 37 | # Wait for 10 milliseconds 38 | time.sleep(0.01) 39 | 40 | except KeyboardInterrupt: 41 | print(" Quit") 42 | -------------------------------------------------------------------------------- /code/6-alarm.py: -------------------------------------------------------------------------------- 1 | # CamJam EduKit 2 - Sensors 2 | # Worksheet 6 - Alarm 3 | 4 | # Import Python header files 5 | import time 6 | from gpiozero import MotionSensor, LED, Buzzer 7 | 8 | # Set a variable to hold the GPIO Pin identity 9 | pir = MotionSensor(17) 10 | red = LED(18) 11 | blue = LED(24) 12 | buzzer = Buzzer(22) 13 | 14 | print("Waiting for PIR to settle") 15 | pir.wait_for_no_motion() 16 | 17 | print("PIR Module Test (CTRL-C to exit)") 18 | 19 | 20 | def sound_alarm(): 21 | # Flash the LEDs and sound buzzer three times 22 | for x in range(0, 3): 23 | buzzer.on() 24 | red.on() 25 | time.sleep(0.2) 26 | red.off() 27 | blue.on() 28 | time.sleep(0.2) 29 | blue.off() 30 | buzzer.off() 31 | time.sleep(0.2) 32 | 33 | 34 | try: 35 | # Variables to hold the current and last states 36 | current_state = False 37 | previous_state = False 38 | 39 | # Loop until users quits with CTRL-C 40 | while True: 41 | # Read PIR state 42 | current_state = pir.motion_detected 43 | 44 | # If the PIR is triggered 45 | if current_state is True and previous_state is False: 46 | print(" Motion detected!") 47 | sound_alarm() 48 | 49 | # Record previous state 50 | previous_state = True 51 | 52 | # If the PIR has returned to ready state 53 | elif current_state is False and previous_state is True: 54 | print(" No Motion") 55 | previous_state = False 56 | 57 | # Wait for 10 milliseconds 58 | time.sleep(0.01) 59 | 60 | except KeyboardInterrupt: 61 | print(" Quit") 62 | --------------------------------------------------------------------------------