Week 5: The Worst Camera in the World

For my latest pcomp project, I decided to try to make The Worst Camera in the World. Initially, I wanted to create a grid of photoresistors, that would act as really, really, bad photosensitive plate that (hopefully) would capture at least a black-and-white impression of whatever was before it. I quickly realized that I did not have 25 photoresistors hanging around, and the shop didn't carry them for free. The shop DOES, however, offer quite a few LEDs for free, and I decided to act on a rumor I once heard: if you reverse the polarity of an LED, it will act as a photo resistor.

Dear reader, the rumors are true.

Amitabh, one of the second years, pointed out that an Arduino won't be able to handle 25 analog inputs, and suggested that I attach a row of LEDs to a servo motor that then moves through set intervals.

What a beautiful idea! And, basically, a very similar concept to my light wand from last week!

So far, I've only built it out with one LED to ensure that the basic concept works. The code is below:

#include <Servo.h>

int photo1 = A0; 
int photo2 = A1;
int photo3 = A2; 
int photo4 = A3;
int photo5 = A4; 

int maxVal = 0; 
int minVal = 1023;
float avgVal = 0;

Servo myservo;
int pos = 0;

int mappedValue;

void setup()
{
    Serial.begin(9600);  //Begin serial communcation
    
    pinMode(photo1, INPUT);
    myservo.attach(9);
    myservo.write(0);
    
}

void readPixel(int photoPixel){

  int potVal = analogRead(photoPixel);
  avgVal = avgVal * 0.95 + potVal * 0.05;
  
  if (potVal > maxVal) maxVal = potVal;
  if (potVal < minVal) minVal = potVal;

//  int mappedValue = map(potVal, 800, 1023, 0, 255);
  mappedValue = map(potVal, minVal+50, maxVal, 0, 255);
  
  }

void displayPixel(){

    if (mappedValue > 200) {   
      Serial.print("▢");
    } else if ((mappedValue < 200) && (mappedValue > 60)) { 
      Serial.print("▨"); 
    } else {
      Serial.print("▩");
    }
  }
  
void resetServo(){
  pos = 0;
  myservo.write(pos);
}

void updateServo(){

  pos = pos+(180/5);
  myservo.write(pos); 
  
  readPixel(photo1);
  displayPixel();

  readPixel(photo1);
  displayPixel();

  readPixel(photo1);
  displayPixel();

  readPixel(photo1);
  displayPixel();

  readPixel(photo1);
  displayPixel();

  if (pos >= 180) resetServo();
  delay(2000/5);
  
}

void loop()
{

  // if switch is pushed, "take a picture"
    updateServo();
    Serial.println(" ");
  
}

Here’s what my (currently) one-pixel camera displays:

And here’s a sketch of where I’m hoping to take it:

I need to build out the complete attachment for the servo, with 4 other LEDs, and I hope to have a picture of 5x5 resolution… that can capture when a blob is before it.

Amitabh also noted that it maybe helpful to have a pinhole lens or some other contraption for better controlling the light into my photosensitive grid…

For now, it remains work in progress!