Introduction: Intel Edison Basic's: Spirit Level

About: 31 years old tinker and diy hobbyist. From Oulu, Finland. IG @mkarvonen_instructables

This is how to make the GY-61 acceleration sensor work with Intel Edison.

And in the same time let's make a spirit level!

Step 1: Things Needed and How to Install.

You will need a Arduino based board (i used the Intel Edison).

Then you will need the GY-61 acceleration sensor. You can use basicly any acceleration sensor with this. Just connect the right pins and re-calibrate the whole thing...

After that you will need a RGB-LCD screen. If you want to use regular LDC screen, delete the RGB-LCD definition from the code. it will work the same but without the possibility to change the color.

Lastly you will need a few cables.

Optional use for the connector shield and for the breadboard.

When you have all the things you will need start installing..

Connect cable to the LCD and the other end to the connector shield's I2C port.

Then connect the GY-61, Vcc goes to Arduino's +5 Vout and the GND goes to Arduino's GND pin.

After that connect the X-out (Blue wire) to Arduino's Analog 1 pin (A1).

Then connect the Y-out (Green wire) to Arduino's Analog 0 pin( A0).

Lastly connect the Z-out (Yellow wire) to Arduino's Analog 2 pin (A2).

the pins in the acceleration sensor (picture 4) go from left to right. (GND (brown),Z-out (yellow),Y-out(green)

,X-out(blue) ,Vcc (red)) .

Step 2: Coding and Calibrating

First of all let's start with the definition of components and variables.

The minVal and maxVal is for calibration. This is a almost 99% sure thing that you will have to change by your self.

If you have any problem's whit that just message me and let's see that if i can help you.

#include "rgb_lcd.h" rgb_lcd lcd;

//Analog read pins const int xPin = 0; const int yPin = 1; const int zPin = 2;

//Change these to calibrate the acceleration sensor. Get the values by reading the (zRead) int minVal = 274; int maxVal = 450;

double x; double y; double z;

Then is time for setup. In this you will just need to start the LCD screen and serial.

void setup(){
Serial.begin(115200); lcd.begin(16, 2); }

The loop is where the magic starts to happen.

First you will have to make calculations for the acceleration sensor readings. (in the code the base math is not done by me. I suck at math :P ) But basically that calculation means that you will have to convert the radians to degrees by calculating (atan2(-y,-z)+PI) to get the x degree and so on...Here is more information from atan2 and calculation.

void loop(){

int xRead = analogRead(xPin); int yRead = analogRead(yPin); int zRead = analogRead(zPin);

//convert read values to degrees -90 to 90 - Needed for atan2 int xAng = map(xRead, minVal, maxVal, -90, 90); int yAng = map(yRead, minVal, maxVal, -90, 90); int zAng = map(zRead, minVal, maxVal, -90, 90);

//Caculate 360deg values like so: atan2(-yAng, -zAng) //atan2 outputs the value of -π to π (radians) //We are then converting the radians to degrees x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI); y = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI); z = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI);

Rest of the code is pretty simple and basic stuff. Set the RGB color. And chose what to print or write on the screen.

The picture shows how to make basic symbols to the LCD screen. Like in example to make a arrow to the right you will have to find the correct picture from the table and write the correct binary for the symbol (arrowright = 0111 for higher 4 bits and 1110 lower bits = 01111110 in binary.

Serial.print("x: ");
Serial.print(x); Serial.print(" | y: "); Serial.print(y); Serial.print(" | z: "); Serial.println(z); // To change the colour simply change the numbers below to something else. Ie ( 255,123,50) lcd.setRGB(0, 0, 255);

lcd.setCursor(0,0); lcd.print("X:"); lcd.print(x); lcd.setCursor(7,0); lcd.write(0b11011111); lcd.setCursor(0,1); lcd.print("Y:"); lcd.print(y); lcd.setCursor(7,1); lcd.write(0b11011111); lcd.setCursor(15,0); lcd.write(0b01011110); lcd.setCursor(15,1);

//the arrow is this one. lcd.write(0b01111110);

delay(1000); }

Step 3: Test the Acceleration Sensor.

The main build is now done.

Test the sensor to make sure the calibration is done.

If you like my project's be sure to follow me!

If you have any questions at all, just ask them. I will answer in 24 hours.

Happy building!