Laser Tripwire Bugs

Hi, I am having problems with my laser tripwire activated lamp project I am making. I am trying to use an Uno board to make a counter and lamp that is activated by 2 lasers, and I am on a serious deadline for it. I had it mostly working until I added the counter, which is a 4 digit seven segment display, common cathode. I needed to control the display through a shift register to minimize needed pins, and I have this mostly working, except it keeps making random characters in digits I am not displaying. Also, after I added the display, my tripwire stopped working, and I traced the error to line 164 in the code uploaded below. In that line it changes a Boolean from either 0 or 1 to somewhere between 70 and 250 without me even accessing the variable. Please help me quickly because I only have a few more days to work out these bugs before I need to start making the project in a permanent enclosure. I can maybe post an eagle schematic if needed, but I have not used eagle yet and the wiring for this project is quite complicated.

unsigned short laserOuterLevel;
unsigned short ambiantOuterLevel;
int laserOuterPin = 13;
int laserOuterSensorPin = 0;
static int THRESHHOLD = 70;
static int PHOTOCHANGEDELAY = 10;
int callibrateSwitch = 12;
bool isLaserAlligned = false;
unsigned long totalPeople = 0000;
unsigned short peopleInRoom = 0;
int relayPin = 2;
int callibratedLedPin = 10;
bool callibrating = false;
bool alreadyTripped;
bool relayOn = false;
int laserInnerPin = 11;
int laserInnerSensorPin = 1;
int laserInnerLevel;
int ambiantInnerLevel;
bool innerTrippedRecently = false;
bool outerTrippedRecently = false;
unsigned int innerLastTripped = 0;
unsigned int outerLastTripped = 0;
static int CROSSINGTIME = 400;
bool justEntered = false;
int peopleNumberArray[3] = {}; 
int binaryDigits[] = {B00111111, B00000110, B01011011, B01001111, B01100110, B01101101, B01111101, B00000111, B01111111, B01101111};
int latchPin = 9;
int clockPin = 8;
int dataPin = 7;
int digitPins[] = {6, 5, 4, 3};

void setup() {
  pinMode(laserOuterSensorPin, INPUT);
  pinMode(laserOuterPin, OUTPUT);
  pinMode(callibrateSwitch, INPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(callibratedLedPin, OUTPUT);
  pinMode(laserInnerSensorPin, INPUT);
  pinMode(laserInnerPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  Serial.begin(9600);

  for(int i = 0; i <= 4; i++){
    pinMode(digitPins[i], OUTPUT);
  }
  
  digitalWrite(relayPin, HIGH);
  callibrate();
}

void loop() {
  ledDisplay();
  checkSwitches();
  if(isLaserAlligned && callibrating == false){
    laserWireTest();
  }
}

void callibrate(){
  digitalWrite(laserOuterPin, LOW);
  delay(PHOTOCHANGEDELAY);
  ambiantOuterLevel = analogRead(laserOuterSensorPin);
  digitalWrite(laserOuterPin, HIGH);
  delay(PHOTOCHANGEDELAY);
  laserOuterLevel = analogRead(laserOuterSensorPin);

  digitalWrite(laserInnerPin, LOW);
  delay(PHOTOCHANGEDELAY);
  ambiantInnerLevel = analogRead(laserInnerSensorPin);
  digitalWrite(laserInnerPin, HIGH);
  delay(PHOTOCHANGEDELAY);
  laserInnerLevel = analogRead(laserInnerSensorPin);
  
  if(((laserOuterLevel <= ambiantOuterLevel) || ((laserOuterLevel > ambiantOuterLevel ) || ((laserInnerLevel <= THRESHHOLD + ambiantInnerLevel))) && (laserInnerLevel <= ambiantInnerLevel) || ((laserInnerLevel > ambiantInnerLevel ) && (laserInnerLevel <= THRESHHOLD + ambiantInnerLevel)))){ //ugly, but checks for laser allignment. Statment here says the laser is not alligned.
    isLaserAlligned = false;
    digitalWrite(callibratedLedPin, LOW);
  } else {
    isLaserAlligned = true;
    digitalWrite(callibratedLedPin, HIGH);
  }
}

void checkSwitches() {
  if(digitalRead(callibrateSwitch) == LOW){
    callibrating = true;
    callibrate();
  } else if(digitalRead(callibrateSwitch) == HIGH) {
    callibrating = false;
  }
}

void laserWireTest() { // SORRY FOR THE MESS HERE! Really hard to split up.
  if ((analogRead(laserOuterSensorPin) <= ambiantOuterLevel) || ((analogRead(laserOuterSensorPin) > ambiantOuterLevel) && (analogRead(laserOuterSensorPin) <= THRESHHOLD + ambiantOuterLevel))){
      Serial.println("Just entered: " + (String)justEntered);
      if(justEntered == false){
        outerTrippedRecently = true;
        outerLastTripped = millis();
      }
  }else if(analogRead(laserOuterSensorPin) >= laserOuterLevel - THRESHHOLD){
        if(CROSSINGTIME <= millis() - outerLastTripped){
          outerTrippedRecently = false;
          justEntered = false;
      }
  }
    if(analogRead(laserInnerSensorPin) >= laserInnerLevel - THRESHHOLD) {
        if(CROSSINGTIME <= millis() - innerLastTripped){
          innerTrippedRecently = false;
          justEntered = false;
      }
    }else if((analogRead(laserInnerSensorPin) <= ambiantInnerLevel) || ((analogRead(laserInnerSensorPin) > ambiantInnerLevel) && (analogRead(laserInnerSensorPin) <= THRESHHOLD + ambiantInnerLevel))){
      if(justEntered == false){
        innerTrippedRecently = true;
        innerLastTripped = millis();
      }
    }
  lasersHandler();
}

void lasersHandler() {
  
  if(innerTrippedRecently && outerTrippedRecently) {
    if(innerLastTripped > outerLastTripped) {
      peopleInRoom ++;
      totalPeople ++;
      innerTrippedRecently = false;
      outerTrippedRecently = false;
      justEntered = true;
    } else if(outerLastTripped > innerLastTripped) {
      if(peopleInRoom != 0){
        peopleInRoom --;
        innerTrippedRecently = false;
        outerTrippedRecently = false;
        justEntered = true;
      }
    }
  }
  
  
  if(peopleInRoom == 0) {
      digitalWrite(relayPin, HIGH);
    } else if(peopleInRoom > 0) {
      digitalWrite(relayPin, LOW);
  }
}


void ledDisplay() {
  makeNumArray(totalPeople);
  shiftOutDigits();
}



void makeNumArray(int number) {
  String numberString = (String)number;
  char numberChars[5];
  numberString.toCharArray(numberChars, 5);
  
  for(int i = 3; 0 <= i; i--) {
   peopleNumberArray[i] = numberChars[i] - '0';
  }
}



void shiftOutDigits() {
  for(int i = 0; i <= 3; i++) {
    int numToShow = peopleNumberArray[i];
    int binaryToShow = binaryDigits[numToShow];

   digitalWrite(digitPins[i], LOW);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, binaryToShow);
    digitalWrite(latchPin, HIGH);
    digitalWrite(digitPins[i], HIGH);
  }
}

Please just post the code in code tags, so that those of us on mobile devices can see it easily.

From your description, it sounds like an out of bounds array access.

THANK YOU SO MUCH! I was a little confused with array sizes VS array indexes, coming from java, where arrays are very different. I still have the floating numbers on my display, but my completely unresponsive Boolean and tripwire are fixed!

for(int i = 0; i <= 4; i++){
    pinMode(digitPins[i], OUTPUT);
  }

Not good.

for(int i = 0; i < 4; i++){
    pinMode(digitPins[i], OUTPUT);
  }

Thank you again. I completely overlooked this. It didn't solve any problems that I know of but it probably did something.

Slightly updated code:

unsigned short laserOuterLevel;
unsigned short ambiantOuterLevel;
int laserOuterPin = 13;
int laserOuterSensorPin = 0;
static int THRESHHOLD = 70;
static int PHOTOCHANGEDELAY = 10;
int callibrateSwitch = 12;
bool isLaserAlligned = false;
unsigned long totalPeople = 0000;
unsigned short peopleInRoom = 0;
int relayPin = 2;
int callibratedLedPin = 10;
bool callibrating = false;
bool alreadyTripped;
bool relayOn = false;
int laserInnerPin = 11;
int laserInnerSensorPin = 1;
int laserInnerLevel;
int ambiantInnerLevel;
bool innerTrippedRecently = false;
bool outerTrippedRecently = false;
unsigned long innerLastTripped = 0;
unsigned long outerLastTripped = 0;
static int CROSSINGTIME = 400;
bool justEntered = false;
int peopleNumberArray[4] = {}; 
int binaryDigits[] = {B00111111, B00000110, B01011011, B01001111, B01100110, B01101101, B01111101, B00000111, B01111111, B01101111};
int latchPin = 9;
int clockPin = 8;
int dataPin = 7;
int digitPins[] = {6, 5, 4, 3};

void setup() {
  pinMode(laserOuterSensorPin, INPUT);
  pinMode(laserOuterPin, OUTPUT);
  pinMode(callibrateSwitch, INPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(callibratedLedPin, OUTPUT);
  pinMode(laserInnerSensorPin, INPUT);
  pinMode(laserInnerPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  Serial.begin(9600);

  for(int i = 0; i < 4; i++){
    pinMode(digitPins[i], OUTPUT);
  }
  
  digitalWrite(relayPin, HIGH);
  callibrate();
}

void loop() {
  ledDisplay();
  checkSwitches();
  if(isLaserAlligned && callibrating == false){
    laserWireTest();
  }
}

void callibrate(){
  digitalWrite(laserOuterPin, LOW);
  delay(PHOTOCHANGEDELAY);
  ambiantOuterLevel = analogRead(laserOuterSensorPin);
  digitalWrite(laserOuterPin, HIGH);
  delay(PHOTOCHANGEDELAY);
  laserOuterLevel = analogRead(laserOuterSensorPin);

  digitalWrite(laserInnerPin, LOW);
  delay(PHOTOCHANGEDELAY);
  ambiantInnerLevel = analogRead(laserInnerSensorPin);
  digitalWrite(laserInnerPin, HIGH);
  delay(PHOTOCHANGEDELAY);
  laserInnerLevel = analogRead(laserInnerSensorPin);
  
  if(((laserOuterLevel <= ambiantOuterLevel) || ((laserOuterLevel > ambiantOuterLevel ) || ((laserInnerLevel <= THRESHHOLD + ambiantInnerLevel))) && (laserInnerLevel <= ambiantInnerLevel) || ((laserInnerLevel > ambiantInnerLevel ) && (laserInnerLevel <= THRESHHOLD + ambiantInnerLevel)))){ //ugly, but checks for laser allignment. Statment here says the laser is not alligned.
    isLaserAlligned = false;
    digitalWrite(callibratedLedPin, LOW);
  } else {
    isLaserAlligned = true;
    digitalWrite(callibratedLedPin, HIGH);
  }
}

void checkSwitches() {
  if(digitalRead(callibrateSwitch) == LOW){
    callibrating = true;
    callibrate();
  } else if(digitalRead(callibrateSwitch) == HIGH) {
    callibrating = false;
  }
}

void laserWireTest() { // SORRY FOR THE MESS HERE! Really hard to split up.
  if ((analogRead(laserOuterSensorPin) <= ambiantOuterLevel) || ((analogRead(laserOuterSensorPin) > ambiantOuterLevel) && (analogRead(laserOuterSensorPin) <= THRESHHOLD + ambiantOuterLevel))){
      Serial.println("Just entered: " + (String)justEntered);
      if(justEntered == false){
        outerTrippedRecently = true;
        outerLastTripped = millis();
      }
  }else if(analogRead(laserOuterSensorPin) >= laserOuterLevel - THRESHHOLD){
        if(CROSSINGTIME <= millis() - outerLastTripped){
          outerTrippedRecently = false;
          justEntered = false;
      }
  }
    if(analogRead(laserInnerSensorPin) >= laserInnerLevel - THRESHHOLD) {
        if(CROSSINGTIME <= millis() - innerLastTripped){
          innerTrippedRecently = false;
          justEntered = false;
      }
    }else if((analogRead(laserInnerSensorPin) <= ambiantInnerLevel) || ((analogRead(laserInnerSensorPin) > ambiantInnerLevel) && (analogRead(laserInnerSensorPin) <= THRESHHOLD + ambiantInnerLevel))){
      if(justEntered == false){
        innerTrippedRecently = true;
        innerLastTripped = millis();
      }
    }
  lasersHandler();
}

void lasersHandler() {
  
  if(innerTrippedRecently && outerTrippedRecently) {
    if(innerLastTripped > outerLastTripped) {
      peopleInRoom ++;
      totalPeople ++;
      innerTrippedRecently = false;
      outerTrippedRecently = false;
      justEntered = true;
    } else if(outerLastTripped > innerLastTripped) {
      if(peopleInRoom != 0){
        peopleInRoom --;
        innerTrippedRecently = false;
        outerTrippedRecently = false;
        justEntered = true;
      }
    }
  }
  
  
  if(peopleInRoom == 0) {
      digitalWrite(relayPin, HIGH);
    } else if(peopleInRoom > 0) {
      digitalWrite(relayPin, LOW);
  }
}


void ledDisplay() {
  makeNumArray(totalPeople);
  shiftOutDigits();
}



void makeNumArray(int number) {
  String numberString = (String)number;
  char numberChars[5];
  numberString.toCharArray(numberChars, 5);
  
  for(int i = 3; 0 <= i; i--) {
   peopleNumberArray[i] = numberChars[i] - '0';
  }
}



void shiftOutDigits() {
  for(int i = 0; i <= 3; i++) {
    int numToShow = peopleNumberArray[i];
    int binaryToShow = binaryDigits[numToShow];

   digitalWrite(digitPins[i], LOW);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, binaryToShow);
    digitalWrite(latchPin, HIGH);
    digitalWrite(digitPins[i], HIGH);
  }
}

Well, I have it mostly working, except for one weird bug: In the thousands digit on the display, where it should be showing a 0, it is showing a 4. Here is my code:

unsigned short laserOuterLevel;
unsigned short ambiantOuterLevel;
int laserOuterPin = 13;
int laserOuterSensorPin = 0;
static int THRESHHOLD = 70;
static int PHOTOCHANGEDELAY = 10;
int callibrateSwitch = 12;
bool isLaserAlligned = false;
unsigned long totalPeople = 0;
unsigned short peopleInRoom = 0;
int relayPin = 2;
int callibratedLedPin = 10;
bool callibrating = false;
bool alreadyTripped;
bool relayOn = false;
int laserInnerPin = 11;
int laserInnerSensorPin = 1;
int laserInnerLevel;
int ambiantInnerLevel;
bool innerTrippedRecently = false;
bool outerTrippedRecently = false;
unsigned long innerLastTripped = 0;
unsigned long outerLastTripped = 0;
static int CROSSINGTIME = 400;
bool justEntered = false;
int peopleNumberArray[4] = {};
int binaryDigits[] = {B00111111, B00000110, B01011011, B01001111, B01100110, B01101101, B01111101, B00000111, B01111111, B01101111, B00000000};
int latchPin = 9;
int clockPin = 8;
int dataPin = 7;
int digitPins[] = {5, 4, 3, 6};

void setup() {
  pinMode(laserOuterSensorPin, INPUT);
  pinMode(laserOuterPin, OUTPUT);
  pinMode(callibrateSwitch, INPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(callibratedLedPin, OUTPUT);
  pinMode(laserInnerSensorPin, INPUT);
  pinMode(laserInnerPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  Serial.begin(9600);

  for (int i = 0; i < 4; i++) {
    pinMode(digitPins[i], OUTPUT);
  }

  digitalWrite(relayPin, HIGH);
  callibrate();
}

void loop() {
  ledDisplay();
  checkSwitches();
  if (isLaserAlligned && callibrating == false) {
    laserWireTest();
  }
}

void callibrate() {
  digitalWrite(laserOuterPin, LOW);
  delay(PHOTOCHANGEDELAY);
  ambiantOuterLevel = analogRead(laserOuterSensorPin);
  digitalWrite(laserOuterPin, HIGH);
  delay(PHOTOCHANGEDELAY);
  laserOuterLevel = analogRead(laserOuterSensorPin);

  digitalWrite(laserInnerPin, LOW);
  delay(PHOTOCHANGEDELAY);
  ambiantInnerLevel = analogRead(laserInnerSensorPin);
  digitalWrite(laserInnerPin, HIGH);
  delay(PHOTOCHANGEDELAY);
  laserInnerLevel = analogRead(laserInnerSensorPin);

  if (((laserOuterLevel <= ambiantOuterLevel) || ((laserOuterLevel > ambiantOuterLevel ) || ((laserInnerLevel <= THRESHHOLD + ambiantInnerLevel))) && (laserInnerLevel <= ambiantInnerLevel) || ((laserInnerLevel > ambiantInnerLevel ) && (laserInnerLevel <= THRESHHOLD + ambiantInnerLevel)))) { //ugly, but checks for laser allignment. Statment here says the laser is not alligned.
    isLaserAlligned = false;
    digitalWrite(callibratedLedPin, LOW);
  } else {
    isLaserAlligned = true;
    digitalWrite(callibratedLedPin, HIGH);
  }
}

void checkSwitches() {
  if (digitalRead(callibrateSwitch) == LOW) {
    callibrating = true;
    callibrate();
  } else if (digitalRead(callibrateSwitch) == HIGH) {
    callibrating = false;
  }
}

void laserWireTest() { // SORRY FOR THE MESS HERE! Really hard to split up.
  if ((analogRead(laserOuterSensorPin) <= ambiantOuterLevel) || ((analogRead(laserOuterSensorPin) > ambiantOuterLevel) && (analogRead(laserOuterSensorPin) <= THRESHHOLD + ambiantOuterLevel))) {
    if (justEntered == false) {
      outerTrippedRecently = true;
      outerLastTripped = millis();
    }
  } else if (analogRead(laserOuterSensorPin) >= laserOuterLevel - THRESHHOLD) {
    if (CROSSINGTIME <= millis() - outerLastTripped) {
      outerTrippedRecently = false;
      justEntered = false;
    }
  }
  if (analogRead(laserInnerSensorPin) >= laserInnerLevel - THRESHHOLD) {
    if (CROSSINGTIME <= millis() - innerLastTripped) {
      innerTrippedRecently = false;
      justEntered = false;
    }
  } else if ((analogRead(laserInnerSensorPin) <= ambiantInnerLevel) || ((analogRead(laserInnerSensorPin) > ambiantInnerLevel) && (analogRead(laserInnerSensorPin) <= THRESHHOLD + ambiantInnerLevel))) {
    if (justEntered == false) {
      innerTrippedRecently = true;
      innerLastTripped = millis();
    }
  }
  lasersHandler();
}

void lasersHandler() {

  if (innerTrippedRecently && outerTrippedRecently) {
    if (innerLastTripped > outerLastTripped) {
      peopleInRoom ++;
      totalPeople ++;
      innerTrippedRecently = false;
      outerTrippedRecently = false;
      justEntered = true;
    } else if (outerLastTripped > innerLastTripped) {
      if (peopleInRoom != 0) {
        peopleInRoom --;
        innerTrippedRecently = false;
        outerTrippedRecently = false;
        justEntered = true;
      }
    }
  }


  if (peopleInRoom == 0) {
    digitalWrite(relayPin, HIGH);
  } else if (peopleInRoom > 0) {
    digitalWrite(relayPin, LOW);
  }
}


void ledDisplay() {
  makeNumArray(totalPeople);
  shiftOutDigits();
}



void makeNumArray(int number) {
  String numberString = (String)number;
  char numberChars[4];
  numberString.toCharArray(numberChars, 4);
  int oppositeNum = 0;
  for (int i = 3; 0 <= i; i--) {
    peopleNumberArray[i] = numberChars[oppositeNum] - '0';
    oppositeNum ++;
  }
}



void shiftOutDigits() {
  for (int i = 3; i >= 0; i--) {
    int numToShow = peopleNumberArray[i];
    if(numToShow < 0 || numToShow > 9){
      numToShow = 10;
    }
    int binaryToShow = binaryDigits[numToShow];

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, binaryToShow);
    digitalWrite(latchPin, HIGH);
    digitalWrite(digitPins[i], LOW);
    digitalWrite(digitPins[i], HIGH);
  }
}

So, rip out everything except your display routine, and drive that with a simple for loop until you’ve debugged it.
Whilst you’re at it, you could get rid of all the String stuff, and just use arithmetic, to simplify “makeNumArray”

Also, to make your code easier to read and maintain, where you’ve got stuff like

int peopleNumberArray[4] = {};
int binaryDigits[] = {B00111111, B00000110, B01011011, B01001111, B01100110, B01101101, B01111101, B00000111, B01111111, B01101111, B00000000};
int latchPin = 9;
int clockPin = 8;
int dataPin = 7;
int digitPins[] = {5, 4, 3, 6};

You’d be better to separate the constants (and make then constant) from the variables.
Pin numbers don’t need to be as big as “int”, you could make then “const byte”.

Thank you for all your help! I was able to fix it by using what you said plus messing around with my code. My project works perfectly now.

Well, once again, I am having problems. I was finishing the final assembly, my deadline being tomorrow, and when I went to test it, I ran into a bug where when I set the decimal point to high on my display, all my digits went high, and when I set it to low, all my digits went low. Code:

unsigned short laserOuterLevel;
unsigned short ambiantOuterLevel;
bool isLaserAlligned = false;
unsigned long totalPeople = 0;
unsigned short peopleInRoom = 0;
bool callibrating = false;
bool alreadyTripped;
bool relayOn = false;
int laserInnerLevel;
int ambiantInnerLevel;
bool innerTrippedRecently = false;
bool outerTrippedRecently = false;
unsigned long innerLastTripped = 0;
unsigned long outerLastTripped = 0;
int peopleNumberArray[4] = {};
bool justEntered = false;

const byte laserOuterPin = 13;
const byte laserOuterSensorPin = 0;
const byte THRESHHOLD = 70;
const byte PHOTOCHANGEDELAY = 10;
const byte callibrateSwitch = 12;
const byte relayPin = 2;
const byte callibratedLedPin = 10;
const byte laserInnerPin = 11;
const byte laserInnerSensorPin = 1;
byte latchPin = 9;
byte clockPin = 8;
byte dataPin = 7;
byte digitPins[] = {5, 4, 3, 6};
const byte binaryDigits[] = {B00111111, B00000110, B01011011, B01001111, B01100110, B01101101, B01111101, B00000111, B01111111, B01101111, B00000000};
const int CROSSINGTIME = 400;



void setup() {
  pinMode(laserOuterSensorPin, INPUT);
  pinMode(laserOuterPin, OUTPUT);
  pinMode(callibrateSwitch, INPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(callibratedLedPin, OUTPUT);
  pinMode(laserInnerSensorPin, INPUT);
  pinMode(laserInnerPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  Serial.begin(9600);

  for (int i = 0; i < 4; i++) {
    pinMode(digitPins[i], OUTPUT);
  }

  digitalWrite(relayPin, HIGH);
  digitalWrite(digitPins[3], HIGH);
  digitalWrite(digitPins[2], HIGH);
  digitalWrite(digitPins[1], HIGH);
  callibrate();
}

void loop() {
  ledDisplay();
  checkSwitches();
  if (isLaserAlligned && callibrating == false) {
    laserWireTest();
  }
}

void callibrate() {
  digitalWrite(laserOuterPin, LOW);
  delay(PHOTOCHANGEDELAY);
  ambiantOuterLevel = analogRead(laserOuterSensorPin);
  digitalWrite(laserOuterPin, HIGH);
  delay(PHOTOCHANGEDELAY);
  laserOuterLevel = analogRead(laserOuterSensorPin);

  digitalWrite(laserInnerPin, LOW);
  delay(PHOTOCHANGEDELAY);
  ambiantInnerLevel = analogRead(laserInnerSensorPin);
  digitalWrite(laserInnerPin, HIGH);
  delay(PHOTOCHANGEDELAY);
  laserInnerLevel = analogRead(laserInnerSensorPin);

  if (((laserOuterLevel <= ambiantOuterLevel) || ((laserOuterLevel > ambiantOuterLevel ) || ((laserInnerLevel <= THRESHHOLD + ambiantInnerLevel))) && (laserInnerLevel <= ambiantInnerLevel) || ((laserInnerLevel > ambiantInnerLevel ) && (laserInnerLevel <= THRESHHOLD + ambiantInnerLevel)))) { //ugly, but checks for laser allignment. Statment here says the laser is not alligned.
    isLaserAlligned = false;
    digitalWrite(callibratedLedPin, LOW);
  } else {
    isLaserAlligned = true;
    digitalWrite(callibratedLedPin, HIGH);
  }
}

void checkSwitches() {
  if (digitalRead(callibrateSwitch) == LOW) {
    callibrating = true;
    callibrate();
  } else if (digitalRead(callibrateSwitch) == HIGH) {
    callibrating = false;
  }
}

void laserWireTest() { // SORRY FOR THE MESS HERE! Really hard to split up.
  if ((analogRead(laserOuterSensorPin) <= ambiantOuterLevel) || ((analogRead(laserOuterSensorPin) > ambiantOuterLevel) && (analogRead(laserOuterSensorPin) <= THRESHHOLD + ambiantOuterLevel))) {
    if (justEntered == false) {
      outerTrippedRecently = true;
      outerLastTripped = millis();
    }
  } else if (analogRead(laserOuterSensorPin) >= laserOuterLevel - THRESHHOLD) {
    if (CROSSINGTIME <= millis() - outerLastTripped) {
      outerTrippedRecently = false;
      justEntered = false;
    }
  }
  if (analogRead(laserInnerSensorPin) >= laserInnerLevel - THRESHHOLD) {
    if (CROSSINGTIME <= millis() - innerLastTripped) {
      innerTrippedRecently = false;
      justEntered = false;
    }
  } else if ((analogRead(laserInnerSensorPin) <= ambiantInnerLevel) || ((analogRead(laserInnerSensorPin) > ambiantInnerLevel) && (analogRead(laserInnerSensorPin) <= THRESHHOLD + ambiantInnerLevel))) {
    if (justEntered == false) {
      innerTrippedRecently = true;
      innerLastTripped = millis();
    }
  }
  lasersHandler();
}

void lasersHandler() {

  if (innerTrippedRecently && outerTrippedRecently) {
    if (innerLastTripped > outerLastTripped) {
      peopleInRoom ++;
      totalPeople ++;
      innerTrippedRecently = false;
      outerTrippedRecently = false;
      justEntered = true;
    } else if (outerLastTripped > innerLastTripped) {
      if (peopleInRoom != 0) {
        peopleInRoom --;
        innerTrippedRecently = false;
        outerTrippedRecently = false;
        justEntered = true;
      }
    }
  }


  if (peopleInRoom == 0) {
    digitalWrite(relayPin, HIGH);
  } else if (peopleInRoom > 0) {
    digitalWrite(relayPin, LOW);
  }
}


void ledDisplay() {
  makeNumArray(totalPeople);
  shiftOutDigits();
}



void makeNumArray(int number) {
  String numberString = (String)number;
  char numberChars[3];
  numberString.toCharArray(numberChars, 4);
  for (int i = 3; 0 <= i; i--) {
    peopleNumberArray[i] = numberChars[i] - '0';
  }

   //this handles a spontanious bug that i couldn't fix. Kinda primative, but it works:
   if(totalPeople < 10){
     for(int i = 1; i < 4; i++){
       peopleNumberArray[i] = 10;
      }
   }
}



void shiftOutDigits() {
  /*for (int i = 3; i >= 0; i--) {
    int numToShow = peopleNumberArray[i];
    if(numToShow < 0 || numToShow > 9){
      numToShow = 10;
    }
    
    int binaryToShow = binaryDigits[numToShow];
    Serial.println(binaryToShow, BIN);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, binaryToShow);
    digitalWrite(latchPin, HIGH);
    digitalWrite(digitPins[i], LOW);
    digitalWrite(digitPins[i], HIGH);
  }*/
    int binaryToShow = binaryDigits[0];

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, B0000000);
    digitalWrite(latchPin, HIGH);
    digitalWrite(digitPins[0], LOW);
    digitalWrite(digitPins[0], HIGH);

}

Eagle Schematic below

laserTripwire.pdf (28.8 KB)

If I remove the large comment (as you could/should have done before posting), shiftOutDigits looks like this

void shiftOutDigits() {
    int binaryToShow = binaryDigits[0];

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, B0000000);
    digitalWrite(latchPin, HIGH);
    digitalWrite(digitPins[0], LOW);
    digitalWrite(digitPins[0], HIGH);

}

Is that what you intended?

Yes, I was using it to test out the parts to see what was wrong. However, the project did not get completed in time for what I needed to enter it in, so I am going to try again next year. Thanks for all your help, though!