SYBCS All Programs
SYBCS All Programs
Programme:
import RPi.GPIO as GPIO # to control Raspberry Pi’s GPIO pins from Python, first need to
import the RPi.GPIO module
import time # to use sleep function from time module
GPIO.setwarnigs(False)
button = 35 #Assign physical pin no. 16 to variable button
led = 33 #Assign physical pin no. 18 to variable led
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(button, GPIO.IN) # Set button to be an input pin
GPIO.setup (led, GPIO.OUT)
while True:
button_state = GPIO.input(button) # read the status of button as input
if (button_state = = False):
GPIO.output(led, True) # if input status is false(low) then led will on
print('Button Pressed...') # if logical low level is detected then print
pressed
while GPIO.input(button) = = False:
time.sleep(0.2) # wait for 0.2 sec till
else: GPIO.output(led, False) #otherwise led is off
A3: Practical 3
Aim: Programming of Raspberry Pi to detect light intensity using photocell
sensor
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
value = 0 # this variable will be used to store the ldr
value
ldr = 32 #ldr is connected with pin number 7
led = 40 #led is connected with pin number 11
GPIO.setup(led, GPIO.OUT) # as led is an output device so that’s why we set it to
output.
GPIO.output(led, False) # keep led off by default
def rc_time (ldr):
count = 0
# Main loop
while True:
print("Ldr Value:")
value = rc_time(ldr)
print(value)
if ( value <= 20000 ):
print("Lights are ON")
GPIO.output(led, True)
if (value > 20000):
print("Lights are OFF")
GPIO.output(led, False)
A4: Practical 4
Program:
import RPi.GPIO as GPIO
sensor= 35 #read PIR Output
LED = 32 #LED for signalling motion detected
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) #choose pin no. system
GPIO.setup(sensor, GPIO.IN)
GPIO.setup(LED, GPIO.OUT)
GPIO.output(LED, GPIO.LOW)
while True:
#when motion detected turn on LED
if(GPIO.input(sensor)):
GPIO.output(LED, GPIO.HIGH)
else: GPIO.output(LED, GPIO.LOW)
Section 2 (EII)
B1 : Practical 1
Aim : To measure Temperature and Humidity by using Arduino
#include <dht.h>
#include <LiquidCrystal.h>
lcd.begin(16, 2);
}
void loop()
{
int chk = DHT.read11(DHT11_PIN);
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(DHT.temperature);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(DHT.humidity);
lcd.print("%");
delay(1000);
}
B2 : Practical 2
Aim: Study of Mobile controlled keypad interfacing using arduino.
void setup()
{
Serial.begin(9600);
pinMode(8, OUTPUT); // put your setup code here, to run once:
}
void loop()
{
if(Serial.available()>0)
{
char data= Serial.read(); // reading the data received from the bluetooth module
switch(data)
{
case 'a': digitalWrite(8, HIGH);
break;
case 'd': digitalWrite(8, LOW);break; //when d is pressed on the app on your smart
break;
default : break;
}
}
}
B3 : Practical 3
Aim: Study of Mobile controlled keypad interfacing using arduino.
Program 1: Write a program for addition, subtraction, multiplication and division
of two numbers.
num1 = 20
num2 = 15
sum = num1+num2
sub = num1-num2
mul=num1 * num2
div =num1/num2
print('The addition of {0} and {1} is {2}'.format(num1,num2,sum))
print('The subtraction of {0} and {1} is {2}'.format(num1,num2,sub))
print('The multiplication of {0} and {1} is {2}'.format(num1,num2,mul))
print('The division of {0} and {1} is {2}'.format(num1,num2,div))
Program 2 : To find area and perimeter of rectangle by using user input
len = float(input(' Enter the length'))
breath = float(input(' Enter the breath'))
area = len*breath # find area
peri=2 *(len+breath) # find perimeter
print('The area of rectangle is % o.2f' %area) # print area
print('The perimeter of rectangle is % o.2f' %peri) print perimeter