0% found this document useful (0 votes)
16 views19 pages

E Spractical

The document outlines a series of practical exercises using Arduino, covering various sensors and components including LEDs, light sensors, temperature sensors, humidity sensors, ultrasonic distance sensors, infrared motion sensors, gas sensors, and servo motors. Each practical includes the aim, relevant C++ code, and descriptions of how to set up and use the components. The exercises demonstrate basic programming and interfacing techniques with Arduino for different applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views19 pages

E Spractical

The document outlines a series of practical exercises using Arduino, covering various sensors and components including LEDs, light sensors, temperature sensors, humidity sensors, ultrasonic distance sensors, infrared motion sensors, gas sensors, and servo motors. Each practical includes the aim, relevant C++ code, and descriptions of how to set up and use the components. The exercises demonstrate basic programming and interfacing techniques with Arduino for different applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Practical 1

AIM:Introduction to Arduino

// C++ code

//

int led =12;

void setup()

pinMode(led, OUTPUT);

void loop()

digitalWrite(led, HIGH);

delay(1000); // Wait for 1000 millisecond(s)

digitalWrite(led, LOW);

delay(1000); // Wait for 1000 millisecond(s)

}
Practical 2

AIM : Light Sensitive Sensors

int ldrPin = A0; // Light sensor connected to analog pin A0

int ledPin = 9; // LED connected to digital pin 9

int threshold = 500; // Light threshold value

void setup() {

pinMode(ledPin, OUTPUT); // Set LED pin as output

Serial.begin(9600); // Start serial communication

void loop() {

int lightValue = analogRead(ldrPin); // Read value from LDR

Serial.print("Light Intensity: ");

Serial.println(lightValue); // Print light intensity to Serial Monitor

if (lightValue < threshold) {

digitalWrite(ledPin, HIGH); // Turn on LED if it's dark

} else {

digitalWrite(ledPin, LOW); // Turn off LED if there's enough light

delay(500); // Small delay for stability

}
OUTPUT :
Practical 3
AIM : Temprature Sensors

// Define the analog pin where the LM35 sensor is connected


const int sensorPin = A0;
float temperatureC;
float temperatureF;

void setup() {
Serial.begin(9600); // Start serial communication
}

void loop() {
// Read analog value from sensor
int sensorValue = analogRead(sensorPin);

// Convert analog reading (0-1023) to voltage (0-5V)


float voltage = sensorValue * (5.0 / 1023.0);

// Convert voltage to temperature (LM35 gives 10mV per degree Celsius)


temperatureC = voltage * 100.0;

// Convert Celsius to Fahrenheit


temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;

// Print values to Serial Monitor


Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.print(" °C / ");
Serial.print(temperatureF);
Serial.println(" °F");

delay(1000); // Wait for 1 second before next reading


}
OUTPUT :
Practical 4

AIM : Humidity Sensors

const int analogIn = A0;


int humiditysensorOutput = 0;
// Defining Variables
int RawValue= 0;
double Voltage = 0;
double tempC = 0;
double tempF = 0;

void setup(){
Serial.begin(9600);
pinMode(A1, INPUT);
}

void loop(){

RawValue = analogRead(analogIn);
Voltage = (RawValue / 1023.0) * 5000; // 5000 to get millivots.
tempC = (Voltage-500) * 0.1; // 500 is the offset
tempF = (tempC * 1.8) + 32; // convert to F
Serial.print("Raw Value = " );
Serial.print(RawValue);
Serial.print("\t milli volts = ");
Serial.print(Voltage,0); //
Serial.print("\t Temperature in C = ");
Serial.print(tempC,1);
Serial.print("\t Temperature in F = ");
Serial.println(tempF,1);
humiditysensorOutput = analogRead(A1);
Serial.print("Humidity: "); // Printing out Humidity Percentage
Serial.print(map(humiditysensorOutput, 0, 1023, 10, 70));
Serial.println("%");

delay(5000); //iterate every 5 seconds

OUTPUT :
Practical 5
Aim:- program using light tracking sensor

Code:- int distance = 0;

int red = 4;

int blue = 5;

int green = 6;

long readUltrasonicDistance(int triggerPin, int echoPin)

pinMode(triggerPin, OUTPUT);

digitalWrite(triggerPin, LOW);

delayMicroseconds(2);

digitalWrite(triggerPin, HIGH);

delayMicroseconds(10);

digitalWrite(triggerPin, HIGH);

pinMode(echoPin, INPUT);

return pulseIn(echoPin, HIGH);

void setup()

{
pinMode(4, OUTPUT);

pinMode(5, OUTPUT);

pinMode(6, OUTPUT);

void loop()

distance = 0.01723 * readUltrasonicDistance(10, 11);

if(distance >=200)

digitalWrite(red, HIGH);

digitalWrite(blue, LOW);

digitalWrite(green, LOW);

delay(2000);

if(distance > 100 && distance < 200)

digitalWrite(red, LOW);

digitalWrite(blue, HIGH);

digitalWrite(green, LOW);

delay(2000);

if(distance <= 100)

digitalWrite(red, LOW);

digitalWrite(blue, LOW);

digitalWrite(green, HIGH);
delay(2000);

OUTPUT:

Practical 6

Aim:- program using light tracking sensor

Code:- int distance = 0;

int red = 4;

int blue = 5;
int green = 6;

long readUltrasonicDistance(int triggerPin, int echoPin)

pinMode(triggerPin, OUTPUT);

digitalWrite(triggerPin, LOW);

delayMicroseconds(2);

digitalWrite(triggerPin, HIGH);

delayMicroseconds(10);

digitalWrite(triggerPin, HIGH);

pinMode(echoPin, INPUT);

return pulseIn(echoPin, HIGH);

void setup()

pinMode(4, OUTPUT);

pinMode(5, OUTPUT);

pinMode(6, OUTPUT);

void loop()

{
distance = 0.01723 * readUltrasonicDistance(10, 11);

if(distance >=200)

digitalWrite(red, HIGH);

digitalWrite(blue, LOW);

digitalWrite(green, LOW);

delay(2000);

if(distance > 100 && distance < 200)

digitalWrite(red, LOW);

digitalWrite(blue, HIGH);

digitalWrite(green, LOW);

delay(2000);

if(distance <= 100)

digitalWrite(red, LOW);

digitalWrite(blue, LOW);

digitalWrite(green, HIGH);

delay(2000);

OUTPUT:
Practical 7

AIM: Programs using digital infrared motion sensors.

CODE:

int a = 0;

int b = 0;

void setup()

Serial.begin(9400);

pinMode(13,OUTPUT);

void loop()

a = analogRead(A0);

b = map(a,0,1023,0,255);

Serial.println(b);
if(b>100)

Serial.println("Motion Detected");

delay(100);

OUTPUT:v

Practical 8

AIM: Programs using gas sensors.

CODE:
int LED = A1;

const int gas = 0;

int MQ2pin = A0;

void setup()

Serial.begin(9600);

void loop()

float sensorValue,MQ2pin;

sensorValue = analogRead(MQ2pin);

if(sensorValue>=470)

digitalWrite(LED,HIGH);

Serial.print(sensorValue);

Serial.println("SMOKE DETECTED");

else

digitalWrite(LED,LOW);

Serial.println("Sensor Value:");

Serial.println(sensorValue);

delay(1000);

float getsensorValue(int pin)

return(analogRead(pin));}
OUTPUT:

Practical 9
Aim: Programs using Servo motors.

Code: #include<Servo.h>

Servo servo1;

int pos= 0;

void setup ()

servo1.attach(13);

void loop()

{
for(pos=0; pos<=180; pos++)

servo1.write(pos);

delay(15);

delay(1000);

for (pos= 180; pos>=180; pos--)

servo1.write(pos);

delay(15);

You might also like