Friday, 28 September 2012

Week 9 FYP 2 : Troubleshoot the Programming


Problem Occured
  • After soldering and testing the accelerometer, the degree of standing still the accelerometer is strayed from 90°. 
  • To solved the problem, the accelerometer need to be calibrated so the degree of standing still is stayed on 90 °. By doing this, the programming code need to change a bit.
#include <Servo.h> 

Servo leftServo, rightServo;

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

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

  • The red lettering shows the value that need to be calibrated.

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

void setup(){
  Serial.begin(9600);
  leftServo.attach(9);
  rightServo.attach(8);
}

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);
  //////////////////////////
  
  /*  
  Serial.print("x: ");
  Serial.print(xRead);
  Serial.print(" | y: ");
  Serial.print(yRead);
  Serial.print(" | z: ");
  Serial.println(zRead);
  */
  
  //Left motor
  if ((z <= 50) && (z > 30))
  {
     leftServo.write(50);
  }
  else if ((z <= 30) && (z > 0))
  {
    leftServo.write(30);
  }
  else if ((z >= 270) && ( z <= 360))
  {
    leftServo.write(30);
  }
  else
  {
    leftServo.write(90);
  }
  
  
  /////////////////
  //right motor
  if ((z >= 130) && (z < 150))
  {
     rightServo.write(130);
  }
  else if ((z >= 150) && (z < 270))
  {
    rightServo.write(150);
  }
  else
  {
    rightServo.write(90);
  }
  delay(100);//just here to slow down the serial output - Easier to read
}

Thursday, 13 September 2012

Saturday, 1 September 2012

Week 5 FYP 2 : Design the Programming


  • The programming is design to control the servo motor which is the servo motor acts an output while the accelerometer acts as an input.




#include <Servo.h>

Servo leftServo, rightServo;

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

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

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

void setup(){
  Serial.begin(9600);
  leftServo.attach(9);
  rightServo.attach(8);
}

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);

  /*
  Serial.print("x: ");
  Serial.print(xRead);
  Serial.print(" | y: ");
  Serial.print(yRead);
  Serial.print(" | z: ");
  Serial.println(zRead);
  */

  //Left motor
  if ((z <= 40) && (z > 20))
  {
     leftServo.write(50);
  }
  else if ((z <= 20) && (z > 0))
  {
    leftServo.write(30);
  }
  else
  {
    leftServo.write(90);
  }
  /////////////////
  //right motor
  if ((z >= 120) && (z < 140))
  {
     rightServo.write(130);
  }
  else if ((z >= 140) && (z < 180))
  {
    rightServo.write(150);
  }
  else
  {
    rightServo.write(90);
  }
  delay(100);//just here to slow down the serial output - Easier to read
}





  • This is the arduino software that used to design a program. 
  • The software can be downloaded at www.arduino.cc


Arduino software to design a program



Saturday, 25 August 2012

Week 4 FYP 2 : Design the Flowchart


  • Flowchart for Arduino




Details on the component
Arduino Dueminalove

  • Arduino can sense the environment by receiving an input from a variety of sensors and can affect its surroundings by controlling lights, motors and other actuators.

Servo Motor                      
  • The nature of Servo motor which allow user to control its rotation angle
  • In this project, the servo motor will attached to the car's headlight in order to rotate the car headlight to a desired angle. 
  • The servo motor as an output



  •  It can measure the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion
  • In this project, the accelerometer use as a motion sensor which it will attached to the car steering.
  • The accelerometer as an input.
                                                                     















Friday, 17 August 2012

Week 3 FYP 2 : Purchasing the Component


LIGHT ACTIVATED RELAY
Item No.
Product
Qty
Unit Price  
     Amount
1
RELAY 9V DC
1 PC
RM6.50
RM   6.50
2
RESISTOR :1K, 1K5 1/4W
3 PCS
RM0.10
RM   0.30
3
DIODE IN4007
1 PC
RM0.50
RM   0.50
4
ZENER DIODE 8.2V
1 PC
RM1.00
RM   1.00
5
TRANSISTOR BC547
1 PC
RM2.00
RM   2.00
6
TRANSISTOR BC557
1 PC
RM2.80
RM   2.80
7
NTC THERMISTOR
1 PC
RM8.00
RM   8.00
8
TRIMMER 100K
1 PC
RM5.00
RM   5.00
9
IC REGULATOR 7806
1 PC
RM2.50
RM   2.50
10
ELECTROLYTIC CAP 1000uF
1 PC
RM3.00
RM   3.00
11
SCREW BLK CONNECTOR 2 WAY
  1 PC
RM2.00
RM   2.00
12
SCREW BLK CONNECTOR 3 WAY
1 PC
RM3.00
RM   3.00
13
JUMPER WIRE & POWER  CABLE
1 PKT
RM5.00
RM   5.00
                                        TOTAL  :
RM   36.60


 PHOTOTRANSISTOR ACTIVATED SWITCH
1
RELAY 12V DC
1 PC
RM6.50
RM   6.50
2
DIODE IN4007
1 PC
RM0.50
RM   0.50
3
RESISTOR 1K, 2M7, 3K9,
4 PCS
RM0.10
RM   0.40
4
LED
1 PC
RM0.30
RM   0.30
5
TRANSISTOR  C1815
2 PCS
RM2.00
RM   4.00
6
TRIMMER 1M
1 PC
RM5.00
RM   5.00
7
PHOTOTRANSISTOR  PT-334-6C
1 PC
RM18.00
RM 18.00
8
SCREW BLK CONNECTOR 2 WAY
2 PCS
RM2.00
RM   4.00
9
SCREW BLK CONNECTOR 3 WAY
3 PCS
RM3.00
RM   9.00
11
JUMPER WIRE & POWER  CABLE
1 PKT
RM5.00
RM   5.00
                                        TOTAL  :
RM   52.70



1
ARDUINO DUEMILANOVE
1 PC
RM87.00
RM   87.00
2
SERVO MOTOR CYTRON C36R
2 PCS
RM40.00
RM   80.00
3
ACCELEROMETER-ADXL335
1 PC
RM120.00
RM   120.00
4
CAR BATTERY 12V 40A
1 PC
RM150.00
RM   150.00
                               TOTAL  :
RM   437.00



  • The total cost for all the component is RM526.30