Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Game Laser Sensor

Bwinter

New Member
Very much an amateur here, and I'm working on a basic laser-maze for a game. My goal a simple module that can send a low-power laser (class II), reflect off a few mirrors and back to the module into a photo-transistor. My design (below) uses a feed-back from the laser-beam back into the photo-transistor (Q3), activating Q1 (keeping the laser powered). Once the beam is broken, Q1 shuts the power off to the laser. An external TRIGGER (from an Arduino) initializes the laser (through Q2) and keeps the laser ON during set-up (then disable during "game-play"). I also have a SENSOR that feeds back to the Arduino when the photo-transistor is off.

I know I could also use the Arduino to trigger/inactivate the laser based off the input from the photo-transistor, but I'd like to keep this feedback loop as-is (and not rely on any of my equally-amateur Arduino programming).

So far, my prototype works properly on my bench (which is good). But I'm simply wondering (and attempting to learn):
  1. Is there a better way to do what I'm trying to do?
  2. Am I using the components correctly?
  3. How would I go about adding a simply LED (on this module) to indicate when the beam is correctly activating the sensor (while in set-up mode, with the TRIGGER providing the ON)?
  4. My eventual goal is to have multiple of these modules synchronized through an Arduino. When the Arduino detects a laser-trip (from one SENSOR), the Arduino would then turn off the remaining modules. Right now, the Arduino simply kills the power to all the modules (turning them off). Without using an additional pin on the Arduino, is there a way to also disable the laser through only the TRIGGER/SENSOR?
1711252591210.png
 
Add a resistor in the link to Q1 base and put the "sensor" connection at the right hand side.

Configure the Arduino pin as open drain, and leave it high normally to read the input level. Switch it to low out to kill the circuit.
(Or if no open drain mode, switch it to output + low, then back to input for normal sensing).

The same connection & pin could also be used as the "trigger", if the output was enabled and set high.

You could add an ultrabright LED and eg. 10K series resistor as an indicator, between trigger and gnd, whilst using a separate trigger pin & transistor.


The emitter follower configuration would not work with a 3.3V MCU, but as long as you are using one with 5V outputs it should be OK.

The usually preferred way is to use common emitter configuration, so the load is in the collector circuit.
That gives nearer the full supply at the load, rather than around 0.6V less that the input from the MCU or previous stage.

The only dubious things are current limiting for LED1 - is that a 5V module, or is it a normal current-operated type LED?
 
Thanks for the suggestions!

I’m using an Arduino Nano ESP32 (with has 3.3v outputs).

A). Why would your configuration not work with 3.3v trigger?
B). Is my original configuration not good with a 3.3v trigger? If not, can you clarify why that’s a mistake?

I’m using a laser module (LED1):

Laser Module
 
Emitter followers reduce the output by one forward junction drop, the base-emitter diode junction.
That means you will get at best around 2.7V out from a 3.3V input, regardless of supply voltage.

A common emitter transistor can be switched by less than 1V as long as the base current is adequate, and still switch any voltage (within it's specifications).

The LED module has internal control circuitry to regulate its current, so that is fine being operated at 5V.
 
Is my original schematic wrong, in that I'm trying to drive a 5V load (laser module), but my TRIGGER and SENSOR both are driven by a 3.3v pin from the Arduino?

Using an I/O expander (MCP23S17) driven at 5V wouldn't be good, because I would have an issue with SPI communication between the Arudino (3.3v) and the MCP23S17 (5v)?

Would I be better using an Arduino (ESP32?) with 5v I/O?
 
Last edited:
Is my original schematic wrong
Yes. If you use an NPN transistor, the emitter should generally be connected to .ground. This is called "low side switching" and maximizes the voltage and "on-state current flow" when the base is activated (pulled high). Your original design was bad.
 
Based off what I'm reading...is this getting closer?

During set-up and initialization, TRIGGER would be an Arduino output (3.3v), then switched to input during gameplay?

1711312651319.png

 
Just about, but you need current limiting when the output is high; otherwise it's virtually shored by the transistor base-emitter junction.

However, you still need to clamp it off to force a trigger...

It may work with two diodes added; one in series with R2, at the right of it, with anode to R2.
Then connect the MCU pin to the resistor-diode junction via another2K resistor.
Add a diode across that resistor, with cathode to the MCU side.

Also add a resistor between base & emitter to bypass any slight leakage, eg. 10K.
 
I don't know what rate you are scanning the targets with your microcontroller or what kind of accuracy is required for a full hit but, adding a capacitor between your light sensor and Q1 will only detect fast transistions of light and briefly turn the LED on.

This way, reflected light or ambient sunlight will be less likely to trigger the system.

Also, move your trigger sensor to connect between LED1 and Q1 so you get move dynamic range in voltage for a hit.
 
Thanks! But unfortunately...I think I'm getting more confused than before (being very much an amateur).

While I conceptually understand using the same GPIO as both the trigger and sensor (switching pinmode), I'm not fully grasping what's needed in the schematic (ie., I don't understand the purpose of R2 above, nor how/why to add the diodes, let alone how to properly select the right component).

Going back to my original schematic, I attempted (?) to reconfigure this to low-side switching.

TRIGGER would always be an output:
  • set high/3.3V to activate Q2 during set-up and initialization
  • set low during game-mode (as Q1 is activated by the phototransistor Q3, thus keeping the laser powered)

The SENSOR (as an Arduino input) would feed back HIGH when Q3 is activated (by the laser). However, once the Arduino detects any LOW signal from a sense (ie, a beam has been interrupted), then set all SENSORS to output LOW (thus inactivating all remaining Q1 on the other modules)?

Would this achieve my goal in a reasonable manner? Or are there still ample mistakes?

1711321535091.png
 
I don't know what rate you are scanning the targets with your microcontroller or what kind of accuracy is required for a full hit but, adding a capacitor between your light sensor and Q1 will only detect fast transistions of light and briefly turn the LED on.

This way, reflected light or ambient sunlight will be less likely to trigger the system.

Also, move your trigger sensor to connect between LED1 and Q1 so you get move dynamic range in voltage for a hit.
I originally included a capacitor as you suggested--but it simply delayed the time between breaking the beam vs turning the beam off (and I think I want an instant beam-break/beam off). But I may need to possibly use a smaller capacitor if the set-up is too sensitive (ie, interrupted by dust).

If anything, ambient sunlight would simply cause the phototransistor to not register a beam-break. But since this is just for a game (intended to be played in a darkend room, I'm not too concerned about that). I also have my phototransistor calibrated (and covered with a red lens) that only the laser can activate it.
 
Thanks! But unfortunately...I think I'm getting more confused than before (being very much an amateur).

While I conceptually understand using the same GPIO as both the trigger and sensor (switching pinmode), I'm not fully grasping what's needed in the schematic (ie., I don't understand the purpose of R2 above, nor how/why to add the diodes, let alone how to properly select the right component).

Going back to my original schematic, I attempted (?) to reconfigure this to low-side switching.

TRIGGER would always be an output:
  • set high/3.3V to activate Q2 during set-up and initialization
  • set low during game-mode (as Q1 is activated by the phototransistor Q3, thus keeping the laser powered)

The SENSOR (as an Arduino input) would feed back HIGH when Q3 is activated (by the laser). However, once the Arduino detects any LOW signal from a sense (ie, a beam has been interrupted), then set all SENSORS to output LOW (thus inactivating all remaining Q1 on the other modules)?

Would this achieve my goal in a reasonable manner? Or are there still ample mistakes?

View attachment 145108
based on my interpretation of your description, I think this is a better design.
 
Low side or High side is based on the output devices switching to ground or switching to power, rather than the transistor configuration - eg. a PNP or P channel device with emitter or source to V+ is a high side switch.

In anything to do with industrial control, safety related or where a false signal could cause harm or damage, high side is required - main on the basis that a fault to ground will prevent a thing operating or blow a fuse, rather than doing the same as a low side switch and activating something.

But, an NPN low side switch is the simplest to control a 5V or higher load from a 3.3V MCU or logic IC; (or a 12V load from 5V etc).



I'm not fully grasping what's needed in the schematic (ie., I don't understand the purpose of R2 above, nor how/why to add the diodes, let alone how to properly select the right component).

With that circuit, R13 is not needed, its just in parallel with R1 - but you do not have a series base resistor, so there is a direct path from 5V through the phototransistor and base that can take excess current.

This is what I was trying to describe, tidied up a bit:

laserswitch.png


(R3 and R4 should actually be a lot higher; 10K or more, I was just copying and pasting & missed changing the values. Also ignore the opto part types, they are just to represent what you are using)


With the MCU pin as an input, it just senses the circuit state.

Set it high and briefly set it to output, and it should switch the circuit on via D2.

Set it low and briefly set it as an output, and it should switch the circuit off, by D3 bypassing the drive to Q2 base.

(D1 means there must be more like 1V at the right of R2 for the transistor to be on; that means the MCU pin when LOW can pull that point down far enough via D3 to remove the base current).


It does need testing in practice - eg. Can the MCU 3,3V output provide enough current after the voltage drops from D2, D1 and the base-emitter voltage drops, to reliably switch it on??

R2 could be split to two lower value resistors totalling around 2K, with D2 connected to the mid point, if needed.. Only the right half would be in the switch-on path.
 
Thanks--staring to make sense what you were describing earlier!

I intentionally didn't include a resistor between the phototransistor and base (Q1 in my diagram), as I wanted to ensure that Q1 was fully activated. On my bench, I only get approx 5-10 mA through the phototransistor under best-case scenario (the laser is focused directly onto the phototransistor, 1cm away). So I didn't think that I would want/need any resistor in this path during normal operation (where the laser could be 10 yards from the phototransistor). Is my understanding here incorrect?

In your diagram, can you clarify the purpose of D1? I understand that it restricts current to only flow into the base. But why is that important here?
 
Is my understanding here incorrect?
Yes, your assumption is wrong.
You are living in a situation where you "hope" you'll not get more than the maximum current flow through Q3 to burn it out, and likewise, hoping that you will not get enough current to burn out the base-emitter junction.

You were actually pretty cavalier in testing your circuit with a direct laser hit to the sensor. It could have easily allowed much more current through (and likely would have if you hit it with a green laser instead of a red laser (the sensor is better tuned for green light than red).

In any case, engineered designs are not a product of hope, they are a product of specifications and adding a resistor to limit current and, if sized appropriately, will not greatly impact your sensitivity.
 
I initially tested the $0.45 sensor alone (not part of any circuit) under ambient light (as I had no good way of knowing how much current would pass) well before I even attempted to hit it with a laser--and even then I slowly introduced the laser with limited exposure. I also verified that the base current (of my Q1) wouldn't be exceeded (<50mA).

Given this, can you clarify how I would go about selecting the appropriate resistor? Knowing that I get max 5-10 mA under perfect set-up (which is far from the normal environment this is intended to function in), I'm more concerned about not getting enough current to properly activate Q1.
 
I initially tested the $0.45 sensor alone (not part of any circuit) under ambient light (as I had no good way of knowing how much current would pass) well before I even attempted to hit it with a laser--and even then I slowly introduced the laser with limited exposure. I also verified that the base current (of my Q1) wouldn't be exceeded (<50mA).

Given this, can you clarify how I would go about selecting the appropriate resistor? Knowing that I get max 5-10 mA under perfect set-up (which is far from the normal environment this is intended to function in), I'm more concerned about not getting enough current to properly activate Q1.
Since you tested it, I'd just leave it but normally, you'd look at the maximum V(ce) that your sensor allows and the maximum current that your Q1 can handle (base to emitter ) and then use ohms law to select a resistor that will limit the current to your circuit's max. Assuming a 0.6v voltage drop from the Q1 base to emitter.
 
In your diagram, can you clarify the purpose of D1?

It's to add a voltage drop from the parts to the left, before the transistor starts to conduct.

Without that, voltage drop across the "turn off" diode and MCU low output level would have to be somewhat under 0.6V to force the transistor off.

With the diode, anything under around 1V should force it off, which is much more practical.

It's a similar arrangement to that used in old "DTL" logic circuits:

main-qimg-fdb114cd67da3a05e1757c8319f6fed0-lq
 
If you need detection accuracy for volume production I suggest you use a photo diode instead that will be very precise and not have the wide tolerance of a hFE.
 

Latest threads

New Articles From Microcontroller Tips

Back
Top