#3: Jack in the Box

When I thought of the word “unexpected”, the first cliche that popped into my head (no pun intended) was the ‘Jack in the Box’ toy every little kid knows. At first, I wanted to use a flex sensor to turn the LED on and off once the box was opened/closed but I realized that a photoresistor would do the same job. I really enjoyed creating this box from scratch, soldering the sensor and LED for the first time and then seeing it work; hence, the smile :).

int Pr = 0; // will be used for analog 0.
int PrValue = 0; // value of output
int Pr_Input = 700; // value of when light is on

void setup() {

Serial.begin(9600); 
pinMode(13, OUTPUT); // pin 13 as output

}

void loop() {

PrValue = analogRead(Pr);
Serial.println(PrValue); 
delay(100); 

if (PrValue < Pr_Input)

{ digitalWrite(13, HIGH); } else { digitalWrite(13, LOW);}

}

 

Leave a Reply