1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#define BTN_PIN         5               // 버튼 연결 Pin 번호
#define BTN_LED_PIN     4               // 버튼 LED 연결 Pin 번호
#define DIODE_LED_PIN   3               // 다이오드 LED 연결 Pin 번호
 
bool enable = false;
 
void setup() {
  Serial.begin(115200);
 
  pinMode(BTN_PIN, INPUT);              // 버튼 Pin을 입력모드로 설정
  pinMode(BTN_LED_PIN, OUTPUT);         // 버튼 LED Pin을 출력모드로 설정
  pinMode(DIODE_LED_PIN, OUTPUT);       // 다이오드 LED Pin을 출력모드로 설정
}
 
void loop() {
  if(digitalRead(BTN_PIN) == HIGH){                   // 버튼 클릭 상태일 때,
      while(digitalRead(BTN_PIN) == HIGH){                // 버튼이 클릭이 종료될 때까지 대기.
        delay(100);
      }
      enable = !enable;                               // 다이오드 LED 상태 전환 
  }
 
  digitalWrite(DIODE_LED_PIN, enable);                // 다이오드 LED 상태 설정  
  digitalWrite(BTN_LED_PIN, !enable);                 // 다이오드 LED 상태와 반대로 버튼 LED 상태 제어
  
  delay(50);
}
cs

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#define CDS_PIN   A0                          // 조도 센서 아닐로그 Pin 번호
#define LED_PIN   3
 
float cdsValue;                              
 
void setup() {
  pinMode(LED_PIN, OUTPUT);       // LED 핀 모드 설정
}
 
void loop() {
  float cdsValue = analogRead(CDS_PIN);                 // 조도 센서 저항값(세기) 읽기
  int ledLux = map(cdsValue, 010232550);          // 조도 세기를 기준으로 LED 출력 세기(0~255) 환산
 
  analogWrite(LED_PIN, ledLux);                         // LED PWM 제어
  
  delay(1000);
}
cs

 

 

<주의> 아두이노 업로드를 위해 IDE에 <DHT.h>와 <LiquidCrystal_I2C.h> 라이브러리가 추가되어 있어야합니다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <DHT.h>                                  // DHT 라이브러리 추가
#include <LiquidCrystal_I2C.h>                    // I2C LCD 라이브러리 추가
 
#define DHT_PIN   2                               // 온습도 센서 연결 디지털 핀 번호
#define DHT_TYPE  DHT22                           // DHT 센서 종류
#define LCD_ADDR  0x3F                            // I2C LCD 주소 0x3F or 0x27
 
DHT dht(DHT_PIN, DHT_TYPE);                       // DHT 객체 선언
LiquidCrystal_I2C lcd(LCD_ADDR, 162);           // 16 * 2 LCD 객체 선언
 
void setup() {
  dht.begin();                                // DHT 센서 활성화
  lcd.init();                                 // LCD 초기화
  lcd.backlight();                            // LCD 백라이트 ON
}
 
void loop() {
  float humidity = dht.readHumidity();            // 습도값 읽기 & 저장
  float temperature = dht.readTemperature();      // 온도값 읽기 & 저장
 
  lcd.setCursor(00);        // x, y 커서 좌표 설정
  lcd.print("Temp:");         // 설정 좌표에 데이터 출력
  lcd.setCursor(01);
  lcd.print("Humi:");
 
  lcd.setCursor(60);        
  lcd.print(temperature);
  lcd.setCursor(61);
  lcd.print(humidity);
 
  delay(2000);
}
cs

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#define POWER_PIN  3    // 전원 모듈 연결 Pin 번호
 
int pwm = 0;            // PWM 제어 값 (TR 및 Mosfet 전원 모듈에서만 사용 가능)
 
void setup() {
  Serial.begin(115200);
 
  pinMode(POWER_PIN, OUTPUT);
}
 
void loop() {
  digitalWrite(POWER_PIN, HIGH);          // 전원 On
  delay(3000);
  digitalWrite(POWER_PIN, LOW);           // 전원 Off
  delay(3000);
 
  //  PWM 제어
  while (pwm > 250) {                  // PWM 값을 최대치(255)까지 증가
    analogWrite(POWER_PIN, pwm);
    pwm += 50;
    delay(3000);
  }
  while (pwm < 0) {                    // PWM 값을 최소치(0)까지 감소
    analogWrite(POWER_PIN, pwm);
    pwm -= 50;
    delay(3000);
  }
}
cs

 

 

 

 

 

 

[피지스 아두이노 IoT] 전원 제어 모듈 : 피지스 메이커 팩토리

[피지스 메이커 팩토리] 재미있고 독특한 아두이노 DIY 콘텐츠 메이커팩토리

smartstore.naver.com

 

 

+ Recent posts