Professional Documents
Culture Documents
IT Major Elective 3
Submitted by:
CRISANTO H PORNIA
Submitted to:
DARYLL A. CABAGAY
TURNING LED ON
(Activity #1)
Description
The above figure shows that the first led will turn on and last for 5 seconds, the
second led will turn on and last for 5 seconds while in the other hand the first led turns
off. The third led will turn on and last for 5 seconds while the second led turn off.
Circuit Design
GPIO.setmode(GPIO.BCM) GPIO.output(24,GPIO.HIGH)
GPIO.setwarnings(False) time.sleep(1)
print("Led off")
while(True): GPIO.output(24,GPIO.LOW)
GPIO.setup(18,GPIO.OUT)
time.sleep(1) GPIO.output(21,GPIO.HIGH)
GPIO.output(21,GPIO.LOW
ULTRASONIC SENSOR
(Activity #2)
Description
Above figure shows that when ultrasonic detects an object distance is less than 5
and greater than 2, led 1 will turn on while in the other hand if the ultrasonic sensor
detect an object distance less than 21 and greater than 6 the led 2 will turn on and led 1
will turn off. If the ultrasonic detects an object distance greater than 21 the led 3 will turn
on and led 2 will turn off.
Circuit Design
GPIO.setmode(GPIO.BCM) GREEN = 17
GPIO.setwarnings(False) YELLOW = 27
GPIO.setup(4,GPIO.OUT) GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(18,GPIO.OUT) GPIO.output(TRIG,0)
GPIO.setup(24,GPIO.OUT) time.sleep(1)
time.sleep(0.00001) GPIO.output(4,GPIO.HIGH)
GPIO.output(TRIG,0) GPIO.output(18,GPIO.LOW)
pass time.sleep(2)
GPIO.output(4,GPIO.LOW)
pass GPIO.output(24,GPIO.HIGH)
else:
GPIO.cleanup()
(ACTIVITY #3)
Description
The figure above shows that when ultrasonic sensor detects an object distance
greater than 0 and less than 7 the led 1 will turn on and the buzzer beeps while if the
distance is greater than 7 and less than 12 the led 2 will turn on and led 1 will turn off
and the buzzer will turn off. If the distance is greater than 13 led 3 turns on and led 2 will
turn off and buzzer will turn off.
Circuit Design
T-COBBLER
(Activity #4)
Description
Above figure shows that T-cobbler is connected to raspberry pi and to the breadboard.
All the pins are the connected to the pins of the breadboard where the T-cobbler is set. when
ultrasonic detects an object distance is less than 5 and greater than 2, led 1 will turn on
while in the other hand if the ultrasonic sensor detect an object distance less than 21
and greater than 6 the led 2 will turn on and led 1 will turn off. If the ultrasonic detects
an object distance greater than 21 the led 3 will turn on and led 2 will turn off.
Circuit Design
import RPi.GPIO as GPIO while True:
import math
ECHO = 18
GPIO.setmode(GPIO.BCM) GREEN = 17
GPIO.setwarnings(False) YELLOW = 27
GPIO.setup(4,GPIO.OUT)
GPIO.setup(18,GPIO.OUT) GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(24,GPIO.OUT) GPIO.output(TRIG,0)
time.sleep(1)
GPIO.setup(ECHO,GPIO.IN)
GPIO.output(TRIG,1)
time.sleep(0.00001) GPIO.output(4,GPIO.HIGH)
GPIO.output(TRIG,0) GPIO.output(18,GPIO.LOW)
GPIO.output(24,GPIO.LOW)
time.sleep(2)
GPIO.output(4,GPIO.LOW)
GPIO.output(24,GPIO.HIGH)
pass
Description
Above figure shows that the three led’s turn on at the same time with different
intensity. The pins used are 2, 3 and 4. The first led Duty Cycle is 5, the second led Duty Cycle
10 and the third led Duty Cycle is 100.
Circuit Design
import RPi.GPIO as GPIO pwm_3=GPIO.PWM(23,50)
import time
pwm_1.start(5)
GPIO.setwarnings(False) pwm_3.start(100)
duty = int(duty_s)
pwm_1=GPIO.PWM(4,50) pwm_1.ChangeDutyCycle(duty)
pwm_2=GPIO.PWM(18,50) time.sleep(0.5)
except KeyboardInterrupt: finally:
RASPBERRY PI – ARDUINO
(Activity #6)
Description
The figure above shows how to connect raspberry pi with arduino using serial
through this raspberry pi can send state to the arduino to turn on and off the led.
Circuit Design
Raspberry pi: print("LED Turn Off")
DC MOTOR
(Activity #7)
Description
The figure above shows that the DC spins forward for 5 seconds after that it spins
backwards then the DC stops.
Circuit Design
import RPi.GPIO as GPIO GPIO.setup(Motor1E,GPIO.OUT)
def loop():
Motor1A = 24 GPIO.output(Motor1A,GPIO.HIGH)
Motor1B = 23 GPIO.output(Motor1B,GPIO.LOW)
Motor1E = 25 GPIO.output(Motor1E,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.HIGH)
GPIO.setup(Motor1B,GPIO.OUT)
sleep(5) if __name__ == '__main__': # Program start
from here
# Stop
setup()
GPIO.output(Motor1E,GPIO.LOW)
try:
loop()
def destroy():
except KeyboardInterrupt:
GPIO.cleanup()
destroy()
Description
The figure above shows that the program starts the DC Motor spins forward and when
the ultrasonic sensor detects a distance of greater than 10 the DC Motor spins backwards.
Circuit Design
import RPi.GPIO as GPIO # Forwards
import time GPIO.output(Motor1A, GPIO.HIGH)
GPIO.output(Motor1B, GPIO.LOW)
GPIO.setwarnings(False) GPIO.output(Motor1E, GPIO.HIGH)
TRIG = 20 while(True):
ECHO = 21 GPIO.output(TRIG, False)
Motor1A = 24 print("Waiting For Sensor To Settle")
Motor1B = 23 time.sleep(2)
Motor1E = 25
GPIO.output(TRIG, True)
def setup(): time.sleep(0.00001)
GPIO.setmode(GPIO.BCM) GPIO.output(TRIG, False)
GPIO.setup(Motor1A, GPIO.OUT)
GPIO.setup(Motor1B, GPIO.OUT) while GPIO.input(ECHO)==0:
GPIO.setup(Motor1E, GPIO.OUT) pulse_start = time.time()
GPIO.setup(TRIG, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN) while GPIO.input(ECHO)==1:
pulse_end = time.time()
def loop():
pulse_duration = pulse_end - pulse_start GPIO.output(Motor1E, GPIO.HIGH)
Description
Above figure shows that when the program starts the cars DC Motor spins forward and
when the ultrasonic sensor detects a distance of greater than 5 the DC Motor spins backwards.
So, the car can avoid an obstacle in its way.
Circuit Design
import RPi.GPIO as GPIO GPIO.setup(TRIG, GPIO.OUT)
import time GPIO.setup(ECHO, GPIO.IN)