Saturday, June 22, 2013

GY-651 (HMC5883L + BMP085) Compass+Barometric Pressure Module with Arduino or PIC

GY-651 (HMC5883L + BMP085) Compass+Barometric Pressure Module with Arduino or PIC



Key Feature: (copy from web)
GY-651 HMC5883LBMP085MWC Four-axis Flight Control Sensor Electronic Compass Atmospheric Module
Descriptions:
- Name: electronic compass atmospheric pressure module (three-axis magnetic field + pressure)
- Model: GY-651
- The use of chip: HMC5883L + BMP085
- Power supply :3-5v (internal low dropout regulator)
- Size: 13.5mm * 15.8mm (standard pitch 2.54mm)
- Communication modes: standard IIC communication protocol)
- Magnetic field range: ± 1.3 to ± 8.1 gauss
- Pressure Range :300-1100hPa
- Chip 12bit AD converter, 16-bit data output
- Machine welding process to ensure quality


Code:
Barometric Pressure

//From Datasheet and Website http://interactive-matter.eu/blog/2009/12/05/arduino-barometric-pressure-sensor-bmp085/
//Syed Razwanul Haque(Nabil)
//Dept of Physics,SUST
//www.fb.com/Nabilphysics

//Bangladesh
#include <Wire.h>

#define I2C_ADDRESS 0x77 //77?

const unsigned char oversampling_setting = 3; //oversamplig for measurement
const unsigned char pressure_waittime[4] = { 5, 8, 14, 26 };

//just taken from the BMP085 datasheet
int ac1;
int ac2;
int ac3;
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1;
int b2;
int mb;
int mc;
int md;


void setup()

  Serial.begin(9600);  // start serial for output
  Serial.println("Setting up BMP085");
  Wire.begin();
  bmp085_get_cal_data();
}
void bmp085_read_temperature_and_pressure(int& temperature, long& pressure);
void loop()
{
  int  temperature = 0;
  long pressure = 0;

  bmp085_read_temperature_and_pressure(&temperature,&pressure);
  Serial.print(temperature,DEC);
  Serial.print(" ");
  Serial.print(pressure,DEC);
  Serial.println();
  delay(100);
}

void bmp085_read_temperature_and_pressure(int* temperature, long* pressure) {
  int  ut= bmp085_read_ut();
  long up = bmp085_read_up();
   long x1, x2, x3, b3, b5, b6, p;
   unsigned long b4, b7;

   //calculate the temperature
   x1 = ((long)ut - ac6) * ac5 >> 15;
   x2 = ((long) mc << 11) / (x1 + md);
   b5 = x1 + x2;
   *temperature = (b5 + 8) >> 4;
  
   //calculate the pressure
   b6 = b5 - 4000;
   x1 = (b2 * (b6 * b6 >> 12)) >> 11;
   x2 = ac2 * b6 >> 11;
   x3 = x1 + x2;
   b3 = (((int32_t) ac1 * 4 + x3)<<oversampling_setting + 2) >> 2;
   x1 = ac3 * b6 >> 13;
   x2 = (b1 * (b6 * b6 >> 12)) >> 16;
   x3 = ((x1 + x2) + 2) >> 2;
   b4 = (ac4 * (uint32_t) (x3 + 32768)) >> 15;
   b7 = ((uint32_t) up - b3) * (50000 >> oversampling_setting);
   p = b7 < 0x80000000 ? (b7 * 2) / b4 : (b7 / b4) * 2;
  
   x1 = (p >> 8) * (p >> 8);
   x1 = (x1 * 3038) >> 16;
   x2 = (-7357 * p) >> 16;
   *pressure = p + ((x1 + x2 + 3791) >> 4);

}


unsigned int bmp085_read_ut() {
  write_register(0xf4,0x2e);
  delay(5); //longer than 4.5 ms
  return read_int_register(0xf6);
}

void  bmp085_get_cal_data() {
  Serial.println("Reading Calibration Data");
  ac1 = read_int_register(0xAA);
  Serial.print("AC1: ");
  Serial.println(ac1,DEC);
  ac2 = read_int_register(0xAC);
  Serial.print("AC2: ");
  Serial.println(ac2,DEC);
  ac3 = read_int_register(0xAE);
  Serial.print("AC3: ");
  Serial.println(ac3,DEC);
  ac4 = read_int_register(0xB0);
  Serial.print("AC4: ");
  Serial.println(ac4,DEC);
  ac5 = read_int_register(0xB2);
  Serial.print("AC5: ");
  Serial.println(ac5,DEC);
  ac6 = read_int_register(0xB4);
  Serial.print("AC6: ");
  Serial.println(ac6,DEC);
  b1 = read_int_register(0xB6);
  Serial.print("B1: ");
  Serial.println(b1,DEC);
  b2 = read_int_register(0xB8);
  Serial.print("B2: ");
  Serial.println(b1,DEC);
  mb = read_int_register(0xBA);
  Serial.print("MB: ");
  Serial.println(mb,DEC);
  mc = read_int_register(0xBC);
  Serial.print("MC: ");
  Serial.println(mc,DEC);
  md = read_int_register(0xBE);
  Serial.print("MD: ");
  Serial.println(md,DEC);
}


long bmp085_read_up() {
  write_register(0xf4,0x34+(oversampling_setting<<6));
  delay(pressure_waittime[oversampling_setting]);
 
  unsigned char msb, lsb, xlsb;
  Wire.beginTransmission(I2C_ADDRESS);
  Wire.send(0xf6);  // register to read
  Wire.endTransmission();

  Wire.requestFrom(I2C_ADDRESS, 3); // read a byte
  while(!Wire.available()) {
    // waiting
  }
  msb = Wire.receive();
  while(!Wire.available()) {
    // waiting
  }
  lsb |= Wire.receive();
  while(!Wire.available()) {
    // waiting
  }
  xlsb |= Wire.receive();
  return (((long)msb<<16) | ((long)lsb<<8) | ((long)xlsb)) >>(8-oversampling_setting);
}

void write_register(unsigned char r, unsigned char v)
{
  Wire.beginTransmission(I2C_ADDRESS);
  Wire.send(r);
  Wire.send(v);
  Wire.endTransmission();
}

char read_register(unsigned char r)
{
  unsigned char v;
  Wire.beginTransmission(I2C_ADDRESS);
  Wire.send(r);  // register to read
  Wire.endTransmission();

  Wire.requestFrom(I2C_ADDRESS, 1); // read a byte
  while(!Wire.available()) {
    // waiting
  }
  v = Wire.receive();
  return v;
}

int read_int_register(unsigned char r)
{
  unsigned char msb, lsb;
  Wire.beginTransmission(I2C_ADDRESS);
  Wire.send(r);  // register to read
  Wire.endTransmission();

  Wire.requestFrom(I2C_ADDRESS, 2); // read a byte
  while(!Wire.available()) {
    // waiting
  }
  msb = Wire.receive();
  while(!Wire.available()) {
    // waiting
  }
  lsb = Wire.receive();
  return (((int)msb<<8) | ((int)lsb));
}


 


Compass:




//For more details about the product please check http://www.seeedstudio.com/depot/


#include <Wire.h>
#include <math.h>

// Shift the device's documented slave address (0x3C) for write operation
// 1 bit right.This compensates for how the TWI library only wants the
// 7 most significant bits (with the high bit padded with 0)

#define HMC5883_WriteAddress 0x1E //  i.e 0x3C >> 1
#define HMC5883_ModeRegisterAddress 0x02
#define HMC5883_ContinuousModeCommand 0x00
#define HMC5883_DataOutputXMSBAddress  0x03

int regb=0x01;
int regbdata=0x40;

int outputData[6];

void setup()

    Serial.begin(57600);
    Wire.begin();       //Initiate the Wire library and join the I2C bus as a master

}

void loop() {

    int i,x,y,z;
    double angle;

    Wire.beginTransmission(HMC5883_WriteAddress);
    Wire.send(regb);
    Wire.send(regbdata);
    Wire.endTransmission();

    delay(1000);
    Wire.beginTransmission(HMC5883_WriteAddress); //Initiate a transmission with HMC5883 (Write address).
    Wire.send(HMC5883_ModeRegisterAddress);       //Place the Mode Register Address in send-buffer.
    Wire.send(HMC5883_ContinuousModeCommand);     //Place the command for Continuous operation Mode in send-buffer.
    Wire.endTransmission();                       //Send the send-buffer to HMC5883 and end the I2C transmission.
    delay(100);


    Wire.beginTransmission(HMC5883_WriteAddress);  //Initiate a transmission with HMC5883 (Write address).
    Wire.requestFrom(HMC5883_WriteAddress,6);      //Request 6 bytes of data from the address specified.

    delay(500);


    //Read the value of magnetic components X,Y and Z

    if(6 <= Wire.available()) // If the number of bytes available for reading be <=6.
    {
        for(i=0;i<6;i++)
        {
            outputData[i]=Wire.receive();  //Store the data in outputData buffer
        }
    }

    x=outputData[0] << 8 | outputData[1]; //Combine MSB and LSB of X Data output register
    z=outputData[2] << 8 | outputData[3]; //Combine MSB and LSB of Z Data output register
    y=outputData[4] << 8 | outputData[5]; //Combine MSB and LSB of Y Data output register


    angle= atan2((double)y,(double)x) * (180 / 3.14159265) + 180; // angle in degrees

    /*

  Refer the following application note for heading calculation.
  http://www.ssec.honeywell.com/magnetic/datasheets/lowcost.pdf 
  ----------------------------------------------------------------------------------------
  atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point
  given by the coordinates (x, y) on it.
  ----------------------------------------------------------------------------------------

  This sketch does not utilize the magnetic component Z as tilt compensation can not be done without an Accelerometer

  ----------------->y
  |
  |
  |
  |
  |
  |
 \/
  x



     N
 NW  |  NE
     | 
W----------E
     |
 SW  |  SE
     S

 */


    //Print the approximate direction

    Serial.print("You are heading ");
    if((angle < 22.5) || (angle > 337.5 ))
        Serial.print("South");
    if((angle > 22.5) && (angle < 67.5 ))
        Serial.print("South-West");
    if((angle > 67.5) && (angle < 112.5 ))
        Serial.print("West");
    if((angle > 112.5) && (angle < 157.5 ))
        Serial.print("North-West");
    if((angle > 157.5) && (angle < 202.5 ))
        Serial.print("North");
    if((angle > 202.5) && (angle < 247.5 ))
        Serial.print("NorthEast");
    if((angle > 247.5) && (angle < 292.5 ))
        Serial.print("East");
    if((angle > 292.5) && (angle < 337.5 ))
        Serial.print("SouthEast");

    Serial.print(": Angle between X-axis and the South direction ");
    if((0 < angle) && (angle < 180) )
    {
        angle=angle;
    }
    else
    {
        angle=360-angle;
    }
    Serial.print(angle,2);
    Serial.println(" Deg");
    delay(1);
}


 

Tuesday, April 23, 2013

Mini SD, Micro SD, SD card Operation using Arduino , PIC Microcontroller

See Pin Configuration before Operation. Wish You Happy Doctoring.....Open Your Arduino IDE .Then File>Example>SD>SD card info. Read the code carefully. Make sure you choose chip select pin correctly.








Friday, March 22, 2013

8*2 LCD & Arduino with Direct Serial Monitor

Connect a 8*2 LCD with Arduino. In Bangladesh NORduino Uno a clone of Arduino Uno is available at www.fb.com/OishiElectronicsSylhet . Then upload Following Code . Open Serial Monitor and Make Fun.
#include <LiquidCrystal.h>
//www.fb.com/OishiElectronicsSylhet
// Robi Kormokar (SUST Physics)
//www.fb.com/Nabilphysics(SUST Physics)
//Circuit : Connect a 8*2 LCD and Open Serial Monitor.Simply Type and See in LCD
LiquidCrystal lcd(2, 5, 6, 7, 9, 10);

char arr[16];
int j = 0;
int k = 0;

void setup() {
  Serial.begin(9600);
  lcd.begin(8, 2);
}

void loop() {

  if(Serial.available() > 0) {
    if(k == 0) {
      lcd.clear();
      k = 1;
    }
   
    if(j < 8) {
      arr[j] = Serial.read();
      lcd.setCursor(j, 0);
    }
    else if (j >= 8) {
      arr[j] = Serial.read();
      lcd.setCursor((j-8), 1);
    }
    lcd.print(arr[j]);
    j = j + 1;
  }
  delay(100);
  if(Serial.available() <= 0) {
   j = 0;
   k = 0;
  }
}

Thursday, March 14, 2013

SM-5100B GSM/GPRS Module with Arduino (with Power connection))

I will just Mention Some Photograph which will give you clear instruction. There is a good tutorial Tronixstuff . Be careful about power supply connection. I should recommend use external regulated 5V power supply. 5V have to apply SM-5100B Vin pin and +5V pin. GND must be common. If you have any query you can find me on Facebook www.fb.com/NabilPhysics or call me +8801717973140.

SM-5100B Successful connection  www.fb.com/Nabilphysics



Wednesday, March 13, 2013

DS-3231 Module Extremely Accurate RTC with Arduino and PIC

Coding and connection of DS-3231 is almost similar to popular DS-1307. But DS-3231 is extremely accurate. It has thermally compensating built in crystal on the other hand DS-1307 required external crystal as a result it is less accurate than DS-3231. Arduino has Popular library to use DS-3231. You need wire library , DS-1307 library and Time library to easily interface DS-3231 with Arduino. Accuracy of DS-3231 is super because crystal fluctuation is strongly managed. You have to very careful if you wanna made your own DS-1307 breakout board. because some crystal are not matched with DS-1307 although frequency is written correctly. I tried with some locally managed crystal but i got there is no time update but when i used a crystal from a old computer motherboard i got Everything working fine. I got 1 second error every 4 hours. most of the time every 4 hours 1 second less as it should be. Then i search and got DS-3231 which is absolutely what i want. If you wanna do some work professionally DS-3231 is a correct choice. In Bangladesh you can find DS-3231 at www.fb.com/OishiElectronisSylhet (+8801717973140) . There is a great tutorial Adafruit Tutorial .


www.fb.com/Nabilphysics   and www.fb.com/OishiElectronisSylhet


Sunday, March 10, 2013

Electronic Voting Machine

This is a Prototype of Electric Voting Machine. I made it just for Fun. But it is very useful. It can take vote,Can save vote, no problem if Electricity gone Even it can upload Voting Result To Election commission office server during every vote. I used Arduino to make it. Code below
EVM




#include <EEPROM.h>
#include <LiquidCrystal.h>
// Syed Razwanul Haque(Nabil)
// Shahjalal University of Scinece and Tech

(Bangladesh)
// www.ArduinoPic.blogspot.com
int reset=8;
int vote1=6;
int vote2=7;
int i=0;
int a=0;
int b=0;
int t=0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
            {  lcd.begin(16, 2);
               pinMode(reset, INPUT);
               pinMode(vote1, INPUT);
               pinMode(vote2, INPUT);
               pinMode(13, OUTPUT);
               lcd.setCursor(3, 0);
               lcd.print("ELECTRONIC");
               lcd.setCursor(1,1);
               lcd.print("VOTING MACHINE");
               delay(8000);
               lcd.setCursor(3, 0);
               lcd.print("          ");
               lcd.setCursor(1,1);
               lcd.print("              ");
            }
        
void loop(){
  int y=analogRead(A4);
  if(y>500)
      {
        EEPROM.write(0,0);
        EEPROM.write(1,0);
        EEPROM.write(2,0);
        digitalWrite(13,HIGH);
        lcd.setCursor(0, 0);
        lcd.print("Memory Cleared");
        lcd.setCursor(0,1);
        lcd.print("Ready For Voting");
             
        delay(8000);
        digitalWrite(13, LOW);
        lcd.setCursor(0, 0);
        lcd.print("              ");
        lcd.setCursor(0,1);
        lcd.print("                ");
       
      } 
            a= EEPROM.read(0);
            b=  EEPROM.read(1);
            t= EEPROM.read(2);
              lcd.setCursor(0, 0);
              lcd.print("Total Vote=");
              lcd.setCursor(11,0);
              lcd.print(t);
             
              lcd.setCursor(0, 1);
              lcd.print("Nabil=");
              lcd.setCursor(6,1);
              lcd.print(a);
             
              lcd.setCursor(8, 1);
              lcd.print("Isrq=");
              lcd.setCursor(14,1);
              lcd.print(b);
             
              int vote_1state=analogRead(A0);

//digitalRead(vote1);
              int vote_2state=analogRead(A5);     

            //digitalRead(vote2);
              int reset_state= digitalRead(reset);
             
      if(reset_state== HIGH)
        { i--;
        if(i==-1)
       {
         i=0;
         digitalWrite(13,HIGH);
       }
        }
         if(vote_1state>2 && i==0 &&

vote_2state<1)
             {
              a++;
              lcd.setCursor(0, 1);
              lcd.print("Nabil=");
              lcd.setCursor(6,1);
              lcd.print(a);
              delay(300);
              EEPROM.write(0,a);
              t++;
              delay(300);
              EEPROM.write(2,t);
              lcd.setCursor(0, 0);
              lcd.print("Total Vote=");
              lcd.setCursor(11,0);
              lcd.print(t);
              delay(15000);
             
             
             }
             if(vote_2state >2 && i==0 &&

vote_1state<1)
              {
              b++;
               lcd.setCursor(8, 1);
              lcd.print("Isrq=");
              lcd.setCursor(14,1);
              lcd.print(b);
              delay(300);
             EEPROM.write(1,b);
              t++;
              delay(300);
              EEPROM.write(2,t);
              lcd.setCursor(0, 0);
              lcd.print("Total Vote=");
              lcd.setCursor(11,0);
              lcd.print(t);
              delay(15000);
             }
           
          if(vote_1state >2 || vote_2state>2) 
               for(i=0;i<2;i++)
               if(i!=0)
               digitalWrite(13, LOW);
              
      delay(300); 
}  

Monday, March 4, 2013

74hc595 Protious Simulation

Protious Simulation to understand basic working mechanism of 74hc595 Shift Register. (Syed Razwanul Haque Nabil)

Download : Click Here  


sim-548 Interfacing without Breakout Board with Arduino and PIC Microcontroller

sim-548 Interfacing without Breakout Board with Arduino and PIC Microcontroller : : by Syed Razwanul Haque (Nabil)

Please Download the image and Rotate Clockwise. You have to very careful while Soldering.. Module Tx will be connected with Arduino Rx and Module Rx will be conected with Arduino Tx. I used a nokia 3.7V battery for Power . Power key should be connected with Push button. Other pin of push button should be connected with Ground. For status LED +ve of LED should be connected with PIN 16 of gsm module and negative with Ground.Dont forget to use LM2576 power IC for power supply as recommended in datasheet. a Code Below :


 
www.fb.com/Nabilphysics
Code : For Arduino
//OISHI electronics sylhet,Bangladesh. www.fb.com/OishiElectronicsSylhet
//Syed Razwanul haque(Nabil) and Robi Kormoker www.fb.com/Nabilphysics +8801717973140
//Shahjalal University of Science and Technology (www.sust.edu)
//Department of Physics
// Code for Arduino 0023
// Download NewSoftSerial library from www.arduino.cc
#include <NewSoftSerial.h>  //Include the NewSoftSerial library to send serial commands to the cellular module.

char r=13;  //return character
NewSoftSerial cell(2,3);  //Create a 'fake' serial port. Pin 4 is the Rx pin, pin 3 is the Tx pin.
String cellContent="";   //string we're sending
String ctlZ="\x1A";     //the code for Ctrl-Z

String content="Test Massage";    //The text I'm sending

void setup() {

  // start the serial library:
  Serial.begin(9600);
  cell.begin(9600);

}

void loop()
{

//add our message to the CellContent string
  cellContent+=content;
//add the Crtl-Z hex character 
  cellContent+=ctlZ;
//put the modem into text mode 
  textMode();
//wait for a moment 
  delay(50);
//send message 
  sendMsg();

cellContent="";
delay(60000);

}

void textMode()
{
  //init text mode
  cell.print("AT+CMGF=1");
  cell.print(r);
}

void sendMsg(){
//This number needs to be replaced with the number you are sending to 
  cell.print("AT+CMGS=\"01717973140\"");
  cell.print(r);
  cell.print(cellContent);
  cell.print(r);
}

Sunday, March 3, 2013

Q2406 , Q2303 Similar wavecom GSM Modem Interface with Arduino

Q2406,Q2303 Similar wavecom GSM Modem Interfacing with Arduino: (Syed Razwanul Haque Nabil )
www.fb.com/Nabilphysics    www.fb.com/OishiElectronicsSylhet
This is a very simple way to interface Q2303 or similar wavecom module with Arduino. Connect Tx of Modem with Arduino Rx and Rx of Modem with Arduino Tx pin (Software Rx, Tx). Power up Modem with Adapter(5V, 1A). Insert SIM. Make sure modem switch is on. Modem GND must be connected with Arduino GND. I draw a picture for Interfacing with Arduino. I tested it. Code is below.


//OISHI electronics sylhet,Bangladesh. www.fb.com/OishiElectronicsSylhet
//Syed Razwanul haque(Nabil) and Robi Kormoker www.fb.com/Nabilphysics +8801717973140
//Shahjalal University of Science and Technology (www.sust.edu)
//Department of Physics
// Code for Arduino 0023
// Download NewSoftSerial library from www.arduino.cc
#include <NewSoftSerial.h>  //Include the NewSoftSerial library to send serial commands to the cellular module.

char r=13;  //return character
NewSoftSerial cell(2,3);  //Create a 'fake' serial port. Pin 4 is the Rx pin, pin 3 is the Tx pin.
String cellContent="";   //string we're sending
String ctlZ="\x1A";     //the code for Ctrl-Z

String content="Test Massage";    //The text I'm sending

void setup() {

  // start the serial library:
  Serial.begin(9600);
  cell.begin(9600);

}

void loop()
{

//add our message to the CellContent string
  cellContent+=content;
//add the Crtl-Z hex character 
  cellContent+=ctlZ;
//put the modem into text mode 
  textMode();
//wait for a moment 
  delay(50);
//send message 
  sendMsg();

cellContent="";
delay(60000);

}

void textMode()
{
  //init text mode
  cell.print("AT+CMGF=1");
  cell.print(r);
}

void sendMsg(){
//This number needs to be replaced with the number you are sending to 
  cell.print("AT+CMGS=\"01717973140\"");
  cell.print(r);
  cell.print(cellContent);
  cell.print(r);
}

Animated Digital Clock with PIC microcontroller and DS-3231 RTC




Animated Digital Clock with PIC microcontroller and DS-3231 RTC

In this clock their is two unit. One unit is for animated second and other for normal hour and minute. For Hour and clock PIC16F72 and for animated second PIC16F877 has been used. For real time their is a DS-3231 RTC (Real Time Clock) which has built in thermal compensating clock. DS-3231 interface using I2C . DS-3231 give pulse to second circuit to change second. Its a very good looking CLOCK. Its now a commercial product of OISHI Electronics, Sylhet, Bangladesh (www.facebook.com/OishiElectronicsSylhet). I suggest all to use DS-3231 instead of DS-1307 . Me and my teacher with my student we made also Arduino version of this clock. Thanks All. Further query : +8801717973140 Facebook: www.fb.com/Nabilphysics 

Syed Razwanul Haque (Nabil)
Msc Student and Microcontroller circuit designer ,Programmer and Project planer at OISHI Electronics
Department of Physics
Shahjalal University of Science and Technology, Sylhet, Bangladesh (www.sust.edu)

Saturday, March 2, 2013

NORduino UNO (Clone of Arduino UNO)

NORduino Uno is clone of Arduino UNO. It is available in Bangladesh market(only @ 1200TK). Please see our page www.facebook.com/OishiElectronicsSylhet I designed it with help of OISHI Electronics Sylhet, Bangladesh and with my student Robi Kormoker(SUST-Physics Department ) I mentioned below schematic although its not exact schematic of  NORduino but it will make you understand to design it with help of NORduino .

This is a Arduino Uno schematic(collected).my another blog www.nabilphysics.blogspot.com

Thursday, February 28, 2013

PIC osciloscope and Developement Board

This is simplest  PIC development board work like Arduino it has bootloader so we can upload firmware easily . It is also a PC based oscilloscope with khz accuracy. Download code and schamatic  Click Here to Download

Tuesday, February 26, 2013

Touch Fan Regulator With PIC Microcontroller

Touch Fan Regulator With PIC Microcontroller

This is a Touch Fan Regulator. We can control Speed Level 0 to 5 just with Touch . I will add details .....