Introduction: Using Photo Sensor As Analog Imput

Picture of Using Photo Sensor As Analog Imput

Here we are using several photo resistors as buttons. The idea is when you cover the resistor is like you are pressing a button.

Step 1: What We Need

Picture of What We Need

- Arduino
- 100k resistor
- Photosensor
- Cable
- Male headers

Step 2: Connecting the Sensor

Picture of Connecting the Sensor

To connect the photosensor we need to add a resistor. Our three
connections are the ground, VCC 5V and the data sent to

Step 3: Placing the Sensors

Picture of Placing the Sensors

Then we simply placed the senors an a plexiglas, for prototyping
we just stick them with tape.

Step 4: Preparing Arduino Connection

Picture of Preparing Arduino Connection

The ground as well as the vcc has to be connected to one cable to connect it to the Arduino. The clearest is to solder it with the resistors to small piece of circuit board.

Step 5: Data Input and Arduino Connection

Picture of Data Input and Arduino Connection

For a good connection it is better to solder the data cables to
male headers so you can easily plug them to the Arduino (shown
in the red square)
Later we plug the output pins to the Arduino marked by the
yellow square

That is it! Follow bellow the arduino code. Have fun!

// select the input pin for the photosensor

int photo0 = 0;
int photo1 = 1;
int photo2 = 2;
int photo3 = 3;
int photo4 = 4;
int photo5 = 5;

// variable to store the value coming from the sensor
int val0 = 0;
int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;
int val5 = 0;

//digital out
int out13 = 13;
int out12 = 12;
int out11 = 11;
int out10 = 10;
int out9 = 9;
int out8 = 8;

void setup() {
pinMode(out13, OUTPUT);

pinMode(out12, OUTPUT);

pinMode(out11, OUTPUT);

pinMode(out10, OUTPUT);

pinMode(out9, OUTPUT);

pinMode(out8, OUTPUT);


void loop() {
val0 = analogRead(photo0);
val1 = analogRead(photo1);
val2 = analogRead(photo2);
val3 = analogRead(photo3);
val4 = analogRead(photo4);
val5 = analogRead(photo5);

}else if(val4<350){

}else if(val3<550){

}else if(val2<850){

}else if(val0<350){

}else if(val5<615){



germap (author)2016-02-24

Good idea, sometimes you don't want to push a button, just want to pass a finger or a hand on a zone, for instance, for a snooze function in an alarm clock.

thomcomstock (author)2016-02-16

Please help me to understand something. If you are using the photo sensor as a button; are buttons not digital (on/off or 1,0) inputs? What is the analog part?

popkalab (author)thomcomstock2016-02-16

sure. The light sensor in this case is connected to the analogue pin in the arduino. this allows you to have a treshold and tell the arduino when u want the button to be on or off. You can even create more states in between this on and off depending on your application. but again, it all depends on what you are doing with it.

thomcomstock (author)popkalab2016-02-16

Thank you for the explanation. As I am quite new to the Arduino scene I sometimes do not realize the full potential of Arduino related instructables. I can now see how powerful this application might be.

Actually, I believe that I can find many uses for this (e.g. incrementally adjusting the angle of my solar panels to follow the sun using your method and a few photo sensors).

Again, thank you.

DIY Hacks and How Tos (author)2016-02-14

Great project! Keep in mind that photoresistors come in a wide variety of values and performance characteristics. You may need to adjust your fixed resistor to compensate.

Thanks. That is very true... I will try to post more details next time ;-)

About This Instructable




Bio: Ricardo O'Nascimento is an artist and researcher on the field of new media and interactive art. He investigates body-environment relations focused on interface development ... More »
Add instructable to: