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

Experiments Code

The document provides a series of Arduino/Raspberry Pi programs for interfacing various sensors and components. It includes code examples for controlling an LED with a timer, responding to a push button or digital sensor, reading temperature from a DHT11 sensor, monitoring an IR sensor's digital values, and measuring distance with an ultrasonic sensor. Each section contains setup and loop functions tailored to the specific hardware interaction.

Uploaded by

dishankalternate
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)
2 views3 pages

Experiments Code

The document provides a series of Arduino/Raspberry Pi programs for interfacing various sensors and components. It includes code examples for controlling an LED with a timer, responding to a push button or digital sensor, reading temperature from a DHT11 sensor, monitoring an IR sensor's digital values, and measuring distance with an ultrasonic sensor. Each section contains setup and loop functions tailored to the specific hardware interaction.

Uploaded by

dishankalternate
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/ 3

1) .

To interface LED/Buzzer with Arduino/Raspberry Pi and write a program to turn ON LED for 1 sec after
every 2 seconds.

int led = 4;
void setup()
{
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led,HIGH);
delay(2000);
digitalWrite(led,LOW);
delay(2000);

2).To interface Push button/Digital sensor with Arduino/Raspberry Pi and write a program to turn ON LED
when push button is pressed or at sensor detection.

int ir = 4;
int led = 3;
void setup()
{
pinMode(ir,INPUT);
pinMode(led,OUTPUT);

void loop()
{
int value = digitalRead(ir);

if (value == 1)
{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led, LOW);
}

}
3).To interface Temperature sensor with Arduino/Raspberry Pi and write a program to print
temperature value in Serial monitor.

#include <DHT11.h>
DHT11 dht11(2);

void setup()
{
Serial.begin(9600);
}
void loop()
{
// For Temperature
int temperature = dht11.readTemperature();
Serial.print ("Temperature: ");
Serial.print (temperature);
Serial.println(" °C ");
delay (1000);
}

4). To interface IR sensor with Arduino/Raspberry Pi and write a program to print digital
values in Serial monitor.

int ir = 4;
void setup()
{
Serial.begin(9600);
pinMode(ir,INPUT);
}

void loop()
{
int value = digitalRead(ir);
Serial.println(value);
delay(1000);
}
5.) To interface Ultrasonic sensor with Arduino/Raspberry Pi and write a program to print
distance values in Serial monitor.

int echoPin = 6;
int trigPin = 7;

long duration;
long distance;

void setup() {

// put your setup code here, to run once:


pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
Serial.begin(9600);
}
void loop() {

//-put your main code here, to run repeatedly:

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);


distance = duration * 0.034 / 2 ;
Serial.print("distance :");
Serial.print(distance);
Serial.println("cm ");
delay(1000);
}

You might also like