Interfacing Arduino dengan Sensor Kompas (CMPS03)


Download Library


PROGRAM KOMPAS DENGAN LIBRARY


#include "Wire.h"
#include "CMPS03.h"

CMPS03 cmps03;

void setup()
{
  Serial.begin(9600);
  Wire.begin();
}

void loop()
{
  Serial.println(cmps03.read());
  delay(1000);
}

PROGRAM KOMPAS TANPA LIBRARY


#include <Wire.h>
#define address 0x60

void setup()
{ 
 Wire.begin();
 Serial.begin(9600);
}
void loop()
{
  byte highByte;
  byte lowByte;
  
  Wire.beginTransmission (address);
  Wire.send(2);
  Wire.endTransmission();
  
  Wire.requestFrom(address, 2);
  while(Wire.available() < 2);
  highByte=Wire.receive();
  lowByte=Wire.receive();
  float bearing=(highByte<<8)+lowByte);
  bearing = bearing/10;
  
  Serial.print(bearing);
  Serial.print("\xB0\t");// penampilan karakter derajat  
  Serial.println(); //enter
  delay(100);  
}

Previous
Next Post »

1 comments:

Click here for comments
Anonymous
admin
March 20, 2012 at 12:22 PM ×

gan, bagaimana ya caranya mengatasi posisi lapangan yang diputar pada lapangan krci jika robotnya memakai kompas?

Congrats bro Anonymous you got PERTAMAX...! hehehehe...
Reply
avatar
Thanks for your comment