Session 3 DIY Moderate Project Indraneel Mukhopadhyay Skill Level: Moderate Dates: 11th January, 2017 Time: 2:00pm to 5:30pm
Overview This session includes Three Projects: Using Capacitive Module Sensor Using RGB Module Using PIR Module Sensor Overview
Bill of Materials Required for the three Projects Required for all three projects: One (1) Raspberry Pi 3 plus USB cables and power supply Ten (10) Female-Female jumper wires PROJECT D also requires: One (1) Capacitive Module Sensor PROJECT E also requires: One (1) RGB Module Sensor PROJECT F also requires: One (1) PIR Module Sensor Bill of Materials Required for the three Projects
DIY Project D: Capacitive Sensor Using the Raspberry Pi to control a Capacitive Sensor DIY Project D: Capacitive Sensor
Capacitive Module Example: What's Required: One (1) Capacitive Module Sensor (OSEPP-Touch-01) Three (3) Female-Female jumper wires Capacitive Module Example:
How Capacitive Sensor works: The sensor plate and the touch of your finger forms a capacitor. Capacitors store charge. The greater the capacitance, the more charge it can store.. The capacitance of this capacitive touch sensor depends on how close your finger is to the plate. How Capacitive Sensor works:
Direct Connection to GPIO Bus with three Female-Female jumpers Jumper Wire Connections: CapSen GND Pin 1 to GND (Pin 6) CapSen Vcc Pin 2 to 3.3v (Pin 1) CapSen Sig Pin 3 to GPIO-23 (Pin 16)
The CODE (Page 1 of 1) See also: capsensor.txt import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) padPin = 23 GPIO.setup(padPin, GPIO.IN) alreadyPressed = False while True: padPressed = GPIO.input(padPin) if padPressed and not alreadyPressed: print "pressed" alreadyPressed = padPressed time.sleep(0.1) The CODE (Page 1 of 1) See also: capsensor.txt
To Run the Sensor at Terminal > sudo python capsensor To Run the Sensor at Terminal > sudo python capsensor.py Output Screen -> In actual applications, the 'pressed' output would be used to initiate other actions in other parts of a larger program
DIY Project E: RGB Module Using the Raspberry Pi to colour control a RGB Module Sensor DIY Project E: RGB Module
RGB Sensor Module Example: What's Required: One (1) RGB Module Sensor (XINDA 3-Clr) Four (4) Female-Female jumper wires RGB Sensor Module Example:
The RGB colour model is an additive colour model in which red, green and blue light are added together in various ways to reproduce a broad array of colours. The name RGB comes from the initials of the three additive primary LED colours: red, green and blue. What is RGB Sensor
Direct Connection to GPIO Bus with four Female-Female jumpers Jumper Wire Connections: RGB B Pin 1 to GPIO-27 (Pin 13) RGB G Pin 2 to GPIO-18 (Pin 12) RGB R Pin 3 to GPIO-17 (Pin 11) RGB GND Pin 4 to GND (Pin 6)
The CODE (Page 1 of 5) See also: rgb.txt # Import the modules used in the script import random, time import RPi.GPIO as GPIO # Set GPIO to Broadcom system and set RGB Pin numbers RUNNING = True GPIO.setmode(GPIO.BCM) red = 17 green = 18 blue = 27 # Set pins to output mode GPIO.setup(red, GPIO.OUT) GPIO.setup(green, GPIO.OUT) GPIO.setup(blue, GPIO.OUT) The CODE (Page 1 of 5) See also: rgb.txt
The CODE (Page 2 of 5) See also: rgb.txt Freq = 100 #Hz # Setup all the LED colors with an initial # duty cycle of 0 which is off RED = GPIO.PWM(red, Freq) RED.start(0) GREEN = GPIO.PWM(green, Freq) GREEN.start(0) BLUE = GPIO.PWM(blue, Freq) BLUE.start(0) # Define a simple function to turn on the LED colors def color(R, G, B, on_time): The CODE (Page 2 of 5) See also: rgb.txt
The CODE (Page 3 of 5) See also: rgb.txt def color(R, G, B, on_time): # Color brightness range is 0-100% RED.ChangeDutyCycle(R) GREEN.ChangeDutyCycle(G) BLUE.ChangeDutyCycle(B) time.sleep(on_time) # Turn all LEDs off after on_time seconds RED.ChangeDutyCycle(0) GREEN.ChangeDutyCycle(0) BLUE.ChangeDutyCycle(0) print("Light It Up!") print("Press CTRL + C to quit.\n") print(" R G B\n---------") The CODE (Page 3 of 5) See also: rgb.txt
The CODE (Page 4 of 5) See also: rgb.txt # Main loop try: while RUNNING: for x in range(0,2): for y in range(0,2): for z in range(0,2): print (x,y,z) # Slowly ramp up power percentage of each active color for i in range(0,101): color((x*i),(y*i),(z*i), .02) # If CTRL+C is pressed the main loop is broken except KeyboardInterrupt: RUNNING = False print "\Quitting" The CODE (Page 4 of 5) See also: rgb.txt
The CODE (Page 5 of 5) See also: rgb.txt # Actions under 'finally' will always be called # regardless of what stopped the program finally: # Stop and cleanup so the pins # are available to be used again GPIO.cleanup() The CODE (Page 5 of 5) See also: rgb.txt
To Run the Sensor at Terminal > sudo python rgb To Run the Sensor at Terminal > sudo python rgb.py Output Screen -> Although we the terminal displays the RGB outputs here as (x,x,x) where "1" shows the LED as ON and "0" as LED OFF - which would be usable to inform other parts of a larger program - merely looking at the RGB Module shows the output results.
DIY Project F: PIR Sensor Using PIR Sensor with Raspberry Pi DIY Project F: PIR Sensor
PIR Sensor Module Example: What's Required: One (1) PIR Sensor (HC-SR501) Three (3) Female-Female jumper wires PIR Sensor Module Example:
PIR stands for Passive InfraRed PIR stands for Passive InfraRed. This motion sensor consists of a fresnel lens, an infrared detector and supporting detection circuitry. The lens on the sensor focuses any infrared radiation present around it towards the infrared detector. Our bodies generate infrared heat and as a result this gets picked up by the motion sensor. The sensor outputs a 5V signal for a period of one minute as soon as it detects the presence of a person. What is PIR Sensor:
When the PIR motion sensor detects a person, it outputs a 5V signal to the Raspberry Pi through its connection to the GPIO. The sensor is highly sensitive and offers a tentative range of detection of about 6-7 meters.. How it works:
Direct Connection to GPIO Bus with three Female-Female jumpers Jumper Wire Connections: PIR Pin 1 to 5v (Pin 02) PIR Pin 2 Output to GPIO-04 (Pin 7) PIR Pin 3 to GND (Pin 6)
The CODE (Page 1 of 1) See also: pirtst.txt import RPi.GPIO as GPIO import time GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(07, GPIO.IN) #Read output from PIR motion sensor while True: i=GPIO.input(07) if i==0: #When output from motion sensor is LOW print "No intruders",i time.sleep(0.1) elif i==1: #When output from motion sensor is HIGH print "Intruder detected",i The CODE (Page 1 of 1) See also: pirtst.txt
To Run the Sensor at Terminal > sudo python pirrrr To Run the Sensor at Terminal > sudo python pirrrr.py Output Screen->
Questions ? End of Session 3