> | | | > Laser Detection: Handling Multiple Detector Circuits

Laser Detection: Handling Multiple Detector Circuits

Posted on Wednesday, 12 December 2012 | No Comments

In the post Laser Detection it was discussed how to set up a detector circuit and how the Arduino would recognise when the LaserBot was hit through the use of an interrupt. That was only for one detector circuit. However, three detector circuits are wanted on the LaserBot to make the game more interesting – more targets to shoot at, different points for the different targets etc. 


At first, only one interrupt was going to be used for all three detector circuits. This caused a problem in detecting which target had been hit as the interrupt only notifies the Arduino that it has been hit but not which target has been hit. The idea was then to have an output coming off each circuit which would then have its own individual port on the Arduino. When the interrupt said that the Arduino had been hit, the Arduino could then check the three different ports and see which ports state had changed. This, however, did not work as the interrupt joined all three circuits together, causing all three circuits to change state when they were hit.

Therefore, it was decided to use the two interrupts available on the Arduino. Two detector circuits would be connected to one interrupt, and the other circuit would be connected to the other interrupt. This meant that the Arduino could differentiate between two circuits, but not three. So, the user could get two different scores for hitting targets, rather than three different scores, which is not a big loss in terms of flexibility for the game. 


Referring to the previous post, the second interrupt is set up in the exact same way as the first interrupt. The interrupts are on pins 2 and 3 on the Arduino Uno. To enable the second interrupt, the following line of code needs to be added where the first interrupt is enabled.
 EIMSK |= (1 << INT1); //Enable external interrupt INT1
Then, another interrupt service routine (ISR) needs to be included.
   unsigned long hitMillis = millis();
  if ((hitMillis - lastBlinkTime) > interval)
    lastBlinkTime = hitMillis;

    score = score + scoreRight;
    Serial.println("Hit Interrupt 2");
Both interrupts on the Arduino are now set up and ready to be used.


The other two detector circuits should be built in the same way as the previous circuit. However, there has been a change in that there is no longer an LED in the circuit, as it was no longer needed for the LaserBot. The updated circuit for a detector circuit can be seen below.
Updated detection circuit
All three detector circuits were set up as above. Then, the output of the collector of the transistor for two of the circuits were joined together. This was then connected to one of the interrupts. The output of the collector of the other circuit went directly to the other interrupt on the Arduino. 


To test the circuit, power was connected to the Arduino and a Serial monitor was opened. Each of the circuits LDR was hit with a laser. On the Serial monitor, for the two circuits that are connected together, “Hit Interrupt 1” was printed while for the circuit that is by itself, “Hit Interrupt 2” was printed. This successfully shows that two different interrupts are being used. 

Leave a Reply

Theme MXS. Powered by Blogger.