산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Manufacturing Technology >> 제조공정

아두이노 MKR1000 WiFi 픽투라이트 시스템 - 프로젝트 2

부품 및 소모품

부품 수량
아두이노 MKR1000 1
LED (일반) 2
점퍼 와이어 1
스파크펀 푸시버튼 스위치 12mm 1
저항 10kΩ 1
저항 330Ω 4
브레드보드 1
USB-A to Micro-USB 케이블 1
범용 NPN 트랜지스터 1

프로젝트 개요

창고나 생산 현장에서 작업자가 부품을 올바른 순서로 피킹(Picking)할 수 있도록 안내하는 WiFi 기반 픽투라이트(Pick-to-Light) 시스템입니다. 시리얼 통신 방식이었던 1차 프로젝트와 달리 MKR1000의 내장 WiFi와 UDP 프로토콜을 사용하여 무선으로 동작합니다. 시퀀스 번호를 포함하여 작업 진행 상황을 추적하고 오류 발생 시 정확한 재시작 지점을 알 수 있습니다.

시스템 구성

PC 측 (Python 스크립트)

아두이노 측 (MKR1000)

설치 및 실행 단계

  1. Python 3.6+ 설치
  2. 아두이노 IDE 설치 (WiFi101 라이브러리 필요)
  3. 작업 디렉토리에 sequence1.txt 파일 생성 (예: 0001,Bin1 형식)
  4. 아두이노 시크릿 탭에 WiFi SSID/비밀번호 입력
  5. 아두이노 스케치 업로드
  6. 프리칭 다이어그램대로 회로 구성 (트랜지스터로 LED 구동)
  7. Python 스크립트 실행 (F5)

소스 코드

아두이노 스케치

#include <SPI.h>
#include <WiFi101.h>
#include <WiFiUdp.h>

const int OKbutton = 2;
const int Bin1 = 8;
const int Bin2 = 9;
String mydata = "";
String myseq = "";
int buttonPress = 0;
int status = WL_IDLE_STATUS;
#include "arduino_secrets.h"
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
int keyIndex = 0;
unsigned int localPort = 2390;
char packetBuffer[255];
char ReplyBuffer[5] = "";
String mystring;
WiFiUDP Udp;

void setup() {
  Serial.begin(9600);
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while (true);
  }
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWiFiStatus();
  Udp.begin(localPort);
}

void loop() {
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    IPAddress remoteIp = Udp.remoteIP();
    Serial.print(remoteIp);
    Serial.print(", port ");
    Serial.println(Udp.remotePort());
    
    int len = Udp.read(packetBuffer, 255);
    if (len > 0) packetBuffer[len] = 0;
    Serial.println("Contents:");
    Serial.println(packetBuffer);
    
    String mystring(packetBuffer);
    mydata = mystring.substring(4);
    myseq = mystring.substring(0, 4);
    Serial.println(mydata);
    Serial.println(myseq);
    
    while (mydata != "") {
      if (mydata == "Bin1") {
        digitalWrite(Bin1, HIGH);
        digitalWrite(Bin2, LOW);
        while (buttonPress != HIGH) {
          buttonPress = digitalRead(OKbutton);
          mydata = "";
        }
        digitalWrite(Bin1, LOW);
        Serial.println("Picked");
        buttonPress = 0;
        delay(1000);
      }
      if (mydata == "Bin2") {
        digitalWrite(Bin2, HIGH);
        digitalWrite(Bin1, LOW);
        while (buttonPress != HIGH) {
          buttonPress = digitalRead(OKbutton);
          mydata = "";
        }
        digitalWrite(Bin2, LOW);
        Serial.println("Picked");
        buttonPress = 0;
        delay(1000);
      }
    }
    
    myseq.toCharArray(ReplyBuffer, 5);
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
    Serial.println(ReplyBuffer);
  }
}

void printWiFiStatus() {
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Python 스크립트

import csv
import socket
import time
import sys

UDP_IP = "192.168.1.119"
UDP_PORT = 2390

print("UDP target IP:", UDP_IP)
print("UDP target port:", UDP_PORT)

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
time.sleep(5)

with open('sequence1.txt') as csvDataFile:
    csvReader = csv.reader(csvDataFile)
    for row in csvReader:
        myseq = row[0]
        mystate = row[1]
        myrow = row[0] + row[1]
        print("Current sequence being picked", myseq, "from", mystate)
        sock.sendto(bytes(myrow, "utf-8"), (UDP_IP, UDP_PORT))
        
        data = ""
        while data == "":
            (data, addr) = sock.recvfrom(1024)
            mytest = data.decode("utf-8")
            print("picked =", mytest)
            if mytest != myseq:
                print("there is a sequence fault at sequence", mytest)
                sys.exit()

시퀀스 파일 예시 (sequence1.txt)

0001,Bin1
0002,Bin2
0003,Bin1
0004,Bin2
0005,Bin1
0006,Bin2
0007,Bin1
0008,Bin2
0009,Bin1
0010,Bin2
0011,Bin1
0012,Bin2
0013,Bin1

회로도 주의사항

MKR1000의 WiFi 활성화 시 핀 8, 9 전압 강하 문제로 LED가 점등되지 않을 수 있습니다. 이를 해결하기 위해 NPN 트랜지스터를 사용하여 LED를 구동하도록 회로를 구성했습니다. 배선 시 저항값과 트랜지스터 정격 확인 필수, 5V 쇼트 주의.

제조공정

  1. 가스 랜턴: 진화, 디자인, 현대 제조 공정
  2. 레이저 포인터: 설계, 제조, 안전성 개요
  3. 손전등: 탄생부터 현대 혁신까지
  4. 만화경: 브루스터의 과학에서 현대 디자인까지
  5. 반도체 레이저: 현대 기술을 위한 정밀 광원
  6. 사진술의 예술과 과학: 다게레오타입에서 현대 필름까지
  7. 교통신호: 공학, 역사, 미래 혁신
  8. 불에서 필라멘트로: 현대 전구 진화와 생산
  9. 아두이노로 간단한 장애물 센서 만들기 - IR LED & 포토다이오드 튜토리얼
  10. DIY 기타 스피드 픽 & 스톰프 페달 - 3D 프린팅 모터식 픽 직접 만들기