Introduction: Using Photo Sensor As Analog Imput

About: 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 for worn devices, interactive install…

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

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

Step 2: 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
Arduino.

Step 3: 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

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

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() {
Serial.begin(9600);
pinMode(out13, OUTPUT);
digitalWrite(out13,LOW);

pinMode(out12, OUTPUT);
digitalWrite(out12,LOW);

pinMode(out11, OUTPUT);
digitalWrite(out11,LOW);

pinMode(out10, OUTPUT);
digitalWrite(out10,LOW);

pinMode(out9, OUTPUT);
digitalWrite(out9,LOW);

pinMode(out8, OUTPUT);
digitalWrite(out8,LOW);

}

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

if(val4>400){
digitalWrite(out13,HIGH);
Serial.println("pressed!");
}else if(val4<350){
digitalWrite(out13,LOW);
}

if(val3>600){
digitalWrite(out12,HIGH);
Serial.println("pressed!");
}else if(val3<550){
digitalWrite(out12,LOW);
}

if(val2>900){
digitalWrite(out11,HIGH);
Serial.println("pressed!");
}else if(val2<850){
digitalWrite(out11,LOW);
}

if(val0>400){
digitalWrite(out9,HIGH);
Serial.println("pressed!");
}else if(val0<350){
digitalWrite(out9,LOW);
}

if(val5>630){
digitalWrite(out8,HIGH);
Serial.println("pressed!");
}else if(val5<615){
digitalWrite(out8,LOW);
}

}

Full Spectrum Laser Contest 2016

Participated in the
Full Spectrum Laser Contest 2016

Raspberry Pi Contest 2016

Participated in the
Raspberry Pi Contest 2016