Distancesensor and Accelerometer

In the beginning I tried to work with two different sensors;
a Distancesensor and an Accelerometer.

I started with the Distancesensor.
Before acctually working with the Lilypad I tried to create a functional curcuit
with the Arduinio Uno. After a short while and several helpful internet sites I was able to get usable output.
Now it was only a question of using the right pins on the Lilypad instead of the Arduino
Uno, but getting it to work simple with wires didn’t work so well, so I decided to keep using
a breadbord for the Distancesensor itself.
Modifying the given code I was able to let my LED blink in different intervals, depending on the
distance between the sensor and my hand.

20160502_224430[1]

The following modification was used on the code to let the LED blink:


if (distance > 61 && distance <= 90) {
  digitalWrite(LED, HIGH);
  delay(1000);
  digitalWrite(LED, LOW);
  delay(1000);
}
if (distance > 30 && distance <= 60) {
  digitalWrite(LED, HIGH);
  delay(600);
  digitalWrite(LED, LOW);
  delay(600);
}
if (distance > 15 && distance <= 30) {
  digitalWrite(LED, HIGH);
  delay(300);
  digitalWrite(LED, LOW);
  delay(300);
}
if (distance > 0 && distance <= 14) {
  digitalWrite(LED, HIGH);
  delay(100);
  digitalWrite(LED, LOW);
  delay(100);
}

The second sensor I used was the Accelerometer, which turned out to be quite a troublesome
child. Getting output wasn’t that hard with nearly every code I found on the net, but useful
and understandable output was hard to find.Reading more about the sensor here and using the code on this site I was finally able to understand more of how the sensor works.
The problem is, that each axis has a different start state unequal to the “Zero-G” mentioned in the second link. But dispite getting different values from each axis the sensor itself still worked well in showing which axis was used an in which direction the sensor was used.

3-Axis Accelerometer
x-axis: blue, y-axis: green, z-axis: red

Still, the current state would only allow one to work with relative values to do something
with light.