34 Light sensors

Hello Everyone.

Let me start by saying that I’m a totally newcomer to the Arduino world so my question may seem noob by after hours of googling I didn’t found what I’m looking for.

I’m helping a friend that needs to use 34 lasers to work as digital independent switches.

Since we have to keep this a low cost project, I was thinking on using the “Mini Photocell” from SparkFun as the light sensor.

This brings me to my first question. Since this photocell is a variable resistance, is there a way to use it on one of the digital pins since I have more of those than the analog ones?

Second question is, even if I manage to use it on the digital pins, I still don’t have 34 of them. Following the same low cost approach, is there a way to have more pins ?

Any support is welcome. Thank you.

The first thing I've got to ask is what in the WORLD you're doing that needs lasers to function as 34 switches ;)

There are a lot of variables that somewhat interact in your questions. The photocells could be used as switches, IF their response time is within acceptable limits (roughly a second) and you can contrive to block out anything resembling your laser source (if it's an IR laser, then you'd need IR filters to block ambient light, for example). Honestly, your best bet would probably be to buy some surplus phototransistors from someplace like All Electronics http://www.allelectronics.com/make-a-store/category/435/Opto-Electronics/1.html, and use them.

To get 34 switch inputs into a 'duino, you'll need an encoder chip of some kind between the switches and digital pins of the 'duino - something that would take (say) 7 switches, and give you the appropriate 3 bits of binary output to feed into the 'duino. If the switches are physically close enough, you might be able to manage it with a matrix-keyboard encoder chip like one from E-Labs http://www.elabinc.com/Semiconductors/ProductOverview/tabid/57/Default.aspx.

Good luck!


If the switches are physically close enough,

Not sure I agree with that.

Also a matrix scanning chip is not what you need because you have little control over the reading of it and you have trouble when more than one detector is activated at the same time.

Photo transistors are the way to go, not photo resistors as the area the laser will cover will not be wide enough to give you a decent reading on a photo resistor.

If you want more analogue inputs use an analogue multiplexer like the 4066. This will also work if you want to switch digital inputs as well.

Hello Grumpy_Mike and DMerriman.

Thank you for the tips. I like the idea of the phototransistors, I'll test that and it's even lower cost.

I also love the idea of the 4066 multiplexer.

If you guys have some links with projects on this please feel free to post them :)

The playground is a great source of information:-



This has got to be a laser harp, right? If it is then have you seen Stephen Hobley's version?


it would be a whole lot cooler if it involved 34 sharks


Thank you for the info. Yes, it's a kind of a harp :)

I already have the lasers and now I've bought two sensors.

  1. Photo transistor BPX43-5
  2. Photo diode

I'm going around and around with this. For the photo transistor I cannot find any examples and since I'm more on the programming side that the electronics, I have no idea how to connect this to the arduino.

The photo diode is the same although I have no reference for this one. It looks exactly like a normal led, transparent with only 2 pins.

Anyone has any ideas on how to connect this two?

My preferred would be the photo diode since the cost is 4 times lower. Consider that I just need on and off and they will be target of a laser so high intensity when on, any other thing will be off (like ambient light)

Help appreciated.

For the photo transistor I cannot find any examples

I find that hard to believe.

Have a look at two of my projects:- http://www.thebox.myzen.co.uk/Hardware/Projects.html The "sound square" and "sneak thief", they both use photo transistors.

Photo diodes are the same to wire up, cathode to an analogue input and pull up resistor to +5N, anode to ground.

Great project that sound square.

I've been doing some testing and built the following that works but I'm afraid it's not correct and damages the Arduino.

Arduino +5v to Photo diode cathode Photo diode anode pin to digital pin 2 Photo diode anode pin to 480 oms resistance resistance to Arduino Gnd

With this setup I have the following code:

int sensorPin = 2;
int val = 100;

void setup() 
  pinMode(sensorPin, INPUT);     

void loop()  
  val = digitalRead(sensorPin);
  Serial.print (val);

This works well, even with strong light the value output is ZERO and with direct laser light (from a laser pen) it returns ONE.

Result is the expected but, can this damage in some way the Arduino?

Thank you.

can this damage in some way the Arduino?

I can’t see how this would damage the input at all, are you experiencing any trouble?

Essentially you are pulling down the input with the resistor and pulling it up through the diode. With such a low value of resistor you are requiring the diode to pass a lot of current when it is on in order to pull it up to a one.

However, if you increase the resistor too much there won’t be enough current to pull it down.

You could also connect it to an analogue input and then it would be more sensitive as you could set your 0 to 1 threshold. This would also allow you to use a much bigger resistor and even swap the position of the resistor and diode which is a more conventional arrangement.

Great news :)

The result is good, no trouble at all. I was just afraid that I would be stressing some components because it was not done exactly how you described.

Regarding changing to analog, I prefer on the digital ports since I have more of those and I need them all

Thank you.