0% found this document useful (0 votes)
4 views

Tutorial Sheet for Ardunio and sensor (1)

The document contains a tutorial sheet with class work and home assignment questions related to Arduino programming. It includes code examples for blinking an LED, using an LDR sensor to control an LED based on light levels, and counting objects with an IR sensor. Additionally, it poses questions for home assignments on using IR sensors, interfacing LDRs, ultrasonic sensors, and DHT11 sensors with Arduino.
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)
4 views

Tutorial Sheet for Ardunio and sensor (1)

The document contains a tutorial sheet with class work and home assignment questions related to Arduino programming. It includes code examples for blinking an LED, using an LDR sensor to control an LED based on light levels, and counting objects with an IR sensor. Additionally, it poses questions for home assignments on using IR sensors, interfacing LDRs, ultrasonic sensors, and DHT11 sensors with Arduino.
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/ 2

Tutorial Sheet - (Unit2)

Class Work

Question-1 Write down a program for blinking of LED.


void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

----------------------------------------------------------------------------
Question2. Use an LDR sensor with an Arduino to turn on an LED when it gets dark (i.e., when
the LDR value falls below a certain threshold). Write the code for this application.

const int ledPin = 13; //pin at which LED is connected


const int ldrPin = A0; //pin at which LDR is connected
int threshold = 118;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT); //Make LED pin as output
pinMode(ldrPin, INPUT); //Make LDR pin as input
}
void loop()
{
//analogWrite(9,(1023-analogRead(ldrPin)));
//delay(100);
int ldrStatus = analogRead(ldrPin); //saving the analog values received from LDR into "ldrStatus"
variable
if (ldrStatus <= threshold) //set the threshold value below at which the LED will turn on
{ //you can check in the serial monior to get approprite value for your LDR
digitalWrite(ledPin, HIGH); //Turing LED ON
Serial.print("Its DARK, Turning ON the LED : ");
Serial.println(ldrStatus);
}
else
{
digitalWrite(ledPin, LOW); //Turing OFF the LED
Serial.print("Its BRIGHT, Turning OFF the LED : ");
Serial.println(ldrStatus);
}
}

Question3.- How can you use an IR sensor to count the number of objects passing through a
detection zone? Write the code to implement this functionality.

int irPin = 2; // IR sensor connected to pin 2

int irValue = 0; // Variable to store the IR sensor value

int objectCount = 0; // Counter for objects detected

void setup()

{ pinMode(irPin, INPUT); // Set IR sensor pin as input

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

void loop() { irValue = digitalRead(irPin); // Read IR sensor value

if (irValue == LOW) { // Object detected

objectCount++; // Increment object count

Serial.print("Object Detected! Total Count: ");

Serial.println(objectCount);

delay(1000); // Debounce delay (wait for 1 second)

delay(100); // Small delay to avoid multiple detections from the same object }

Home Assignment
Q1. Write an Arduino program using IR sensor
i) In case detects movement then display “outsider in the park”
ii) In case movement not detected then display “park is safe”
“In case 1: LED will glow RED”. And “ in case 2 : LED will be off.”

Q2. Explain how to interface an LDR with an Arduino UNO to measure the intensity of light
and print the value on the serial monitor.
Q3: Write down a program to interface Arduino with Ultrasonic Sensor.

Q4. Explain how to interface a DHT11 temperature and humidity sensor with Arduino UNO
and write a program to read and display the temperature on the serial monitor.

You might also like