Class 8

  • What is sensor
  • types of sensor
  • LDR sensor
  • IR sensor
  • project 1
  • ultrasonic sensor
  • 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);
}

 Smoke sensor  : -  smoke detector is a device that senses smoke, typically as an indicator of fire


coding of smoke sensor

#define MQ2pin 0

float sensorValue;  //variable to store sensor value

void setup() {
	Serial.begin(9600); // sets the serial port to 9600
	Serial.println("MQ2 warming up!");
	delay(20000); // allow the MQ2 to warm up
}

void loop() {
	sensorValue = analogRead(MQ2pin); // read analog input pin 0

	Serial.print("Sensor Value: ");
	Serial.println(sensorValue);
	
	delay(2000); // wait 2s for next reading
}

Rain drop sensor : -   The Raindrops Detection sensor module is used for rain detection. It is also for measuring rainfall intensity.  

       





Connection of raindrop sensor

                     








Coding of Raindrop sensor     

              int sensorRead = 0;

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

void loop() {
int sensorRead= analogRead(A0);
Serial.println(sensorRead);
}


MC Q3

MQ3 Alcohol Gas Sensor detects the concentrations of alcohol gas in the air and ouputs its reading as an analog voltage. The sensor can measure concentrations of 0.04mg/L to 4mg/L





Coding of MC Q3

        /* MQ-3 Alcohol Sensor Circuit with Arduino */
int AnalogPin=0;//the AOUT pin of the alcohol sensor goes into analog pin A0 of the arduino
int value1 = 0; 
int value2 = 0;
float promille=0;
void setup() {
Serial.begin(115200);//sets the baud rate
pinMode(AnalogPin, INPUT);//sets the pin as an input to the arduino
delay(14400000); // this it the pre heat time, maybe not enough, I make a check today
}
void loop()
{
value1= analogRead(AnalogPin);//reads the analaog value from the alcohol sensor's AOUT pin I guess it is Parts per Million
value2=value1 - 98; // here I made a small work around, this sensor has a very long pre heat time, when it is not heated to working temperature, it will show values too high even when there is no alcohol, thats why I removed the amount which was over 0, when no alcohol was next to it
// limit= digitalRead(DOUTpin);//reads the digital value from the alcohol sensor's DOUT pin
Serial.print("Alcohol value: ");
Serial.println(value2);//prints the alcohol value
promille = (0.4/200)*value2*2;
Serial.print("Promillewert: ");
Serial.println(promille,3);
//Serial.print("Limit: ");
//Serial.print(limit);//prints the limit reached as either LOW or HIGH (above or underneath)
delay(100) ;
}



Bluetooth:-  Bluetooth is a wireless communication technology that allows devices to connect and exchange data over short distances. It operates in the 2.4 GHz frequency range and is commonly used for connecting devices like smartphones, headphones, speakers, and other peripherals. Bluetooth enables features like audio streaming, file transfer, and device control, making it convenient for a wide variety of applications. Its low power consumption and ease of use have contributed to its widespread adoption in consumer electronics.

#define led1 2

#define led2 3


char val;

void setup() {

 Serial.begin(9600);

 pinMode(led1,OUTPUT);

 pinMode(led2,OUTPUT);


}


void loop() {

  if(Serial.available())

  {

    val= Serial.read();

    Serial.println(val);

    if(val=='1')

    digitalWrite(led1,HIGH);

    else if(val=='2')

    digitalWrite(led1,LOW);

    else if(val=='3')

    digitalWrite(led2,HIGH);

    else if(val=='4')

    digitalWrite(led2,LOW);

  }

    

    

  }

What is ioT

The Internet of Things (IoT) is a network of physical objects that are connected to the internet and can exchange data with other devices and systems: 

Key Components of IoT

  1. Devices/Things: Physical objects such as smart thermostats, wearables, home appliances, vehicles, etc., equipped with sensors, actuators, and communication interfaces.
  2. Connectivity: The means through which devices communicate with each other and to a central hub or cloud, such as Wi-Fi, Bluetooth, 5G, Zigbee, and other network protocols.
  3. Data Processing and Analysis: The collected data is processed using cloud computing, edge computing, or AI to derive actionable insights. This could involve machine learning algorithms and analytics to make decisions.
  4. User Interface: The means by which users interact with IoT systems, whether it’s through mobile apps, dashboards, or voice commands.

How IoT Works

  • Sensors in IoT devices collect data about the physical environment, such as temperature, motion, or humidity.
  • The data is then transmitted via network connectivity to a central system (cloud or local servers).
  • The system processes the data, often using algorithms to make real-time decisions or trigger actions.
  • The actuators in IoT devices can then perform specific actions, such as turning off a light, adjusting a thermostat, or sending notifications to users.

Applications of IoT

  1. Smart Homes: Devices like smart thermostats, security cameras, and lighting systems can be controlled remotely to improve convenience, security, and energy efficiency.
  2. Healthcare: Wearable devices and sensors enable continuous monitoring of health metrics such as heart rate, blood sugar, or activity levels, contributing to personalized healthcare.
  3. Smart Cities: IoT helps monitor and manage urban infrastructure, from traffic lights to waste management, improving sustainability and efficiency.
  4. Industrial IoT (IIoT): In industries, IoT sensors monitor machinery health, track inventory, optimize production lines, and enable predictive maintenance.
  5. Agriculture: Smart sensors monitor soil conditions, moisture levels, and weather forecasts to optimize crop management and irrigation.

Benefits of IoT

  • Efficiency and Automation: IoT devices can automate tasks and improve operational efficiency by making real-time adjustments.
  • Cost Savings: By optimizing processes and reducing waste, IoT can lead to significant cost reductions, especially in energy and resource management.
  • Data-Driven Insights: IoT systems provide valuable data that can be used for improving products, services, and customer experiences.
  • Improved Decision-Making: Real-time data allows for better decision-making in various sectors like manufacturing, healthcare, and urban planning.

Challenges of IoT

  • Security: With the vast number of connected devices, IoT systems can be vulnerable to cyberattacks. Ensuring data privacy and device security is a key concern.
  • Interoperability: Devices from different manufacturers may not always communicate effectively, creating challenges for integration and standardization.
  • Data Management: Handling the massive amounts of data generated by IoT devices requires robust storage and processing systems.

Future of IoT

The IoT market is growing rapidly with the advent of 5G networks, which enable faster and more reliable communication between devices. IoT is expected to be increasingly integrated with artificial intelligence (AI), machine learning, and edge computing to enable more advanced, real-time, and intelligent systems.

In conclusion, IoT is transforming industries, homes, and cities, offering endless possibilities for automation, efficiency, and innovation. As the technology evolves, it will continue to reshape the way we interact with the world around us.


ESP :-   An ESP microcontroller is a low-cost, low-power system-on-chip (SoC) microcontroller with integrated Wi-Fi and Bluetooth connectivity:


 Microcontroller :- A microcontroller unit (MCU) is essentially a small computer on a single chip. It is designed to manage specific tasks within an embedded system ...

  









INDEX

  •  Light blinking
  •  Traffic lights
  •  Motor control 
  •  Servo motor control
  •  Sensor control

Control a led by IOT

  1. Go to Blynk website
  2. log in
  3. Create a new template
  4. Select microcontroller esp8266 and Done
  5. Go to DataStream 
  6. select virtual pin 
  7. write name , datatype - integer and done
  8. Go to Web Dashboard and drag & paste switch button
  9. click on setting of switch and select led(v0) ans Save  
  10. install bynk on mobile if you want to control from mobile
  11. Go to +New device 
  12. form template . 


Now setting on Arduino IDE
  1. open Arduino 
  2. click on preference 
  3. paste  http://arduino.esp8266.com/stable/package_esp8266com_index.json
  4. Go to board manager and install the ESP8266 board
  5. Download blynk library
  6.  Download ESP8266 wifi library 
  7. select include library and add zip of blynk annd esp board
  8. Write blynk code in Arduino 
/*New blynk app project
   Home Page
*/

//Include the library files
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define BLYNK_AUTH_TOKEN "" //Enter your blynk auth token

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "";//Enter your WIFI name
char pass[] = "";//Enter your WIFI password

//Get the button value
BLYNK_WRITE(V0) {
  digitalWrite(D0, param.asInt());
}

void setup() {
  //Set the LED pin as an output pin
  pinMode(D0, OUTPUT);
  //Initialize the Blynk library
  Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
}

void loop() {
  //Run the Blynk library
  Blynk.run();
}








 

                      

    




Comments

Popular posts from this blog

Class 6

Class 5