"Arduino Official Tutorial First series" Sample program 6-3 Memsic2125 Accelerometer _arduino

Source: Internet
Author: User
Memsic2125 Acceleration Meter

MEMSIC2125 is a two-axis accelerometer that can measure the acceleration of positive or negative 2g in two directions (g represents the gravitational acceleration). Its pin design is simple: Only two data output pins, one for the x axis and one for the Y axis. Its data output pins will output different pulse widths according to the size of the acceleration (do not know what the pulse width is please see this article). The subtle level of pulse width can be measured by pulseln () to obtain the acceleration data by calculation. Complete the hardware equipment required for this example Arduino board or Genuino board Memsic 2125 Accelerometer jumper bread plate connecting line circuit

First, use the small triangle on the Memsic2125 to correctly insert the sensor on the bread plate. Connect the Memsic2125 +v and Gnd to +5v and GND, respectively. The number 2nd pin first received xout, the number 3rd pin first received yout.

Your Arduino or Genuino board must be connected to the computer to see the results on the serial monitor. Schematic diagram

Routine code

Open the Arduino IDE's serial monitor to see the effect.

/*
   Memsic2125

   reads the pulse width of the memsic 21,252-axis accelerometer and converts it to the real acceleration and outputs it to the serial monitor.

   Circuit Construction:
    * Xout received number 2nd digital PIN
    * Yout received 3rd digital pin
    * +V received +5v
    * GND received GND

   code public */

/immutable constant:
const int xpin = 2;     Acceleration X-Axis Output
const int ypin = 3;     Acceleration Y-Axis output

void Setup () {
  //init serial connection:
  Serial.begin (9600);
  The initial acceleration pin is the output mode:
  Pinmode (Xpin, INPUT);
  Pinmode (Ypin, INPUT);

void Loop () {
  //storage pulse width variable:
  int pulsex, Pulsey;
  Variables for storing acceleration:
  int Accelerationx, accelerationy;

  Read the pulse width above the x\y:
  pulsex = Pulsein (Xpin, high);
  Pulsey = Pulsein (Ypin, high);

  Converting the pulse width to the
  acceleration//x and the Y axis will be output by the gravitational acceleration of (MILLI-G):
  //In accordance with this unit the gravity acceleration of the earth is 1000g, or LG.
  Accelerationx = ((PULSEX/10)-$) * 8;
  Accelerationy = ((PULSEY/10)-$) * 8;

  Output acceleration Data
  serial.print (Accelerationx);
  Output a tab character:
  serial.print ("T");
  Serial.print (accelerationy);
  Serial.println ();

  Delay (MB);
Related information

Pinmode ()
Pulsein ()
Serial.begin ()
Serial.print ()
ADXL3XX: Read the adxl3xx accelerometer.
Detection of collisions using piezoelectric elements: piezoelectric components are used to detect collisions.
The original title is knock
Memsic2125: two-axis accelerometer.
Ping: Use ultrasonic to detect the distance of an object.

Original link update process date log translator June 27, 2016 create and translate documents Steven

Translator: Steven
Email: gammapi@qq.com
Reprint please indicate the source, all just because of love.
I hope you can point out your valuable opinions, thank you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.