IT/YOLO

[8] 아두이노를 활용한 부저 알람

주니- 2018. 6. 25. 15:10

데이터 학습을 통해 싸우는 장면을 동영상, 웹캠을 통해 확인할 수가 있었습니다.

하지만 확인만 될뿐 알려주는 기능은 없었기에 어떻게 활용을 해야하나 생각을 많이 하였습니다.

결과로는 아두이노를 통한 부저 알림과 GPS위치 확인등이 있었습니다.

아두이노 다운로드 과정은 쉽게 찾아 보실 수 있습니다.

아두이노 다운로드

운영체제에 맞게 다운받으시면 됩니다. (특별한 환경설정은 없고 사용하시는 기기에 맞게 설정하셔 사용하시면 됩니다.)

설치가 완료된 후 좌표값과 서버와 통신을 설정하였기 때문에

Bounding Box의 좌표를 서버로 보낸것을 다시 불러와야 했기에 Arduino - Ethernet -  WebClient예제를 활용하였습니다.

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
#include <SPI.h>
#include <Ethernet.h>
 
int speakerpin = 10;
 
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "192.168.0.9";    // 서버의 IP
 
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,0,6); // 아두이노 우노의 IP
 
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
 
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
 
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");
 
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET / HTTP/1.1");
    client.println("Host: 192.168.0.9"); // 데이터 가져올 host
    client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}
 
void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
 
  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    tone(speakerpin, 1000, 1000);
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
 
    // do nothing forevermore:
    while (true);
  }
}

아두이노 우노 Ethernet IP주소는 Arduino - Ethernet -  DhcpAddressPrinter예제를 활용하였습니다.

아두이노 우노의 MAC주소 같은경우 정품은 뒷면에 적혀있다고 들었는데 저는 적혀 있지 않았습니다.

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
#include <SPI.h>
#include <Ethernet.h>
 
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};
 
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
 
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  // this check is only needed on the Leonardo:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
 
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for (;;)
      ;
  }
  // print your local IP address:
  printIPAddress();
}
 
void loop() {
 
  switch (Ethernet.maintain())
  {
    case 1:
      //renewed fail
      Serial.println("Error: renewed fail");
      break;
 
    case 2:
      //renewed success
      Serial.println("Renewed success");
 
      //print your local IP address:
      printIPAddress();
      break;
 
    case 3:
      //rebind fail
      Serial.println("Error: rebind fail");
      break;
 
    case 4:
      //rebind success
      Serial.println("Rebind success");
 
      //print your local IP address:
      printIPAddress();
      break;
 
    default:
      //nothing happened
      break;
 
  }
}
 
void printIPAddress()
{
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print(".");
  }
 
  Serial.println();
}

아두이노 Ethernet IP주소 결과

YOLO - 서버 좌표값 읽어온 결과