Posts

Showing posts from February, 2024

Materials Required for Temperature Project

                                                  Temperature and Humidity Sensor:-  https://amzn.to/3IeZ1rb                                                                  Arduino UNO:- https://amzn.to/3mhamzG Jumper Wires:- https://amzn.to/3GvV1SW   Breadboard:- https://amzn.to/3Ulqv3G LCD Display With I2C Module:- https://amzn.to/3Vd1Gtt

Arduino Code Temperature Sensor

 //Libraries #include <DHT.h> //I2C LCD: #include <LiquidCrystal_I2C.h> #include <Wire.h> LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display    //Constants #define DHTPIN A3     // what pin we're connected to #define DHTTYPE DHT11   // DHT 11 DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino //Variables //int chk; int h;  //Stores humidity value int t; //Stores temperature value void setup() {     Serial.begin(9600);     Serial.println("Temperature and Humidity Sensor Test");     dht.begin();     lcd.init(); //initialize the lcd     lcd.backlight(); //open the backlight } void loop() {     //Read data and store it to variables h (humidity) and t (temperature)     // Reading temperature or humidity takes about 250 milliseconds!     h = dht.readHumidity();     t = dht.readTemperature();          //Print temp and humidity values to serial monitor     Serial.print("Humidity: &qu

Circuit Diagram Temperature Sensor

Image
 

Arduino Code

 //define Pins #include <Servo.h> Servo servo; int trigPin = 11; int echoPin = 12; // defines variables long duration; int distance; void setup()  {   servo.attach(13);   servo.write(180);  delay(2000);    // Sets the trigPin as an Output pinMode(trigPin, OUTPUT); // Sets the echoPin as an Input  pinMode(echoPin, INPUT); } void loop()  { // Clears the trigPin digitalWrite(trigPin, LOW); delayMicroseconds(2); // Sets the trigPin on HIGH state for 10 micro seconds digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Reads the echoPin, returns the sound wave travel time in microseconds duration = pulseIn(echoPin, HIGH); // Calculating the distance distance= duration*0.034/2; // Prints the distance on the Serial Monitor Serial.print("Distance: "); Serial.println(distance); if ( distance <= 25   ) // Change Distance according to Ultrasonic Sensor Placement  { servo.write(180); delay(3000);  }  else  { servo.write(90);  } }

Circuit Diagram

Image