0% found this document useful (0 votes)
8 views10 pages

SYBCS All Programs

The document outlines practical programming exercises for Raspberry Pi and Arduino, focusing on controlling LEDs, reading button inputs, detecting light intensity, and measuring temperature and humidity. It includes sample code for each practical, detailing the setup and functionality of various electronic components. The document serves as a guide for students in the Electronics Department at Dr. D.Y. Patil ACS College, Pimpri.

Uploaded by

faizanshaikhhere
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views10 pages

SYBCS All Programs

The document outlines practical programming exercises for Raspberry Pi and Arduino, focusing on controlling LEDs, reading button inputs, detecting light intensity, and measuring temperature and humidity. It includes sample code for each practical, detailing the setup and functionality of various electronic components. The document serves as a guide for students in the Electronics Department at Dr. D.Y. Patil ACS College, Pimpri.

Uploaded by

faizanshaikhhere
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Dr. D.Y.

Patil ACS College, Pimpri


S.Y.B.Sc(Computer science)
Electronics Department
All Programs for practical’s
Section1 E1
A1: Practical 1

Aim: Programming of Raspberry Pi to control LEDs attached to the GPIO


pins
Program:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(37, GPIO.OUT)
while True:
GPIO.output(37, GPIO.HIGH)
time.sleep(1)
GPIO.output(37, GPIO.LOW)
time.sleep(1)
A2: Practical 2

Aim: Programming of Raspberry Pi to get feedback from a switch connected


to the GPIO pins.

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

GPIO.setup(ldr, GPIO.OUT) #Output on the pin for


GPIO.output(ldr, False)
time.sleep(0.1)
GPIO.setup(ldr, GPIO.IN) #Change the pin back to input
while (GPIO.input(ldr) == 0):
count += 1 #Count until the pin goes high
return count

# 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

Aim: Programming of Raspberry Pi for motion detection

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>

LiquidCrystal lcd(7,6, 5, 4, 3, 2);


dht DHT;
#define DHT11_PIN 8
void setup()
{

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

Program 3: Write a program to find semi perimeter and area of triangle


a = float(input('Enter first side:'))
b = float(input('Enter second side :'))
c = float(input('Enter third side :'))
s = (a+b+c) / 2
print(' The semiperimeter of Triangle is %0.2f' %s)
area = ( s * (s-a) * (s-b) * (s-c))**0.5
print(' The area of Triangle is %0.2f' %area)
Program 4: Write a program to convert temperature in degree Celsius to Fahrenheit

cel = float (input ('Enter temperature in Celsius: '))


fah = (cel*1.8)+32 # calculate temperature in Fahrenheit
print ('%0.1f Celsius is equal to %0.1f degree Fahrenheit'%(cel, fah))
Note:
#Formula : T(℉) = T(℃) x 9/5 + 32

# Or, T(℉) = T(℃) x 1.8 + 32

You might also like