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

Code For The Project

The document contains Arduino code for a project that integrates a DHT11 temperature and humidity sensor, an ultrasonic distance sensor, a buzzer, a servo motor, and an LCD display. The code measures distance and triggers different buzzer sounds based on proximity, while also displaying temperature and humidity readings on the LCD. Additionally, the servo motor sweeps every five seconds to enhance the model's functionality.

Uploaded by

Happy studies
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)
22 views3 pages

Code For The Project

The document contains Arduino code for a project that integrates a DHT11 temperature and humidity sensor, an ultrasonic distance sensor, a buzzer, a servo motor, and an LCD display. The code measures distance and triggers different buzzer sounds based on proximity, while also displaying temperature and humidity readings on the LCD. Additionally, the servo motor sweeps every five seconds to enhance the model's functionality.

Uploaded by

Happy studies
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/ 3

CODE FOR THE PROJECT :

#include <DHT.h>

#include <Servo.h>

#include <LiquidCrystal.h>

// Pin definitions

#define TRIG_PIN 10

#define ECHO_PIN 11

#define BUZZER_PIN 8

#define DHTPIN 7

#define DHTTYPE DHT11

// DHT Sensor object

DHT dht(DHTPIN, DHTTYPE);

// LCD Pins: RS, E, D4, D5, D6, D7

LiquidCrystal lcd(12, 13, 2, 4, 5, 6);

// Servo motor object

Servo radarServo;

void setup() {

// Initialize serial communication

Serial.begin(9600);

// Initialize ultrasonic sensor pins

pinMode(TRIG_PIN, OUTPUT);

pinMode(ECHO_PIN, INPUT);

// Initialize buzzer pin

pinMode(BUZZER_PIN, OUTPUT);

// Initialize DHT sensor

dht.begin();

// Attach servo to pin 9

radarServo.attach(9);

// Initialize LCD

lcd.begin(16, 2);

lcd.print("Airport Model");

delay(2000);

lcd.clear();

void loop() {

// Measure distance

long distance = measureDistance();


// Display distance on serial monitor

Serial.print("Distance: ");

Serial.print(distance);

Serial.println(" cm");

// Buzzer warning based on distance

if (distance < 10) {

tone(BUZZER_PIN, 1000); // High-pitched beep

delay(200);

noTone(BUZZER_PIN);

delay(200);

} else if (distance < 20) {

tone(BUZZER_PIN, 500); // Medium-pitched beep

delay(400);

noTone(BUZZER_PIN);

delay(400);

} else {

noTone(BUZZER_PIN);

// Read temperature from DHT11 and display it

float temperature = dht.readTemperature();

float humidity = dht.readHumidity();

if (isnan(temperature) || isnan(humidity)) {

lcd.setCursor(0, 0);

lcd.print("Sensor Error! ");

} else {

lcd.setCursor(0, 0);

lcd.print("Temp: ");

lcd.print(temperature);

lcd.print("C ");

lcd.setCursor(0, 1);

lcd.print("Humid: ");

lcd.print(humidity);

lcd.print("% ");

// Rotate servo every 5 seconds

radarServo.write(0); // Start position

delay(500); // Wait for 0.5 seconds

radarServo.write(180); // Sweep position


delay(5000); // Wait for 5 seconds

lcd.clear(); // Clear LCD for next update

// Function to measure distance using ultrasonic sensor

long measureDistance() {

long duration, distance;

// Trigger ultrasonic pulse

digitalWrite(TRIG_PIN, LOW);

delayMicroseconds(2);

digitalWrite(TRIG_PIN, HIGH);

delayMicroseconds(10);

digitalWrite(TRIG_PIN, LOW);

// Read echo pulse

duration = pulseIn(ECHO_PIN, HIGH);

// Calculate distance in cm

distance = duration * 0.034 / 2;

// Return distance

return distance;

You might also like