Commit cdf7c1f6 authored by james.clarke2's avatar james.clarke2

Update My_Alarm_Sensor

parent 89478a1d
const int trigPin = 9;
const int echoPin = 10;
const int buzzer = 11;
const int ledPin = 13;
long duration;
int distance; Serial.print("Connecting");
int safetyDistance; while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());
void setup() {
pinMode(trigPin, OUTPUT); pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT); pinMode(echoPin, INPUT);
pinMode(buzzer, OUTPUT); pinMode(buzzer, OUTPUT);
pinMode(ledPin, OUTPUT); pinMode(ledPin, OUTPUT);
Serial.begin(9600); Serial.begin(9600);
}
}
void loop() { void loop() {
...@@ -36,7 +42,7 @@ void loop() { ...@@ -36,7 +42,7 @@ void loop() {
distance= duration*0.034/2; distance= duration*0.034/2;
safetyDistance = distance; safetyDistance = distance;
if (safetyDistance <= 5) { if (safetyDistance <= 20) {
digitalWrite(buzzer, HIGH); digitalWrite(buzzer, HIGH);
digitalWrite(ledPin, HIGH); digitalWrite(ledPin, HIGH);
} }
...@@ -49,6 +55,6 @@ void loop() { ...@@ -49,6 +55,6 @@ void loop() {
Serial.println(distance); Serial.println(distance);
} }
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment