add right sonar sketch and fritzing diagram
authordaniel watson <ozzloy@gmail.com>
Fri, 8 Nov 2013 01:33:32 +0000 (17:33 -0800)
committerdaniel watson <ozzloy@gmail.com>
Fri, 8 Nov 2013 01:33:32 +0000 (17:33 -0800)
arduino-sketches/right_sonar/right-sonar.fzz [new file with mode: 0644]
arduino-sketches/right_sonar/right_sonar.ino [new file with mode: 0644]

diff --git a/arduino-sketches/right_sonar/right-sonar.fzz b/arduino-sketches/right_sonar/right-sonar.fzz
new file mode 100644 (file)
index 0000000..2c08bb2
Binary files /dev/null and b/arduino-sketches/right_sonar/right-sonar.fzz differ
diff --git a/arduino-sketches/right_sonar/right_sonar.ino b/arduino-sketches/right_sonar/right_sonar.ino
new file mode 100644 (file)
index 0000000..3d4af2e
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+int right_echo_pin = 6;
+int right_trigger_pin = 7;
+
+int ping_microseconds = 0;
+double sound_cm_per_microsecond_at_sea_level = 0.034029;
+int count = 0;
+
+void setup(){
+  Serial.begin(9600);
+  pinMode(right_echo_pin, INPUT);
+  pinMode(right_trigger_pin, OUTPUT);}
+
+void loop(){
+  // make sure trigger pin is off, a.k.a. LOW
+  digitalWrite(right_trigger_pin, LOW);
+  delayMicroseconds(2);
+
+  // send a 10 microsecond HIGH pulse to the trigger pin
+  digitalWrite(right_trigger_pin, HIGH);
+  delayMicroseconds(10); // leave the pin on for 10 microseconds
+  digitalWrite(right_trigger_pin, LOW);
+
+  ping_microseconds = pulseIn(right_echo_pin, HIGH);
+
+  // wait for the sonar sensor hardware to recover from pinging
+  delayMicroseconds(50);
+
+  // print out the pulse time
+  Serial.print(ping_microseconds);
+  Serial.print(" = ping time (microseconds), ");
+  Serial.print(ping_microseconds * sound_cm_per_microsecond_at_sea_level / 2);
+  Serial.print(" = distance (cm). #");
+  Serial.println(count++);
+
+  // wait so it's easier to read the serial monitor.
+  // change delay to 0 for fullspeed.
+  //  default is 333, which is about 1/3 of a second
+  delay(333);}