Oh ok. Thank you. Well at the moment I have the sensor hooked to a breadboard for testing/learning the code. I have found a sketch...below...and it works fine, but it simply (well maybe not so simply lol) just sends the cm/inches to the serial monitor. I have tried altering the sketch to read the input of ECHO_PIN and turn on an LED when it reads 12 inshes or less. With no success. Trig is pin 10 and Echo is pin 11, LED is hooked to pin 13 (onboard). BTW my robot is a 2 wheel/2 casters where the 2 wheels are drive and steering. Basically just a platform atm.
/* YourDuino SKETCH UltraSonic Serial 1.0
Runs HC-04 and hopefully SRF-06 Ultrasonic Modules
Uses: Ultrasonic Library (Copy to Arduino Library folder)
http://iteadstudio.com/store/images/produce/Sensor/HCSR04/Ultrasonic.rar terry@yourduino.com */
/*-----( Import needed libraries )-----*/
#include "Ultrasonic.h"
/*-----( Declare Constants and Pin Numbers )-----*/
#define TRIG_PIN 10
#define ECHO_PIN 11
/*-----( Declare objects )-----*/
Ultrasonic OurModule(TRIG_PIN, ECHO_PIN);
/*-----( Declare Variables )-----*/
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
Serial.println("UltraSonic Distance Measurement");
Serial.println("YourDuino.com
terry@yourduino.com");
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
Serial.print(OurModule.Ranging(CM));
Serial.print("cm ");
delay(100); //Let echos from room dissipate
Serial.print(OurModule.Ranging(INC));
Serial.println("inches");
delay(500);
}//--(end main loop )---
/*-----( Declare User-written Functions )-----*/
And heres the scetch I've tried to alter it to.
/*-----( Import needed libraries )-----*/
#include "Ultrasonic.h"
/*-----( Declare Constants and Pin Numbers )-----*/
#define TRIG_PIN 10
#define ECHO_PIN 11
#define LED 13
/*-----( Declare objects )-----*/
Ultrasonic OurModule(TRIG_PIN, ECHO_PIN);
/*-----( Declare Variables )-----*/
int sensor_upper_limit = 12;
int sensor = 0;
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
Serial.println("UltraSonic Distance Measurement");
Serial.println("YourDuino.com
terry@yourduino.com");
pinMode(LED, OUTPUT);
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
Serial.print(OurModule.Ranging(CM));
Serial.print("cm ");
delay(100); //Let echos from room dissipate
Serial.print(OurModule.Ranging(INC));
Serial.println("inches");
delay(500);
sensor = analogRead(ECHO_PIN);
if(sensor_upper_limit > sensor){
digitalWrite(LED, HIGH);
}else{
digitalWrite(LED, LOW);
}
}
/*-----( Declare User-written Functions )-----*/