Introduction: Intel® Edison Hands-on Day 7: Luminous Treasure Box

Luminous treasure box, the name sounds fun. And that would be real fun! We will make this box, which will be closed during the day, once in the night, its light will get brighter with the box opened slowly. Ha-ha...the inner workings of the box is that analog ambient light sensor can detect light strong or weak. With the brightness changing, the output values will be different. At night, to reach the set value, the servo will rotate, and LED turn on at the same time.

What you needed:

Step 1: Connection Diagram

TowerPro SG50 Servo → Digital 9

Analog Ambient Light Sensor → Analog 0

Digital Piranha LED Light Module - Red → Digital 3

Fixed the servo at the connection of the box, the LED in the box. Of course, the sensor is exposed to detect ambient light. After the installation is completed, place the box in the dark. And you can check if the box should open automatically.

Step 2: Example Code


Servo myservo;

int LED = 3; //the number of the LED pin

int val = 0; //variable to store the sensor value

int pos = 0;

int light =0;

void setup(){

// initialize the digital pin as an output.


// initialize serial communication at 9600 bits per second:


// attaches the servo on pin 9 to the servo object


// tell servo to go to position in 0 degree



void loop(){

val = analogRead(0); // read the input on analog pin 0

Serial.println(val); // print out the value you read

//Once smaller than the set value,increasing angles


pos = pos +2;

if(pos >= 90){ //After moverd to 90 degree, keep in this degree

pos = 90;


// tell servo to go to position in variable 'pos'



// As the angle increases, increased brightness LED

light = map(pos,0,90,0,255);

analogWrite(LED,light); //set the brightness


pos = pos -2; //minus 2 degree

if(pos <= 0){

pos = 0; //reduced up to 0 degrees




light = map(pos,0,90,0,255);