Professional Documents
Culture Documents
SYSTEMS
GROUP 8
MATERIALS NEEDED
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() {
Serial.begin(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);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
MATERIALS NEEDED
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() {
Serial.begin(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;
Serial.print(accelerationX);
Serial.print("\t");
Serial.print(accelerationY);
Serial.println();
delay(100);
}