본문 바로가기

디지털/코딩

[아두이노01] LED 불 켜기 와 끄기

반응형

안녕하세요.

오늘은 아두이노를 이용해서 LED 불 켜기 와 끄기를 해보려고 합니다.

먼저 필요한 준비물은 

아두이노와 LED, 그리고 저항인데요.

저항은 220, 330옴 모두 가능해요.

 

1. LED 깜박이기

LED를 가장 쉽게 깜박이는 방법은 아두이노 IDE에서 기존 예제를 이용해 보는 것이 가장 쉽습니다.

처음 학생들에게 접근할 때는 이렇게 하는 것을 권장합니다.

자체 예제에서 Blink 파일을 열어 보시면 되는데요.

 

/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

이것은 기존 소스인데요.

/*

// 

모두 주석입니다.

주석을 제거해 보겠습니다.

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);                    
  digitalWrite(LED_BUILTIN, LOW); 
  delay(1000);                    
}

남는 코드가 이렇게 되는데요.

파일 이름을 다른 이름으로 저장해 보겠습니다.

LED01 이름으로 저장한 후에 컴파일을 해보겠습니다.

컴파일 한 후에는 아두이노에 업로드 하려고 하는데요.

아두이노 보드를 컴퓨터에 연결해야 합니다.

연결한 후에 업로드를 하면 위 L자에서 불이 깜박이는 것을 확인 할 수 있는데요.

아두이노 첫번째 시간은 이렇게 아두이노를 이용해서 깜박이게 하는 것으로 첫 번째 수업을 마치도록 하겠습니다.

 

수고하셨습니다.

 

작성일 : 2021.11.15

반응형