Introduction: Hello builders! In this project you will learn how to make a Flat Surface Detector. Whenever you're making something like a table or a desk you need to check if the surface is not tilted at an angle and is sitting flat on the ground. Unless you're into a tilted desk and you like it for some weird reason this tool can be quite handy. Now off course you can get the same thing on your phones but lets just make it cause we are creative :). This project is made with the LinkIt One Board Microcontroller which is a very powerful tool to control virtually anything electronic. Also this project uses an gyroscoping to measure its tilt and yaw to know whether or not it is on a flat surface. Lets get into the parts needed for this project.

## Step 1: Parts

Level: Easy

2. Usb Cable

3. 3 axis Gyroscope/Accelerometer

4. 2 LED's ( Green and Red )

5. Perf Board

Tools:

1. Soldering Iron

2. Hot Glue

## Step 2: Solder Gyroscope

1. Solder red wires on to the Gyroscope's pins( X, Y, Z)

2. Solder power wires to the VCC and GND.

Make sure that none of the pins are bridged in the connections and then move on.

## Step 3: Solder the LED

In this step we will solder the LED's on to a perf board so that they can indicate if the surface is laying down untilted.

1. Cut the LED's legs short

2. Put the LED's in the perf board

3. Solder the leds onto the Board.

4. On solder wires on to the leds.

## Step 4: Check

Now check that you have the Gyroscope, the led board soldered and the LinkIt One Board. Once you have all these you are ready to program. So lets code it.

## Step 5: Code

This code will allow you to keep the board on a surface and know whether or not the surface is leveled. Make sure to change the numbers in the if statement according to your readings or this will not work.

int GreenLed = 13; // LED's
int RedLed = 12;

int xaxis = A0; // pins of the Accelerometer

int yaxis = A1;

int zaxis = A2;

int oval;

int oval;

int zval;

void setup() {

pinMode(GreenLed, OUTPUT);

pinMode(RedLed, OUTPUT);

pinMode(xaxis, INPUT);

pinMode(yaxis, INPUT);

pinMode(zaxis, INPUT); }

void loop() {

if (xval == 0 && yval == 0 && zval == 0 ) // change the 0's here to the numbers you see when your accelerometer is sitting down flat

{ digitalWrite(GreenLed, HIGH);

digitalWrite(RedLed, LOW);

}

else

{

digitalWrite(RedLed, HIGH);

digitalWrite(GreenLed,LOW);

}

}

## Step 6: Wire It

In this step we will take the programmed board and wire it up.

1. First connect the GND of the leds to GND of the board.

2. Connect the Green LED to pin 13

3. Connect the Red LED to pin 12

4. Connect the Accelerometers wires (x,y,z) to (A0,A1,A2)

5. Connect the VCC of the Accelerometer to 5v and GND to GND.

And thats it you're basically done except its not pretty... yet so lets make it pretty by enclosing it in a small compact box.

## Step 7: Box It

Find yourself a small cardboard board that is big enough to enclose the Microcontroller as that is the biggest component in the box.

1. Put a dab of hot glue at the bottom of the box.

2. Stick the Accelerometer flat to the bottom.

3. Then put in the MicroController on top

4. Make a hole for the leds to seek through and hot glue it there.

5. Make a hole for the USB cable

6. Close the box and thats it

## Step 8: Testing and Conclusion

Now plug in the board to usb power and pick it up.

If you did everything right it should now be glowing red, and after keeping it on something not titled(table) it should be green.

In conclusion this project is fun and simple but if you want a level detector you can also use the one in your phone. If you have any questions feel free to ask me in the comments. Have fun building:)