I created a circuit with a motor that will turn on if the amount of light surrounding it increases. I calibrated a photosensor to accomplish this, which also will help in my final project.
State Diagram:

Circuit Photo:

Code:
int motorPin = 4;
int ledPin = 13;
int photoPin = 0;
int readIn = 0;
int initialRead = 0;
int activateVal = 0;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(motorPin, OUTPUT);
pinMode(photoPin, INPUT);
blink(); //blinks the status LED
initialRead = analogRead(photoPin); //gets initial reading for photosensor
activateVal = initialRead * 2; //the activation value will be double the initial
blink();
}
void loop()
{
readIn = analogRead(photoPin); //gets the current sensor reading
while (readIn >= activateVal) //while loop turns on motor and status LED if current reading
{ //is greater than the activation value
digitalWrite(ledPin, HIGH);
digitalWrite(motorPin, HIGH);
readIn = analogRead(photoPin); //checks the current value
}
digitalWrite(ledPin, LOW); //turns off motor and LED if current value is not great enough
digitalWrite(motorPin, LOW);
}
void blink()
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}