0% found this document useful (0 votes)
4 views6 pages

Arduino RaspberryPi Programs

The document contains various Arduino and Raspberry Pi programs for different applications, including LED blinking based on temperature, object detection using IR sensors, and temperature and humidity monitoring with DHT11. It also includes examples of LED brightness control using PWM, binary counting, and digital counters. Each program is presented with code snippets and demonstrates specific functionalities related to hardware interactions.

Uploaded by

landocleatusmsec
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)
4 views6 pages

Arduino RaspberryPi Programs

The document contains various Arduino and Raspberry Pi programs for different applications, including LED blinking based on temperature, object detection using IR sensors, and temperature and humidity monitoring with DHT11. It also includes examples of LED brightness control using PWM, binary counting, and digital counters. Each program is presented with code snippets and demonstrates specific functionalities related to hardware interactions.

Uploaded by

landocleatusmsec
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

Arduino IDE and Raspberry Pi Programs

1) LED Blinking Speed Based on Temperature using LM35

int sensorPin = A0;


int ledPin = 9;

void setup() {
pinMode(ledPin, OUTPUT);
[Link](9600);
}

void loop() {
int value = analogRead(sensorPin);
float voltage = value * (5.0 / 1023.0);
float temp = voltage * 100;

int delayTime = map(temp, 20, 50, 1000, 100);

digitalWrite(ledPin, HIGH);
delay(delayTime);
digitalWrite(ledPin, LOW);
delay(delayTime);
}

2) LED and IR Sensor for Object Detection

int irPin = 2;
int ledPin = 13;

void setup() {
pinMode(irPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
int state = digitalRead(irPin);

if (state == LOW) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}

3) LM35 Temperature Sensor Display

int sensorPin = A0;

void setup() {
[Link](9600);
}

void loop() {
int value = analogRead(sensorPin);
float voltage = value * (5.0 / 1023.0);
float temp = voltage * 100;

[Link]("Temperature: ");
[Link](temp);
[Link](" °C");

delay(1000);
}

4) DHT11 Temperature and Humidity

#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
[Link](9600);
[Link]();
}

void loop() {
float temp = [Link]();
float hum = [Link]();
[Link]("Temp: ");
[Link](temp);
[Link](" °C Humidity: ");
[Link](hum);
[Link](" %");

delay(2000);
}

5) LED Brightness Control using PWM

int ledPin = 9;

void setup() {
pinMode(ledPin, OUTPUT);
}

void loop() {
for (int i = 0; i <= 255; i++) {
analogWrite(ledPin, i);
delay(10);
}

for (int i = 255; i >= 0; i--) {


analogWrite(ledPin, i);
delay(10);
}
}

6) LM35 with LED Threshold Control

int sensorPin = A0;


int ledPin = 13;

void setup() {
pinMode(ledPin, OUTPUT);
}

void loop() {
int value = analogRead(sensorPin);
float temp = value * (5.0 / 1023.0) * 100;
if (temp > 30) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}

delay(500);
}

7) 2-bit Binary Counter using Raspberry Pi

import [Link] as GPIO


import time

pins = [17, 27]

[Link]([Link])
for pin in pins:
[Link](pin, [Link])

try:
while True:
for i in range(4):
[Link](pins[0], i & 1)
[Link](pins[1], (i >> 1) & 1)
[Link](1)

except KeyboardInterrupt:
[Link]()

8) Digital Counter using LEDs in Arduino

int leds[] = {2, 3, 4, 5};

void setup() {
for (int i = 0; i < 4; i++) {
pinMode(leds[i], OUTPUT);
}
}

void loop() {
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 4; j++) {
digitalWrite(leds[j], (i >> j) & 1);
}
delay(1000);
}
}

9) Blink Multiple LEDs in Sequence

int leds[] = {2, 3, 4, 5};

void setup() {
for (int i = 0; i < 4; i++) {
pinMode(leds[i], OUTPUT);
}
}

void loop() {
for (int i = 0; i < 4; i++) {
digitalWrite(leds[i], HIGH);
delay(300);
digitalWrite(leds[i], LOW);
}
}

10) IR Sensor with LED using Raspberry Pi

import [Link] as GPIO


import time

IR_PIN = 17
LED_PIN = 18

[Link]([Link])

[Link](IR_PIN, [Link])
[Link](LED_PIN, [Link])

try:
while True:
sensor = [Link](IR_PIN)
if sensor == 0:
[Link](LED_PIN, [Link])
print("Object Detected")
else:
[Link](LED_PIN, [Link])
print("No Object")

[Link](0.5)

except KeyboardInterrupt:
[Link]()

You might also like