IRON BOX ENERGY SAVING SYSTEM USING ACCELEROMETER AND ARDUINO

Photo of author

By Jackson Taylor

IN THIS PROJECT IRON BOX WILL AUTOMATICALLY TURNS OFF WHEN IT IS IN NOT USE (NO MOVEMENT ).
JUST SHAKE IT TO TURN ON.

  • SENSOR -ADXL335
  • RELAY -12V ,5A






CIRCUIT

PROGRAM -ARDUINO
#define buzzer  10
#define relay   9
int x, y, z, xg, yg, zg, flag = 0, flag1 = 0, su = 1, i;
int x1, y1, z1;
int xt = 8, yt = 8, zt = 12;
int xd, yd, zd;
int time1;
void setup()
{
Serial.begin(9600);
init_outputs();
on_all();
}
void loop()
{
  read_accelerometer();
  if ( (x <= 420 && x >= 400) && (y <= 360 && y >=320) && (z <= 360 && z >= 310)) //hori
  {  
    Serial.println(“vert”);
    vertical ();
  }
  else if ( x <= 350 && x >= 300 && y <= 420 && y >= 380 && z >= 310 && z <= 350)
  {
    Serial.println(“hori”);
    horizontal();
  }
}
void vertical(void)
{
  time1 = 0;
  on_all();
  x1 = x;    y1 = y;    z1 = z;
  do
  {
    read_accelerometer();
    xd = x – x1;    yd = y – y1;    zd = z – z1;
    time1 = time1 + 1;
    if (time1 > 12)//TIME TO TURN OFF IN VERTICAL POSITION =12 * 250mS =3 SECONDS
    {
      off_all();      time1 = 11;
    }
  } while ((!((xd < -xt) || (xd > xt) )) && (!((yd < -yt) || (yd > yt) )) && (!((zd < -zt) || (zd > zt) ))) ;
  on_all();Serial.println(“brk1”);
  Serial.print(“zt=”); Serial.println(zd);
}
void horizontal(void)
{ time1 = 0;
  on_all();
  x1 = x;    y1 = y;    z1 = z;
  do
  {
    read_accelerometer();
    xd = x – x1;    yd = y – y1;    zd = z – z1;
    time1 = time1 + 1;
    if (time1 > 12) //TIME TO TURN OFF IN HORIZONTAL POSITION =12 * 250mS =3 SECONDS
    {
      off_all();      time1 = 7;
    }
  } while ((!((xd < -xt) || (xd > xt) )) && (!((yd < -yt) || (yd > yt) )) && (!((zd < -zt) || (zd > zt) ))) ;
  on_all();
  Serial.println(“brk1”);
  Serial.print(“zt=”); Serial.println(zd);
}
void read_accelerometer(void)
{
  x = analogRead(A5);
  y = analogRead(A4);
  z = analogRead(A3);
  Serial.print(x);
  Serial.print(‘,’);
  Serial.print(y);
  Serial.print(‘,’);
  Serial.println(z);
  delay(250);
}
void off_all(void)
{
  digitalWrite (buzzer, HIGH);
  digitalWrite (relay, HIGH);
  Serial.println(“——–off———“);
}
void on_all(void)
{ Serial.println(“——-on——–“);
  digitalWrite(buzzer, LOW);
  digitalWrite(relay, LOW);
}
void init_outputs(void)
{
  pinMode(buzzer, OUTPUT);
  pinMode(relay, OUTPUT);
}