아두이노 선풍기 만들기

아두이노 선풍기 만들기

아두이노에 프로그래밍을 하기위해 아두이노 ide를 인스톨 해야 된다.

arduino ide download 여기에서 다운로드를 받아서 인스톨을 먼저해야된다.

호환보드는 ch340 driver를 인스톨해야 되는데 링크에서 인스톨 먼저 진행 하면 되겠다.

그다음에 아두이노 ide가 실행 되면 아래의 코드를 붙혀 넣고 업로드를 진행하면 된다. ^^

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

#include <Servo.h>

Servo myservo;
int dcmPin1 = 3;
int dcmPin2 = 11;
int servoPin = 13;

int POW_SW_Pin = 8;
int PAN_SW_Pin = 7;
int LV1_SW_Pin = 6;
int LV2_SW_Pin = 5;
int LV3_SW_Pin = 4;

int pos = 90;
int Dir_Servo = 0;
unsigned char dcmPower = 50;
int PAN_OnOff = 0;
int POW_OnOff = 0;
int POW_LEVEL = 1;

int Key_Data[10] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
int Key_Data_Before[10] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};

void setup() {

myservo.attach(servoPin);
myservo.write(90);

pinMode(POW_SW_Pin, INPUT);
pinMode(PAN_SW_Pin, INPUT);
pinMode(LV1_SW_Pin, INPUT);
pinMode(LV2_SW_Pin, INPUT);
pinMode(LV3_SW_Pin, INPUT);

pinMode(dcmPin1, OUTPUT);
pinMode(dcmPin2, OUTPUT);
digitalWrite(dcmPin1, LOW);
digitalWrite(dcmPin2, LOW);
analogWrite(dcmPin1, 0);
analogWrite(dcmPin2, 0);
delay(1000);
}

void loop() {
readKey();
if (POW_OnOff == HIGH)
{
if (POW_LEVEL == 1 ) analogWrite(dcmPin2, 85);
else if (POW_LEVEL == 2 ) analogWrite(dcmPin2, 175);
else if (POW_LEVEL == 3 ) analogWrite(dcmPin2, 255);
else;
analogWrite(dcmPin1, 0);
PAN_Control();
delay(60);
}
else if (POW_OnOff == LOW)
{
analogWrite(dcmPin1, 0);
analogWrite(dcmPin2, 0);
delay(100);
}
else;
}

void PAN_Control()
{
if (PAN_OnOff == HIGH)
{
if (Dir_Servo == LOW)
{
if (pos < 150)
{
pos++;
myservo.write(pos);
}
else Dir_Servo = HIGH;
}
else
{
if (pos > 30)
{
pos--;
myservo.write(pos);
}
else Dir_Servo = LOW;
}
}
else;
}

void readKey()
{
for (int i = POW_SW_Pin; i >= LV3_SW_Pin; i--)
{
Key_Data[i] = digitalRead(i);
if (Key_Data[i] == LOW && Key_Data[i] != Key_Data_Before[i])
{
Key_Data_Before[i] = Key_Data[i];
if (i == POW_SW_Pin) {
if (POW_OnOff == LOW) POW_OnOff = HIGH;
else POW_OnOff = LOW;
}
else if (i == PAN_SW_Pin) {
if (PAN_OnOff == LOW) PAN_OnOff = HIGH;
else PAN_OnOff = LOW;
}
else if (i == LV1_SW_Pin) POW_LEVEL = 1;
else if (i == LV2_SW_Pin) POW_LEVEL = 2;
else if (i == LV3_SW_Pin) POW_LEVEL = 3;
else;
delay(200);
}
else if (Key_Data[i] == HIGH && Key_Data[i] != Key_Data_Before[i])
{
Key_Data_Before[i] = Key_Data[i];
}
else;
}
}



참조