0% found this document useful (0 votes)
12 views2 pages

Mission 2

The document contains an Arduino sketch that measures distance using an ultrasonic sensor. It controls two LEDs based on the measured distance, providing feedback through the serial monitor. The program categorizes distances into three ranges, triggering different LED states and messages accordingly.

Uploaded by

정원혁
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Mission 2

The document contains an Arduino sketch that measures distance using an ultrasonic sensor. It controls two LEDs based on the measured distance, providing feedback through the serial monitor. The program categorizes distances into three ranges, triggering different LED states and messages accordingly.

Uploaded by

정원혁
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

int trigPin=9;

int echoPin=8;
int LED1=5;
int LED2=6;

void setup() {
Serial.begin(9600);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);

// put your setup code here, to run once:

void loop() {
// put your main code here, to run repeatedly:
float duration, distance;
digitalWrite(trigPin,HIGH);
delay(10);
digitalWrite(trigPin,LOW);

duration=pulseIn(echoPin,HIGH);
distance=((float)(340*duration/10000)/2);

Serial.print("Duration:");
Serial.print(duration);
Serial.print("|nDistance:");
Serial.print(distance);
Serial.println("cm|n");

if (distance<10) {
digitalWrite(LED1,LOW);
digitalWrite(LED2,HIGH);
Serial.println("너무 가까워요!");
}

else if ((distance>=10) && (distance<=30)) {


digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
}

else {
digitalWrite(LED1,HIGH);
digitalWrite(LED2,LOW);
Serial.println("가까이 와 주세요!");
}

delay(500);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy