아두이노 - 모션 센서 - 릴레이 | Arduino - Motion Sensor - Relay

우리는 어떻게 하는지 배울 것입니다:

릴레이를 전구, LED 스트립, 모터 또는 액추에이터에 연결함으로써... 우리는 모션 센서를 이용하여 전구, LED 스트립, 모터 또는 액추에이터를 제어할 수 있습니다...

준비물

1×Arduino Uno Amazon
1×USB 2.0 cable type A/B 쿠팡 | Amazon
1×HC-SR501 Motion Sensor Amazon
1×Relay Amazon
1×Jumper Wires Amazon
1×(Optional) Solenoid Lock Amazon
1×(Optional) 12V Power Adapter Amazon
1×(Optional) DC Power Jack 쿠팡 | 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
공개: 이 섹션에서 제공된 링크 중 일부는 제휴 링크입니다. 이 링크를 통해 구매한 경우 추가 비용없이 수수료를 받을 수 있습니다. 지원해 주셔서 감사합니다.

릴레이 및 모션 센서에 관하여

만약 여러분이 릴레이와 모션 센서(핀배열, 작동 원리, 프로그래밍 방법 등)에 대해 잘 모른다면, 다음 튜토리얼에서 배워보세요:

선연결

Arduino Motion Sensor Relay 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-relay */ const int MOTION_SENSOR_PIN = 7; // 모션 센서의 OUTPUT 핀에 연결된 Arduino 핀 const int RELAY_PIN = A5; // 릴레이의 IN 핀에 연결된 Arduino 핀 int motionStateCurrent = LOW; // 모션 센서의 핀의 현재 상태 int motionStatePrevious = LOW; // 모션 센서의 핀의 이전 상태 void setup() { Serial.begin(9600); // 시리얼 초기화 pinMode(MOTION_SENSOR_PIN, INPUT); // 아두이노 핀을 입력 모드로 설정 pinMode(RELAY_PIN, OUTPUT); // 아두이노 핀을 출력 모드로 설정 } void loop() { motionStatePrevious = motionStateCurrent; // 이전 상태 저장 motionStateCurrent = digitalRead(MOTION_SENSOR_PIN); // 새로운 상태 읽기 if (motionStatePrevious == LOW && motionStateCurrent == HIGH) { // 핀 상태 변경: LOW -> HIGH Serial.println("Motion detected!"); digitalWrite(RELAY_PIN, HIGH); // 켜기 } else if (motionStatePrevious == HIGH && motionStateCurrent == LOW) { // 핀 상태 변경: HIGH -> LOW Serial.println("Motion stopped!"); digitalWrite(RELAY_PIN, LOW); // 끄기 } }

사용 방법

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

코드 설명

소스 코드의 주석 라인에서 라인별 설명을 읽어보세요!

동영상

비디오 제작은 시간이 많이 걸리는 작업입니다. 비디오 튜토리얼이 학습에 도움이 되었다면, 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!