Class 8

  • What is sensor
  • types of sensor
  • LDR sensor
  • IR sensor
  • project 1
  • smoke sensor
  • Rain drop sensor
  • MQ3 sensor
  • project 2
  • Bluetooth
  • LCD
  • project 3
  • IOT
  • esp32
  • esp8266
  • Led project by esp32 and esp8266
  • Sensor connect of esp32
  • final project




#LDR 

int ldr = A0;


void setup() {

  Serial.begin(9600);

  pinMode(A0,INPUT);

  pinMode(13,OUTPUT);


}


void loop() {

  int data = analogRead(ldr);

  Serial.print(" ldr ");

  Serial.println(data);

  delay(100);

  if(data <= 500)

  {

    digitalWrite(13,HIGH);

  }

  else

  {

    digitalWrite(13,LOW);

  }


}




#Ultrasonic

An ultrasonic sensor is device that measures the distance to an object using ultrasonic sound waves.


                           
An ultrasonic sensor works through a process that involves sending out sound waves and measuring the time it takes for them to return. Here’s a step-by-step explanation of how it operates:

1. **Emission of Ultrasound**: The sensor has a transducer that emits a burst of high-frequency sound waves (ultrasound) into the environment.

2. **Travel of Sound Waves**: These sound waves travel through the air until they encounter an object or surface.

3. **Reflection of Sound Waves**: When the sound waves hit an object, they bounce back towards the sensor.

4. **Reception of Echoes**: The sensor has a receiver (often part of the same transducer) that detects the returning sound waves, or echoes.

5. **Time Measurement**: The sensor measures the time it takes for the sound waves to travel from the sensor to the object and back. This time interval is crucial for determining the distance.

6. **Distance Calculation**: Using the speed of sound in air (approximately 343 meters per second at room temperature), the sensor calculates the distance to the object. The formula used is:

                                Distance=Time×Speed of Sound/2


      
Coding of ultrasonic sensor.
// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600); // Starts the serial communication
}
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);
  delay(100);
}



Comments

Popular posts from this blog

Class 6

Class 5