아두이노 - 모션 센서 - LED | Arduino - Motion Sensor - LED

우리는 HC-SR501 동작 센서로부터의 동작 감지에 따라 LED를 켜고 끄는 방법을 배울 것입니다.

준비물

1×Arduino Uno Amazon
1×USB 2.0 cable type A/B 쿠팡 | Amazon
1×HC-SR501 Motion Sensor Amazon
1×LED Amazon
1×220 ohm resistor Amazon
1×Breadboard 쿠팡 | Amazon
1×Jumper Wires Amazon
1×(Optional) 9V Power Adapter for Arduino Amazon
1×(Recommended) Screw Terminal Block Shield for Arduino Uno 쿠팡 | Amazon
1×(Optional) Transparent Acrylic Enclosure For Arduino Uno Amazon
공개: 이 섹션에서 제공된 링크 중 일부는 제휴 링크입니다. 이 링크를 통해 구매한 경우 추가 비용없이 수수료를 받을 수 있습니다. 지원해 주셔서 감사합니다.

LED 및 모션 센서에 관하여

다음 튜토리얼에서 LED 및 모션 센서(핀아웃, 작동 원리, 프로그래밍 방법 등)에 대해 모른다면 배워보세요:

선연결

Arduino Motion Sensor LED Wiring Diagram

이 이미지는 Fritzing을 사용하여 만들어졌습니다. 이미지를 확대하려면 클릭하세요.

초기 설정

Time Delay AdjusterScrew it in anti-clockwise direction fully.
Detection Range AdjusterScrew it in clockwise direction fully.
Repeat Trigger SelectorPut jumper as shown on the image.
arduino motion sensor initial setting

아두이노 코드

/* * 이 Arduino 코드는 newbiely.kr 에서 개발되었습니다 * 이 Arduino 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino/arduino-motion-sensor-led */ const int MOTION_SENSOR_PIN = 7; // Arduino 핀이 모션 센서의 출력핀에 연결됨 const int LED_PIN = 3; // Arduino 핀이 LED의 핀에 연결됨 int motionStateCurrent = LOW; // 모션 센서 핀의 현재 상태 int motionStatePrevious = LOW; // 모션 센서 핀의 이전 상태 void setup() { Serial.begin(9600); // 시리얼 초기화 pinMode(MOTION_SENSOR_PIN, INPUT); // 아두이노 핀을 입력 모드로 설정 pinMode(LED_PIN, OUTPUT); // 아두이노 핀을 출력 모드로 설정 } void loop() { motionStatePrevious = motionStateCurrent; // 이전 상태 저장 motionStateCurrent = digitalRead(MOTION_SENSOR_PIN); // 새로운 상태 읽기 if (motionStatePrevious == LOW && motionStateCurrent == HIGH) { // 핀 상태 변경: LOW -> HIGH Serial.println("Motion detected!"); digitalWrite(LED_PIN, HIGH); // 켜기 } else if (motionStatePrevious == HIGH && motionStateCurrent == LOW) { // 핀 상태 변경: HIGH -> LOW Serial.println("Motion stopped!"); digitalWrite(LED_PIN, LOW); // 끄기 } }

사용 방법

  • 아두이노를 USB 케이블을 통해 PC에 연결하세요.
  • 아두이노 IDE를 열고, 올바른 보드와 포트를 선택하세요.
  • 위의 코드를 복사하고 아두이노 IDE로 엽니다.
  • 아두이노 IDE에서 Upload 버튼을 클릭하여 코드를 아두이노에 업로드하세요.
Arduino IDE Upload Code
  • 센서 앞으로 손을 움직이세요
  • LED 상태의 변화를 확인하세요

코드 설명

소스 코드의 주석 라인에 있는 줄별 설명을 읽으세요!

동영상

비디오 제작은 시간이 많이 걸리는 작업입니다. 비디오 튜토리얼이 학습에 도움이 되었다면, YouTube 채널 을 구독하여 알려 주시기 바랍니다. 비디오에 대한 높은 수요가 있다면, 비디오를 만들기 위해 노력하겠습니다.

※ OUR MESSAGES

  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!