float temp;
int tempPin=0;
int sensor=7;
int Motion_Sensor_value;
int echoPin=9;
int trigPin=13;
int redLEDpin=10;
int greenLEDpin=11;
int buzzer=4;
void setup() {
// put your setup code here, to run once:
pinMode(sensor,INPUT);//configuring pin 7 as Input
Serial.begin(9600);//To show output value of sensor in serial monitor
pinMode(redLEDpin,OUTPUT);
pinMode(greenLEDpin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(trigPin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
temp=analogRead(tempPin);
temp=temp*0.48828125+32;
Serial.print("Welcome to the demo car");
Serial.print("Current Engine Temperature:");
Serial.print(temp);
Serial.print("*F");
Serial.println();
delay(3000);
if(temp<132)
{
Motion_Sensor_value=digitalRead(sensor);// reading sensor value from pin 7
int duration=pulseIn(echoPin,HIGH);
int dist=duration*0.34/2;
if(Motion_Sensor_value==1 || dist<100)
{digitalWrite(greenLEDpin,HIGH);//turn on the LED/Buzzer when motion is detected by writing 1 to the pin 10
digitalWrite(redLEDpin,LOW);
digitalWrite(echoPin,HIGH);
digitalWrite(trigPin,LOW);
delayMicroseconds(1);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
tone(buzzer,1000,5000);
Serial.println("Stop!");
Serial.println("Motion detected!");//printing output to serial monitor
Serial.print("Distance:");
Serial.println(dist);
delay(5000);
}else{
digitalWrite(redLEDpin,HIGH);
digitalWrite(greenLEDpin,LOW);
digitalWrite(12,HIGH);
Serial.println("Carry on no obstacle there!");//printing output to serial monitor
}
}
else{
Serial.print("Car Overheated!!");
tone(buzzer,20000,2000);
delay(2000);
tone(buzzer,10000,2000);
delay(2000);
tone(buzzer,20000,2000);
delay(2000);
}
}
Comments
Please log in or sign up to comment.