Pages: [1]   Go Down
Author Topic: Maxbotix sonar (analog) Working code  (Read 2959 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Running thru A/D
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

(dunno if this is the right place to post)

I tried to use the Devantech SRF08 I2C sonar but with no luck
(check the forum, no one replied to my request for help so I suppose it's impossible to use
as the I2C/TWI code is too big for the small Arduino's memory).
Finally I got this Maxbotix ultrasonic range finder and
used the analog output to connect it to Arduino.

Notice: This is a rework of the code for the Parallax PING,
they say it works with the Maxbotix sensor too
but I couldn't understand which sensor output they use.
Go analog, simple and smooth.
Enjoy,
GiovanniConti

conti.gio@gmail.com


/*

+++ Maxbotix ultrasonic range finder +++

- Sensor is connected to arduino ANALOG-0
- Range in centimeters = (val * 1,24)
- A led connected to DIGITAL-13 blinks, speed is proportional to the sensed value
 --- > share your knowledge < ---
 
 (( Lorenzo + Giovanni ) Conti ) 18/06/2006
 
 
 */


int ultraSoundSignal = 0; // Ultrasound signal pin ANALOG-0
int val = 0;
int ultrasoundValue = 0;
int ledPin = 13;                 // LED connected to DIGITAL-13

void setup() {
  beginSerial(19200);                  // Sets the baud rate to 19200
  pinMode(ledPin, OUTPUT);      // sets the DIGITAL-13 pin as output  
  
}

void loop() {
 val = 0;

pinMode(ultraSoundSignal, INPUT); // Switch signalpin ANALOG-0 to input
val = analogRead(ultraSoundSignal); // Append signal value to val

digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(val);                  // waits, proportional to the sensed value
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(val);                  // waits, proportional to the sensed value

/* Writing out values to the serial port
 * -------------------------------------------------------------------
 */
 
ultrasoundValue = val; // Append analog read to ultrasoundValue

serialWrite('A'); // Example identifier for the sensor
printInteger(ultrasoundValue);
serialWrite(10);
serialWrite(13);


/* Delay of program
 * -------------------------------------------------------------------
 */
delay(100);
}
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is great.  I've been looking for this exact help.

I'm a newbie... very much a newbie, (artist) but with limited electronics background.  I've been trying to incorporate more electronics into my work and I was wondering if you might be able to help me.

I don't suppose you have a photo of your setup, or possibly just a schematic of how you set things up to work?   :question

  [smiley=dankk2.gif]

/me
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

BTW, the size of the Arduino libraries has shrunk in 0005, so the TWI/I2C library should fit with a little bit of space left over for your program.  Maybe the Devantech SRF08 is worth another try?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 25
Running thru A/D
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@aztlan2k:

sorry for the delay,
with maxbotix ez-1 you only have 3 wires between the sensor and arduino,
the 5v+ and ground going from arduino to the sensor +/-
and the analog output from the sensor going to an analog input pin on arduino,
then simply use the code I proveded in the forum (search for srf08 or maxbotix)
and you are ready to rock...
beware of the cable length!
as you're going to use an analog signal voltage,
long cables will introduce lot of noise in the signal,
i used 10m once but the readings were very noisy,
look on the maxbotix website, in the faq they explain how you can reduce noise using a resistor and a capacitor...
hope this helps you,
have bright days
gio
Logged


Pages: [1]   Go Up
Jump to: