Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
ardutronic
Published © CC BY-NC

arduBand - Save your eyes!

Every 10 minutes it checks my position and if it detects that I am sitting for thirty minutes, it activates an alarm.

IntermediateFull instructions provided5 hours3,032

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
SparkFun Power Cell - LiPo Charger/Booster
SparkFun Power Cell - LiPo Charger/Booster
×1
Analog Accelerometer: ADXL335
Adafruit Analog Accelerometer: ADXL335
×1
Buzzer
Buzzer
×1
SparkFun RGB LED Breakout - WS2812B
SparkFun RGB LED Breakout - WS2812B
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Solder Flux, Soldering
Solder Flux, Soldering
Soldering iron (generic)
Soldering iron (generic)
Hot Air Station, Industrial
Hot Air Station, Industrial

Story

Read more

Custom parts and enclosures

Housing

Stl file

Schematics

Schematic

Eagle file

Board

Eagle file

Code

acc_test.ino

C/C++
#include <FastLED.h>

#include <Wire.h>
int ADXL345 = 0x53;
float X_out, Y_out, Z_out;
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>

#define DELAYVAL 500

#define PIN 10
#define NUMPIXELS 1
const byte motor = 11;
const byte piezo = 9;
unsigned long minutes;
unsigned long prevMinutes;
int myTime;
int myTime2;
int myPos;

int minMotorVal = 0;
int maxMotorVal = 50;

int a;
int i;

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  Serial.begin(9600);
  pinMode(piezo, OUTPUT);
  pinMode(motor, OUTPUT);
  Wire.begin();
  Wire.beginTransmission(ADXL345);
  Wire.write(0x2D);
  Wire.write(8);
  Wire.endTransmission();
  delay(10);
  pixels.begin();
  pixels.clear();
}
void loop() {
  pixels.clear();
  minutes = millis();
  if (minutes - prevMinutes >= 1000)
  {
    prevMinutes = minutes;
    myTime++;
  }

  if (myTime == 600)
  {
    checkValues();
    checkPosition();
    notification();

    for (int i = 0; i <= 20; i++)
    {
      pixels.setPixelColor(0, pixels.Color(0, 0, i));
      pixels.show();
      delay(10);
    }

    for (int i = 20; i >= 0; i--)
    {
      pixels.setPixelColor(0, pixels.Color(0, 0, i));
      pixels.show();
      delay(10);
    }
  }

  if (myTime == 1200)
  {
    checkValues();
    checkPosition();
    notification();

    for (int i = 0; i <= 20; i++)
    {
      pixels.setPixelColor(0, pixels.Color(0, 0, i));
      pixels.show();
      delay(10);
    }

    for (int i = 20; i >= 0; i--)
    {
      pixels.setPixelColor(0, pixels.Color(0, 0, i));
      pixels.show();
      delay(10);
    }
  }

  if (myTime >= 1800)
  {
    checkValues();
    myPos++;
    notification();
    timeout();
  }

  Serial.print("myTime :");
  Serial.println(myTime);
  Serial.print("myTime2 :");
  Serial.println(myTime2);
  Serial.print("myPos :");
  Serial.println(myPos);
  delay(1000);
}

void checkValues()
{
  Wire.beginTransmission(ADXL345);
  Wire.write(0x32);
  Wire.endTransmission(false);
  Wire.requestFrom(ADXL345, 6, true);
  X_out = ( Wire.read() | Wire.read() << 8);
  X_out = X_out / 256;
  Y_out = ( Wire.read() | Wire.read() << 8);
  Y_out = Y_out / 256;
  Z_out = ( Wire.read() | Wire.read() << 8);
  Z_out = Z_out / 256;
}

void checkPosition()
{
  if (Y_out <= 0.5)
  {
    myPos++;
  }

  if (Y_out > 0.5)
  {
    myPos = 0;
    myTime = 0;
  }
}

void notification()
{
  if (myPos >= 3)
  {
    analogWrite(motor, maxMotorVal);
    delay(500);
    analogWrite(motor, minMotorVal);
    delay(500);
    analogWrite(motor, maxMotorVal);
    delay(500);
    analogWrite(motor, minMotorVal);

    for (int i = 0; i <= 20; i++)
    {
      pixels.setPixelColor(0, pixels.Color(i, 0, 0));
      pixels.show();
      delay(10);
    }

    for (int i = 20; i >= 0; i--)
    {
      pixels.setPixelColor(0, pixels.Color(i, 0, 0));
      pixels.show();
      delay(10);
    }
  }
}

void timeout()
{

  if (Y_out < 0.5)
  {
    myTime2 = myTime;
  }
  if (Y_out >= 0.5)
  {
myPos = 1;
    if ((myTime2 + 60) == myTime)
    {
      tone(piezo, 1000);
      delay(300);
      tone(piezo, 1000);
      delay(300);
      tone(piezo, 2000);
      delay(300);
      noTone(piezo);
      myPos = 0;
      myTime = 0;
      a = 0;
      for (int i = 0; i <= 20; i++)
      {
        pixels.setPixelColor(0, pixels.Color(0, i, 0));
        pixels.show();
        delay(10);
      }

      for (int i = 20; i >= 0; i--)
      {
        pixels.setPixelColor(0, pixels.Color(0, i, 0));
        pixels.show();
        delay(10);
      }
    }
  }
}

Credits

ardutronic

ardutronic

39 projects • 40 followers
I'm 20 years old student of electronic technical college. I'm passionate about electronics as well as editing movies

Comments