Raspberry pi & Arduino programs
Raspberry pi programs:
# led interfacing raspberry pi
# to study and understand led interfacing raspberry pi
from RPi.GPIO import *
import time
setwarnings(False)
setmode(BCM)
setup(4,OUT)
while True :
output(4,HIGH)
time.sleep(2)
output(4,LOW)
time.sleep(3)
# switch interfacing raspberry pi
# to study and understand interfacing switch connect to the raspberry pi
from RPi.GPIO import *
import time
setwarnings(False)
setmode(BCM)
setup(4,OUT)
setup(17,IN)
while True :
button_state=input(17)
if button_state == False :
output(4,False)
print("Button pressed...")
while input(17) == False :
time.sleep(2)
else :
output(4,True)
#temperature sensor(LM35)
#to study and understand concept of interfacing temperature sendor (LM35)
# to raspberry pi
import Adafruit_ADS1x15
import time
adc=Adafruit_ADS1x15.ADS1115()
GAIN = 1
while True :
values=[0]*1
for i in range(1) :
values[i]=adc.read_adc(i,gain=GAIN)
temp=values[i]*0.125
temp=temp/10
print("analog o/p={0:>6}".format(*values))
printf("temp. in C={0:>6}".format(temp))
time.sleep(2)
#LDR interfacing arduino
#to study and understand concept of interfaong photocell sensor (ldr)
# to raspberry pi
import Adafruit_ADS1x15
import time
adc=Adafruit_ADS1x15.ADS1115()
GAIN = 1
while True :
values=[0]*1
for i in range(1) :
values[i]=adc.read_adc(i,gain=GAIN)
if values[i]>300 :
print("dark condition")
else :
print("light condition")
time.sleep(2)
#PIR sensor interfacing raspberry pi
# to study and understand concept of interfacing passive infra-red (pir)
# sensor to raspberry pi
from RPi.GPIO import *
import time
setmode(BCM)
setup(4,OUT)
setup(17,IN)
while True :
button_state=input(17)
if button_state==True :
output(4,False)
print("motion detected..")
while input(17) == True :
time.sleep(2)
else :
output(4,True)
Arduino programs:
//LED interfacing ARDUINO
//to study and understand the concept of led interfacing arduino
int LED1=13;
int LED2=12;
int LED3=11;
void setup()
{
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
}
void loop()
{
digitalWrite(LED1,HIGH);
delay(200);
digitalWrite(LED2,HIGH);
delay(200);
digitalWrite(LED3,HIGH);
delay(200);
digitalWrite(LED1,LOW);
delay(300);
digitalWrite(LED2,LOW);
delay(300);
digitalWrite(LED3,LOW);
delay(300);
}
//TEMPERATURE &HUMIDITY SENSOR
// to study and understand concept of temperature and humidity sensor
interfacing arduino
#include<dht.h>
dth=DHT;
#define DHT11_PIN 3
GAIN=1;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int chk=DHT.read11(DHT11_PIN);
Serial.println("humidity");
Serial.println(DHT.humidity,1);
Serial.println("temperature");
Serial.println(DHT.temperature,1);
delay(5000);
}
Python program:
# conversion of decimal
# conversion of decimal to binary,octal,hexadecimal equivalent no
# using python programming
num=int(input("hey plz enter the decimal no:"))
print("decimal to binary conversion is:",bin(num))
print("decimal to octal conversion is:",oct(num))
print("decimal to hexadecimal conversion is:",hex(num))
d
Comments
Post a Comment
hey