Week 9: Analog and Digital sensors – Picture Perfect

Concept

I have always wondered why it is not possible to take the perfect picture of yourself. I realized that two of the most important controllable variables in photography are the lighting and the focus distance. Hence the project was designed to give an indication of the perfect lighting for the surroundings and the distance for the person taking the photo.

Implementation

const int buttonPin = 7; 
int onOff = 0;
int sensorPin = A0;   
int ledPin = 13;  
int sensorValue = 0; 
const int blueLEDPin = 12;
const int yellowLEDPin = 8;
const int goLED = 10;
#define echoPin 2 
#define trigPin 3
long duration; 
int distance;
void setup() {
  // put your setup code here, to run once:
  
  pinMode(ledPin, OUTPUT);
  digitalWrite(blueLEDPin, OUTPUT);
  digitalWrite(yellowLEDPin, OUTPUT);
  digitalWrite(goLED, OUTPUT);
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);

  //Ultra
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
  pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT

}

void loop() {
  onOff = digitalRead(buttonPin);
//LDR
  sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  digitalWrite(ledPin, LOW);
  digitalWrite(blueLEDPin, LOW);
  delay(sensorValue/2);
  digitalWrite(ledPin, HIGH);
  digitalWrite(blueLEDPin, HIGH);
  delay(sensorValue/2);

  //Ultrasonic sensor
  digitalWrite(trigPin, LOW);
  delay(2);
  digitalWrite(trigPin, HIGH);
  delay(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2; 
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  if ((distance>40&&distance<55)){
    digitalWrite(yellowLEDPin, HIGH);
    
  }
  else {
    digitalWrite(yellowLEDPin, LOW);
    delay(distance*2);
    digitalWrite(yellowLEDPin, HIGH);
  }
  Serial.println(onOff);
  if ((distance>40&&distance<55)&&(sensorValue>600 &&sensorValue<900)&&(onOff == LOW)){
    digitalWrite(goLED, HIGH);
    digitalWrite(yellowLEDPin, HIGH);
    digitalWrite(blueLEDPin, HIGH);
    delay(10000);
    digitalWrite(goLED, LOW);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(blueLEDPin, LOW);
  
  }

}

The program takes in the lighting of the surroundings using the LDR and then makes the blue LED turn on and off proportional to the intensity of the light. This shows if you need to increase the light in surroundings or if it getting closer to the perfect level. Likewise with the Ultrasonic sensor, it detects the distance from the object right in front and inputs distance data and the yellow led blinks proportionally to the distance from sensor. When button is pressed and conditions are met, the lights stay on for 10 seconds.

Reflections

Initially, I wanted to use Tarek’s creative switch idea to make sure that the subject is flexing for the picture. However, I realized that it would require a considerable length of wire to obtain a reasonable distance to take a good picture. I also wanted to make the iPhone take the photo itself via voice commands (where a recoding of me sating “hi Siri, take a picture” would be output once the correct conditions are met). However, iOS security regulations and the lack of complexity in the speaker would not allow this function.

Leave a Reply