PAJ
Published © GPL3+

Pick to Light Project 1 Serial

Low cost, easy build pick to light system.

BeginnerFull instructions provided2 hours7,679

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
Initially I used an Uno to get this project started so you can use hat if it all you have.
×1
Jumper wires (generic)
Jumper wires (generic)
×1
LED (generic)
LED (generic)
×2
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
Breadboard (generic)
Breadboard (generic)
×1
Resistor 330 ohm
Resistor 330 ohm
Choose the resistor to suit you LED's
×2
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Resistor 10k ohm
Resistor 10k ohm
×1

Software apps and online services

Arduino Web Editor
Arduino Web Editor

Story

Read more

Schematics

PickToLight

Schematic for UNO wiring connection

PickToLightmkr

Schematic for MKR1000 wiring connection

Code

Arduino Sketch

Arduino
Pick to Light Arduino sketch copy into Arduino IDE or Web editor
const int OKbutton = 2; // set the pin for the okay button/switch
const int Bin1 = 8; // the pin that the LED for bin 1 is attached to
const int Bin2 = 9; // the pin that the LED for bin 2 is attached to
String mydata = " ";  // a variable to read incoming serial data into set to empty string
int buttonPress = 0; // a variable to store state of the button/switch

void setup() {
  // initialize serial communication:
  Serial.begin(9600); //set the baud rate
  // initialize the LED pins as an output:
  pinMode(Bin1, OUTPUT);
  pinMode(Bin2, OUTPUT);
  // initialize the button pin as input
  pinMode(OKbutton, INPUT);


}

void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    mydata = Serial.readString(); //get first line of data from  pc

    while (mydata != " "){ //Test to see if mydata is still empty if it isn't check which bin should be lit up
      if (mydata == "Bin1"){ // start bin 1 routine
        digitalWrite(Bin1, HIGH); // light LED for bin 1 by setting pin high
        digitalWrite(Bin2, LOW);  // set LED for bin 2 off by setting pin low
            while (buttonPress != HIGH) { // wait for button press loop
              buttonPress = digitalRead(OKbutton); //keep checking button
              mydata = " "; //set mydata back to emty string
    }
        digitalWrite(Bin1, LOW);// turn led for bin 1 off
        Serial.println("Picked"); //send message to PC
        buttonPress = 0; //reset button low
      }
      if (mydata == "Bin2"){// start bin 2 routine
        digitalWrite(Bin2, HIGH);// light LED for bin 2 by setting pin high
        digitalWrite(Bin1, LOW); // set LED for bin 1 off by setting pin low
            while (buttonPress != HIGH) { // wait for button press loop
              buttonPress = digitalRead(OKbutton); //keep checking button
              mydata = " "; //set mydata back to emty string
    }
        digitalWrite(Bin2, LOW); // turn led for bin 1 off
        Serial.println("Picked"); //send message to PC
        buttonPress = 0; //reset button low
      }
 
    }

  }
}

Python script

Python
Python script copy into new file opened in IDLE
## load the necessary libraries
import csv
import serial
import time
##Initialise the serial connection
ser = serial.Serial('COM3',9600)
time.sleep(5)
##open csv file and read it in one line at a time
with open('sequence.txt') as csvDataFile:
    csvReader = csv.reader(csvDataFile)
    for row in csvReader: ##for each line do the following
        myseq = row[0] ##read in the sequence number
        mystate = row[1] ##read in the bin number
        print(myseq) ## print sequence number for tracking
        print(mystate)##print bin number for visual checking
        ser.write(mystate.encode('utf-8')) ## write bin to arduino encoding to unicode
        fromuno  = ser.readline().decode('UTF-8') ##confirmation from Arduino decoding back to characters
        print(fromuno) ##print picked message from Arduino

sequence

Plain text
CSV file of the bin sequence save in cwd
1,Bin1
2,Bin2
3,Bin1
4,Bin2
5,Bin1
6,Bin2
7,Bin1
8,Bin2
9,Bin1
10,Bin2
11,Bin1
12,Bin2
13,Bin1

Credits

PAJ
3 projects • 7 followers
Contact

Comments

Please log in or sign up to comment.