Arduino Laser Tag Update #3

Hardware Testing and Refinement

Laser Tag Board 15-1-22

One of the issues I encountered with my proposed setup in Update #1 is that the LED segments will periodically dim. This was because I only used one resistor to power all 7 segments (8 including the dot) in parallel. This would work if all LEDs in the display were manufactured the same way. However, it’s more likely that some LEDs draws more current than the others causing some segments to become slightly brighter while the others dim. The better way to connect the LEDs is to have a resistor after each one. I used a 2K Ω resistor after each segment so that the current flowing through each LED remains low.

Electronic Schematic 15-1-22

This hardware configuration worked out a lot better for me. All the LEDs remained at a constant brightness. I also managed to get the IR Sensor an the IR LED working at the same time. My test code for this setup is shown below.

#include <IRremote.h>

#define RECV_PIN 2

#define DIGIT_1 12
#define DIGIT_2 10
#define DIGIT_3 9
#define DIGIT_4 6

#define SEG_A 7
#define SEG_B 11
#define SEG_C 15
#define SEG_D 17
#define SEG_E 18
#define SEG_F 8
#define SEG_G 14
#define SEG_DOT 16

IRrecv irrecv(RECV_PIN);
IRsend irsend;

decode_results results;

int x = 1;

void setup()
{
  irrecv.enableIRIn(); // Start the receiver
  
  Serial.begin(9600);
  
  pinMode(13, OUTPUT);
  
  pinMode(SEG_A, OUTPUT);
  pinMode(SEG_B, OUTPUT);
  pinMode(SEG_C, OUTPUT);
  pinMode(SEG_D, OUTPUT);
  pinMode(SEG_E, OUTPUT);
  pinMode(SEG_F, OUTPUT);
  pinMode(SEG_G, OUTPUT);
  pinMode(SEG_DOT, OUTPUT);
  
  pinMode(DIGIT_1, OUTPUT);
  pinMode(DIGIT_2, OUTPUT);
  pinMode(DIGIT_3, OUTPUT);
  pinMode(DIGIT_4, OUTPUT);
  
  digitalWrite(SEG_A, LOW);
  digitalWrite(SEG_B, LOW);
  digitalWrite(SEG_C, LOW);
  digitalWrite(SEG_D, LOW);
  digitalWrite(SEG_E, LOW);
  digitalWrite(SEG_F, LOW);
  digitalWrite(SEG_G, LOW);
  digitalWrite(SEG_DOT, LOW);
  
  delay(250);
}

void loop() {
  
  digitalWrite(DIGIT_1, HIGH);
  digitalWrite(DIGIT_2, LOW);
  digitalWrite(DIGIT_3, LOW);
  digitalWrite(DIGIT_4, LOW);
  
  delay(x);
  
  digitalWrite(DIGIT_1, LOW);
  digitalWrite(DIGIT_2, HIGH);
  digitalWrite(DIGIT_3, LOW);
  digitalWrite(DIGIT_4, LOW);
  
  delay(x);
  
  digitalWrite(DIGIT_1, LOW);
  digitalWrite(DIGIT_2, LOW);
  digitalWrite(DIGIT_3, HIGH);
  digitalWrite(DIGIT_4, LOW);
  
  delay(x);
  
  digitalWrite(DIGIT_1, LOW);
  digitalWrite(DIGIT_2, LOW);
  digitalWrite(DIGIT_3, LOW);
  digitalWrite(DIGIT_4, HIGH);
  
  delay(x);
  
  if (irrecv.decode(&results)) {
    irrecv.resume(); // Receive the next value
    
    digitalWrite(13, HIGH);
    
  }else{
    digitalWrite(13, LOW);
  }
  
  if (Serial.read() != -1) {
    
    digitalWrite(DIGIT_1, LOW);
    digitalWrite(DIGIT_2, LOW);
    digitalWrite(DIGIT_3, LOW);
    digitalWrite(DIGIT_4, LOW);
    
    for (int i = 0; i < 3; i++) {
      irsend.sendSony(0xa90, 12); // Sony TV power code
      delay(40);
    }
    
    irrecv.enableIRIn();
  }
  
}
Advertisements

Arduino Laser Tag Update #2

Software Flow Chart

Flow Chart

Over the holidays, I started drawing a flow chart diagram for the software portion of the Arduino Laser Tag project. The idea here is to use software polling to detect the trigger and reload buttons instead of using interrupts. I wanted to get around the issue of the interrupts incorrectly detecting the release of the trigger due to the debounce of the buttons. The HDWController will be a new class created to manage all the hardware components (motors, speaker, IR emmitter and sensor). The LaserGun class will be more of an abstract class that will queue certain tasks for the HDWController to perform. You can view the Excel spreadsheet of the flow chart here.