0% found this document useful (0 votes)
9 views3 pages

Raspberry Pi and Arduino Projects Guide

Uploaded by

Yash Manral
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)
9 views3 pages

Raspberry Pi and Arduino Projects Guide

Uploaded by

Yash Manral
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

Relay Control (Raspberry Pi)

import [Link] as GPIO


import time
relay_pin = 17
[Link]([Link])
[Link](relay_pin, [Link])
try:
while True:
[Link](relay_pin, [Link])
[Link](5)
[Link](relay_pin, [Link])
[Link](5)
except KeyboardInterrupt:
[Link]()

DC Motor with L293D (Raspberry Pi)


import [Link] as GPIO
import time
in1, in2, en = 23, 24, 25
[Link]([Link])
[Link](in1, [Link])
[Link](in2, [Link])
[Link](en, [Link])
p = [Link](en, 1000)
[Link](50)
try:
[Link](in1, [Link])
[Link](in2, [Link])
[Link](5)
[Link](in1, [Link])
[Link](in2, [Link])
[Link](5)
[Link](in1, [Link])
[Link](in2, [Link])
except KeyboardInterrupt:
[Link]()

LCD I2C (Raspberry Pi)


from RPLCD.i2c import CharLCD
import time
lcd = CharLCD('PCF8574', 0x27)
[Link]()
lcd.write_string("Hello, IoT World!")
[Link](2)
[Link]()
lcd.write_string("Temp: 25C\nHumidity: 60%")

DHT11 Sensor (Raspberry Pi)


import Adafruit_DHT
import time
sensor = Adafruit_DHT.DHT11
pin = 4
while True:
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print(f"Temperature={temperature}C Humidity={humidity}%")
[Link](2)

Ultrasonic Sensor (Raspberry Pi)


import [Link] as GPIO
import time
[Link]([Link])
TRIG = 23
ECHO = 24
[Link](TRIG, [Link])
[Link](ECHO, [Link])
try:
while True:
[Link](TRIG, False)
[Link](0.5)
[Link](TRIG, True)
[Link](0.00001)
[Link](TRIG, False)
while [Link](ECHO) == 0:
pulse_start = [Link]()
while [Link](ECHO) == 1:
pulse_end = [Link]()
duration = pulse_end - pulse_start
distance = duration * 17150
print(f"Distance: {distance:.2f} cm")
except KeyboardInterrupt:
[Link]()

Arduino Blink
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}

IR Sensor (Arduino)
int ir = 2;
void setup() {
pinMode(ir, INPUT);
[Link](9600);
}
void loop() {
int state = digitalRead(ir);
[Link](state);
delay(200);
}

LM35 Sensor (Arduino)


int sensorPin = A0;
void setup() {
[Link](9600);
}
void loop() {
int value = analogRead(sensorPin);
float voltage = (value * 5.0) / 1023.0;
float temperature = voltage * 100;
[Link](temperature);
delay(500);
}
Servo Motor (Arduino)
#include <Servo.h>
Servo myservo;
void setup() {
[Link](9);
}
void loop() {
[Link](0);
delay(1000);
[Link](90);
delay(1000);
[Link](180);
delay(1000);
}

Raspberry Pi LED Blink


import [Link] as GPIO
import time
[Link]([Link])
[Link](18, [Link])
while True:
[Link](18, True)
[Link](1)
[Link](18, False)
[Link](1)

You might also like