Wednesday, November 13, 2013

control system using the arduino with ADXL335

Hi these the project explain about the how to control the system using the ADXl335 3d mem sensor or motion sensor.

connections:

1.3 digital pins connected to the arduino to relay board
2.3 analog pins connected to the ADXL335
adxl335 gnd to arduino gnd
adxl335 vcc to arduino 3v3

concept:
using the adxl 335 we can control the system or device using the gestures
simply adxl 335 give the analog values that is connected with the arduino 
so simply arduno receive the values from the analog port by analogread..

by using your hand gestures you can control your home automation and industrial automation

code:

/*

 this is the program to demonstrate the simple

 "Control System Based On Gesture Recognition Using 3D MEMS Accelerometers"

 http://anildurgam.blogspot.com
 sponsred by the potentiallabs
 visit us
 http://potentiallabs.com/
 http://potentiallabs.com/cart
 */


//for controlling the motor directions
//we need 4 digital pins


//motor one control
//int motor1_d1 =7;
int motor1_d2 =8;

//motor two control
int motor2_d1 = 9;
int motor2_d2 = 7;

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

//The minimum and maximum values that came from
//the accelerometer while standing still
//You very well may need to change these
int minVal = 265;
int maxVal = 402;


//to hold the caculated values
double x;
double y;
double z;


//for particular direction
char dir_tion =0;

void setup()
{  

  Serial.begin(9600);
  Serial.print("Robot is ready...give directions");
  Serial.println("\n"); 
  Serial.println("calibrating the time....");
  Serial.println("\n"); 
  //motor pin ...analog pins
 // pinMode(motor1_d1,OUTPUT);
  pinMode(motor1_d2,OUTPUT);

  pinMode(motor2_d1,OUTPUT);
  pinMode(motor2_d2,OUTPUT);
  pinMode(xPin,INPUT);
  pinMode(yPin,INPUT);
  pinMode(zPin,INPUT);


 // digitalWrite(motor1_d1,LOW); 
  digitalWrite(motor1_d2,HIGH); 
  digitalWrite(motor2_d1,HIGH); 
  digitalWrite(motor2_d2,HIGH); 


}


void loop()
{

  //read the analog values from the accelerometer
  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);

  //Output the caculations
  Serial.print("x: ");
  Serial.print(x);
  Serial.print(" | y: ");
  Serial.print(y);
  Serial.print(" | z: ");
  Serial.println(z);

  delay(1000);//just here to slow down the serial output - Easier to read


  //robot move front...hand down..  
  if (x > 210 && x <=230 ) 
  {


    digitalWrite(motor2_d1,HIGH);  

 //   digitalWrite(motor1_d1,LOW); 
    digitalWrite(motor1_d2,LOW); 
    //  digitalWrite(motor2_d1,LOW); 
    digitalWrite(motor2_d2,LOW); 
    delay(1000);

  }

  //robot move right side......hand right ...
  else if(x > 190 && x <=210)
  {

    digitalWrite(motor1_d2,HIGH); 

    //  digitalWrite(motor1_d1,LOW); 
   // digitalWrite(motor1_d1,LOW); 
    digitalWrite(motor2_d1,LOW); 
    digitalWrite(motor2_d2,LOW);

    delay(1000);
  }

  //robot move left side.....hand left........
  else if(x >= 231 && x <= 250)
  {

    digitalWrite(motor2_d2,HIGH); 

   // digitalWrite(motor1_d1,LOW); 
    digitalWrite(motor1_d2,LOW); 
    digitalWrite(motor2_d1,LOW); 
   // digitalWrite(motor2_d2,LOW); 
    delay(1000);
  }




  //stop the robot
  else
  {
    //digitalWrite(motor1_d1,LOW); 
    digitalWrite(motor1_d2,LOW); 
    digitalWrite(motor2_d1,LOW); 
    digitalWrite(motor2_d2,LOW); 
  }

  delay(100);

}




above image shows the values received from the adxl335




python class topic video