0% found this document useful (0 votes)
3 views16 pages

Ultrasonic Rangefinder & Accelerometer Guide

This document describes how to use an ultrasonic rangefinder and accelerometer with an Arduino. It provides instructions on connecting a PING ultrasonic rangefinder and MEMSIC 2125 dual-axis accelerometer to an Arduino, and includes code to read distance measurements from the rangefinder and acceleration values from the accelerometer and print them over a serial connection. The rangefinder works by sending and receiving ultrasonic pulses to determine distance to objects, while the accelerometer outputs pulses corresponding to g-forces that are converted to milli-g values.

Uploaded by

Reymar Belmonte
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views16 pages

Ultrasonic Rangefinder & Accelerometer Guide

This document describes how to use an ultrasonic rangefinder and accelerometer with an Arduino. It provides instructions on connecting a PING ultrasonic rangefinder and MEMSIC 2125 dual-axis accelerometer to an Arduino, and includes code to read distance measurements from the rangefinder and acceleration values from the accelerometer and print them over a serial connection. The rangefinder works by sending and receiving ultrasonic pulses to determine distance to objects, while the accelerometer outputs pulses corresponding to g-forces that are converted to milli-g values.

Uploaded by

Reymar Belmonte
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

MICROPROCESSOR

SYSTEMS
GROUP 8

PING ULTRASONIC RANGEFINDER


This sketch reads a PING ultrasonic rangefinder
and returns the distance to the closest object in
range
it sends a pulse to the sensor to initiate a reading,
then listens for a pulse to return.
The length of the returning pulse is proportional to
the distance of the object from the sensor.

MATERIALS NEEDED

Gizduino AT-Mega 644


Ping Ultrasonic Range Finder (4 pins)
Connecting Wires

THE CIRCUIT
Vcc connection of the PING attached to +5V
Gnd connection of the PING attached to ground
Trig connection of the PING attached to digital
pin 7
Echo connection of the PING attached to digital
pin 6

CODE
const int pingPin = 7;
const int echo = 6;
void setup() {
[Link](9600);
}

void loop() {
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(echo, INPUT);
duration = pulseIn(echo, HIGH);

inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
[Link](inches);
[Link]("in, ");
[Link](cm);
[Link]("cm");
[Link]();
delay(100);
}

long microsecondsToInches(long microseconds) {


return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds) {
return microseconds / 29 / 2;
}

MEMSIC 2125 DUAL-AXIS ACCELEROMETER

Converts the pulses output by the 2125 into


milli-g's (1/1000 of earth's gravity) and prints
them over the serial connection to the
computer.

MATERIALS NEEDED

Gizduino AT-Mega 644


MEMSIC 2125 Dual-Axis Accelerometer
Connecting Wires

THE CIRCUIT
X output of accelerometer to digital pin 2
Y output of accelerometer to digital pin 3
+V of accelerometer to +5V
GND of accelerometer to ground

CODE
const int xPin = 2;
const int yPin = 3;
void setup() {
[Link](9600);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
}

void loop() {
int pulseX, pulseY;
int accelerationX, accelerationY;
pulseX = pulseIn(xPin, HIGH);
pulseY = pulseIn(yPin, HIGH);
accelerationX = ((pulseX / 10) - 500) * 8;
accelerationY = ((pulseY / 10) - 500) * 8;

[Link](accelerationX);
[Link]("\t");
[Link](accelerationY);
[Link]();
delay(100);
}

You might also like