Show Posts
Pages: [1] 2 3 ... 7
1  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: January 02, 2013, 02:40:14 pm
Hello.. i wrote a code that uses this library, and isn't 100% reliable when debugging...
I'd be grateful if you comment it.

1) TRIG_PIN_L, TRIG_PIN_R, ECHO_PIN_L and ECHO_PIN_R are never defined.
2) No reason to set the pin modes, NewPing does that for you.
3) You shouldn't set the maximum distance to 2000cm on the "NewPing SONAR" lines.  The sensor won't work beyond 500cm and setting it to 2000 could make the time between pings from 33ms to 115ms or just cause problems in general.  Just remove the ,2000 and it will default to the sensor's maximum distance, which is 500cm and will allow for 33ms between pings as you have it set.
4) The "constrain" commands will give you problems as out of range results (which are zero) would change to 6.  Out of range would typically be beyond 500cm, making it 6cm will probably not give you want you're looking for.  Instead, do something like "if (per_l > 0) per_l = constrain(per_l, MIN_DISTANCE, MAX_DISTANCE);" so there can still be a zero result (out of range).
5) The rest of your code then needs to accommodate what to do with out of range results.  It doesn't appear that you have considered that.  If anything, a zero result should be changed to MAX_DISTANCE + 1, as that's what it means.  Without considering a zero result (out of range), your sketch will probably never work.

That should give you a good start to diagnose what's going on.  1, 3, 4 & 5 are real problems that will seriously cause problems for your sketch.

Tim

thank you sir

EDIT: I got everything to work now... I hope it will run flawlessly in the real life... Thanks again
2  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: January 02, 2013, 01:26:45 pm
Hello.. i wrote a code that uses this library, and isn't 100% reliable when debugging...
I'd be grateful if you comment it.
Code:
#include <NewPing.h>

#define BAUD 9600
#define MIN_DISTANCE 6      //Minimum distance to ping (cm)
#define MAX_DISTANCE 60     //Maximum distance to ping (cm)
#define THRESHOLD 10        //Treshold (cm)
#define HOLD_TIME 15        //Delay between each step (ms)
#define STEP_TIME 33        //Delay between ultrasonic's

//Creating ultrasonic objects
NewPing SONAR_L(TRIG_PIN_L, ECHO_PIN_L, 2000);
NewPing SONAR_R(TRIG_PIN_R, ECHO_PIN_R, 2000);

//Creating debugg function
void debugg(int val_l, int val_r)
{
  Serial.print(val_l);
  Serial.print(" ");
  Serial.print(val_r);
  Serial.println();
}

//Creating setup function
void setup()
{
  Serial.begin(BAUD);
  
  pinMode(ECHO_PIN_L, INPUT);
  pinMode(ECHO_PIN_R, INPUT);
  pinMode(TRIG_PIN_L, OUTPUT);
  pinMode(TRIG_PIN_R, OUTPUT);
}

//Program
void loop()
{
  //Declaring local static variables
  static bool hold = false;
  static int val_l, val_r;
  static int per_l, per_r;
  static int prev_per_l = MIN_DISTANCE, prev_per_r = MIN_DISTANCE;

  //Reading ultrasonic values
  delay(STEP_TIME);
  unsigned int uS1 = SONAR_L.ping();
  per_l = uS1 / US_ROUNDTRIP_CM;
  
  delay(STEP_TIME);
  unsigned int uS2 = SONAR_R.ping();
  per_r = uS2 / US_ROUNDTRIP_CM;
  
  //Limiting the effective range of ultrasonics
  per_l = constrain(per_l, MIN_DISTANCE, MAX_DISTANCE);
  per_r = constrain(per_r, MIN_DISTANCE, MAX_DISTANCE);
  
  //This part of code is used to save the distance of ultrasonic sensors
  //when the hand is moved away from the beam ) ) ) of the sensor
  if( (per_l - prev_per_l) > THRESHOLD )
  {
    per_l = prev_per_l;
    hold=false;
  }

  if( (per_r - prev_per_r) > THRESHOLD )
  {
    per_r = prev_per_r;
    hold=false;
  }
  
  prev_per_l = per_l;
  prev_per_r = per_r;

  //Modifying the data using linear math (used for servo motors)
  per_l = map(per_l, MIN_DISTANCE, MAX_DISTANCE, 100, 0);

  val_l = map(per_r, MIN_DISTANCE, MAX_DISTANCE, 90, 0);
  val_r = map(per_r, MIN_DISTANCE, MAX_DISTANCE, 0, 90);
  
  val_l = val_l * (per_l / 100.0);
  val_r = val_r * (per_l / 100.0);

  //Writing final data to servo motors
  servo_l.write(val_l);
  servo_r.write(val_r);
  
  //Debugging the final data
  debugg(val_l, val_r);

  //Applying the final delay (due to servo speed characteristics)
  hold=true;
  if(hold==true) delay(HOLD_TIME);
}
3  Using Arduino / Sensors / Re: Ultrasonic Sensor delays on: January 02, 2013, 11:40:38 am
i am just looking a solution for the same problem..
only working thing is "so called" newping library, which has a 15 ultrasonic sensor example smiley
4  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: November 25, 2012, 12:41:02 pm
is it ok to use this:

HC-SR04 -------> > > > >             blank space          < < < < < - ------HC-SR04 sensor 2

is it ok if i limit the max reading range of both sensors to like 50 cm (and i need to read 50 cm), and i place sensors like 200 cm away from each other..
Would this work if each sensor had an independent microcontroller ???
Code:
delay(STEP_TIME);
  unsigned int uS1 = SONAR_L.ping();
  per_l = uS1 / US_ROUNDTRIP_CM;

Is the blank space enough, or should i use a "sponge" to prevent interference between 2 of the sensors ?????
THX smiley-mr-green

The thing to remember is that setting the maximum distance doesn't change how strong the trigger ping is nor how far the sensor will actually sense a ping.  All it does is just make anything beyond the set distance register as "clear" and the Arduino to stop monitoring that sensor.  The strength of the ping and the ability for a sensor to read a ping up to 500cm away is still there.

There's still a benefit in setting this distance as short as possible for your project.  Especially when using the standard ping() method.  But, don't think of it as changing the way the actual sensor works.

What you always need to consider is that when a sensor does a ping, that ping can echo from around 29 to 35ms.  It doesn't matter what you set the maximum distance to, this is how long a ping could be read by another sensor as a stray echo.

So in your example, it really depends on what the time is between pings.  If the ping to ping time is 100ms, there would be no issue.  If, however, you want to ping both sensors at the exact same time, you could have a problem.

Hope this helps.

Tim
Thanks for the anwser...
I will solve the problem by syncing them (only one sensor will work at a time, then a short delay, then the second will work etc...)
5  Topics / Interactive Art / Re: Stage Design application on: November 24, 2012, 02:25:24 pm
awsome
6  Using Arduino / Installation & Troubleshooting / Re: New IDE very slow on: November 24, 2012, 02:18:06 pm
go for his mode
7  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: November 24, 2012, 02:12:34 pm
is it ok to use this:

HC-SR04 -------> > > > >             blank space          < < < < < - ------HC-SR04 sensor 2

is it ok if i limit the max reading range of both sensors to like 50 cm (and i need to read 50 cm), and i place sensors like 200 cm away from each other..
Would this work if each sensor had an independent microcontroller ???
Code:
delay(STEP_TIME);
  unsigned int uS1 = SONAR_L.ping();
  per_l = uS1 / US_ROUNDTRIP_CM;

Is the blank space enough, or should i use a "sponge" to prevent interference between 2 of the sensors ?????
THX smiley-mr-green
8  Topics / Device Hacking / Re: wired controller on: November 24, 2012, 02:00:27 pm
First of all, you should try to find some manuals, and not to just connect things to it.
For example if the comm is RS232 you would've fried your xbee's if you just connected them...
9  Using Arduino / LEDs and Multiplexing / Re: A Low Cost Approach to Graphical Waterfall on: November 24, 2012, 01:50:03 pm
how can you efficiently color the water???
10  Using Arduino / Installation & Troubleshooting / Re: problems to upload sketch to arduino mega 2560 on: November 24, 2012, 01:43:35 pm
Next time google "STUFF THAT YOU WANNA BUY PROBLEMS"
because there are tons of problems with mega (if you google it)
It will save you some $$$, trust me...
11  Topics / Robotics / Re: What size motor? on: November 24, 2012, 01:35:42 pm
Tank style drive is extremely NON efficient .... You will need to grab few details about your robot and calculate the motors  smiley-sleep
12  Community / Bar Sport / Re: mbed - anyone tried it? on: November 24, 2012, 01:30:27 pm
Id like to try mbed  smiley-yell
but, for 60$ i can get tons of other stuff...
13  Using Arduino / Sensors / Re: proximity sensor (no ultra sonic) for >1.5m? on: November 24, 2012, 01:23:19 pm
why don't you use long range sharp sensors?
14  Using Arduino / Sensors / Re: Suggestion for measuring underwater? on: November 24, 2012, 01:21:06 pm
is the water clear or muddy?
15  Using Arduino / General Electronics / Re: 12v Power Supply? on: November 24, 2012, 01:17:12 pm
just search 12v power supply on ebay and work with 60% of the clarified power
Pages: [1] 2 3 ... 7