/* project done by Turya Bhattacharjee
components used :- LCD display 16*2 , buzzer , LED 2 , NTC sensor , ultrasonic sensor accelerometer + gyroscope */
#define ECHOpin 5 // it defines the ECHO pin of the sensor to pin 5 of Arduino
#define TRIGpin 6
// we have defined the variable
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd (12, 11, 10, 9, 8, 7);
Adafruit_MPU6050 mpu;
int greenLED1=7;
int redLED2=8;
int blueLED3= 13;
int buzzer=2;
int ThermistorPin = 0;
int Vo;
float R1 = 100000;
float logR2, R2, T;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
void setup() {
lcd.begin(20,4);
pinMode(TRIGpin, OUTPUT); // It sets the ECHO pin as OUTPUT
pinMode(ECHOpin, INPUT); // It sets the TRIG pin as INPUT
Serial.println("Test of the Ultrasonic Sensor HC-SR04"); // It will appear on Serial Monitor
Serial.println("with the Arduino UNO R3 board");
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(2, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(115200);
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
lcd.print("MPU6050 Found!");
delay(500);
lcd.clear();
delay(500);
// set accelerometer range to +-8G
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
// set gyro range to +- 500 deg/s
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
// set filter bandwidth to 21 Hz
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
delay(100);
}
void loop() {
// It first sets the TRIG pin at LOW for 2 microseconds
digitalWrite(TRIGpin, LOW);
delayMicroseconds(4);
// It now sets TRIG pin at HIGH for 15 microseconds
digitalWrite(TRIGpin, HIGH);
delayMicroseconds(15);
digitalWrite(TRIGpin, LOW);
// It will read the ECHO pin and will return the time
duration = pulseIn(ECHOpin, HIGH);
// distance formula
distance = duration*(0.034/2); // (speed in microseconds)
// Speed of sound wave (340 m/s)divided by 2 (forward and backward bounce)
// To display the distance on Serial Monitor
lcd.print("Distance: ");
lcd.print(distance);
lcd.println(" cm"); //specified unit of distance
delay(500);
lcd.clear();
delay(500);
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
lcd.print("Acceleration = ");
lcd.println(a.acceleration.x);
delay(500);
lcd.clear();
delay(500);
if (a.acceleration.x >= 3) {
digitalWrite(redLED2, HIGH);
digitalWrite(buzzer, HIGH);
delay(500);
}
else {
digitalWrite(greenLED1, HIGH);
digitalWrite(buzzer, HIGH);
digitalWrite(redLED2, LOW);
delay(500);
}
if (distance <=45){
digitalWrite(blueLED3, HIGH);
digitalWrite(buzzer, HIGH);
}
else {
digitalWrite(blueLED3, LOW);
digitalWrite(buzzer, LOW);
digitalWrite(redLED2, LOW);
}
Vo = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
T = T - 273.15;
// Tf = (T * 9.0)/ 5.0 + 32.0;
lcd.print("Temp:");
//lcd.print(Tf);
//lcd.print(" F");
lcd.print(T);
lcd.print("c");
delay(500);
lcd.clear();
delay(500);
}