Show Posts
Pages: 1 ... 24 25 [26] 27 28 ... 31
376  Using Arduino / Sensors / Re: Motor and Ping sensor seem incompatible? on: June 27, 2012, 03:58:40 pm
You would need information about the exact shield you're using to figure this out, or find out that it's not possible.  Why not just connect the sensor and servo directly to the Arduino without the shield?

377  Using Arduino / Sensors / Re: SPEED READER FOR BIKE on: June 26, 2012, 06:44:57 pm
Graynomad has it right, a hall effect sensor and a magnet on one of the spokes is the way to go.  To get the distance per rotation see Sheldon Brown's page:

The most accurate method of getting the tire circumference is a rollout test, which you can read how to do also on Sheldon Brown's page:

378  Using Arduino / Sensors / Re: How do I check if ive got a faulty HC-SRO4? on: June 25, 2012, 10:38:03 am
Hi, that sketch is brilliant, I understand every line of it. But its still saying Ping 0cm!

What happens if you wire it to pins 11 and 12 (don't use pin 13)?  Here's the full sketch:

Be sure 12 is wired to trigger and 11 wired to echo, if you switch them, it won't work for sure.  Also, 0cm is the correct result if there's nothing within the ping range, so put a box or something foot away. I have 4 SR04 sensors and they "work" with the above sketch.  3 of my SR04 sensors do have a problem where they don't work well beyond about 50cm.  It seems to me that this may be a common problem with the SR04, so be sure your test object is fairly close to the sensor.

Also, just to make sure we're both using the same library, attached is my development version of NewPing (v1.4 pre-release).  Just replace these files with the ones already in the NewPing folder.

379  Using Arduino / Sensors / Re: NewPing (Ultrasonic) Library for HC-SR04, SRF05 and SRF06 sensors - v1.3 on: June 25, 2012, 09:39:26 am
I am having the same problem with two of my HC-SR04s. All I'm getting is a reading of 0cm regardless of what's in front of the sensor. These sensors both work with a different ultrasonic library. Does anyone have an idea of what may be causing this?

First, try using the example sketch below, it's the new example that's being included with NewPing.  Be sure you have the trigger and echo pins wired correctly.  Don't change anything in the example, even the pins used.

Also, when you say you have a problem with two sensors, does that mean you have other sensors that work and two that do not?  I've found the SR04 sensors tend to have a terrible quality control.  Of the 4 that I have, only 1 I would say works correctly.  The other 3 work, but get all wonky at distances beyond 50cm.

Finally, just to make sure we're both using the same library, attached is my development version of NewPing (v1.4 pre-release).  Just replace these files with the ones already in the NewPing folder.

380  Using Arduino / Displays / Re: LCD Bitmap - Updated v1.4 on: June 21, 2012, 04:47:37 pm
Thanks, it worked!.

I had changed the LCD reference for LiquidCrystal and of course it worked, but nice to have the latest files with the conditionals.



Thanks for testing.  I'll incorporate that in the next release.

381  Using Arduino / Sensors / Re: Ping))) and Midi on: June 21, 2012, 04:41:46 pm
Hello people,

I have a little problem which has big consequences. It belongs my bachelor thesis.

I use 3 Ping))) sensors and convert their value into midi messages via the midi library. The values the ping sensor send via midi were perfect for short distance but for a distance in 2,5m range it just jumps around. Is there a work around for it, or should I use other sensors.

Thank you so much for fast answers!


I've got an ultrasonic library that may give you better results.  I'm also looking for someone with a PING))) to test.  If you want to try it out, let me know and I'll get you a copy that works with PING))) sensors.  For more information on my library see this thread:,106043.0.html

382  Using Arduino / Sensors / Re: NewPing (Ultrasonic) Library for HC-SR04, SRF05 and SRF06 sensors - v1.3 on: June 21, 2012, 04:38:23 pm
FYI, further testing and I'm having problems with the combination of a SRF06, using one pin, and using the Teensy hardware.  It works, but only about half the time.  I'm going to try a few things this evening and I'll let everyone know the results.  The plan is to post the new release in the forum for people to test before I release this version.  Specifically, testing it using only one Arduino pin.

383  Using Arduino / Displays / Re: LCD Bitmap - Updated v1.4 on: June 21, 2012, 01:57:30 pm
maybe to help newbies, you could add a compile time check/error to tell them how to resolve the issue.
For example, LCDBitmap.h includes <LiquidCrystal.h>
fm's LiquidCrystal.h includes "LCD.h" so the include of "LCD.h" is not needed in LCDBitmap.h
(This will eliminate the preprocessor error).

Actually, when using a 4bit connection the LCDBitmap library was supposed to work without the need for the New LiquidCrystal library.  I've changed the code so it should work with or without the New LiquidCrystal library and attached the revision to my previous reply.

Adding an error if trying to use other connection types without the New LiquidCrystal library is a good idea too, and I'll probably be implementing that as well.

384  Using Arduino / Displays / Re: LCD Bitmap - Updated v1.4 on: June 21, 2012, 01:39:08 pm

I have installed arduino 1.0.1 and I just downloaded LCDBitmap library . I loaded the LCDBitmap_standard_4bit example and try to compile it.

This is the outcome:

/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:89:17: error: LCD.h: not found
In file included from LCDBitmap_Standard_4bit.cpp:2:
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:110: error: expected `)' before ‘*’ token
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:133: error: ISO C++ forbids declaration of ‘LCD’ with no type
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:133: error: expected ‘;’ before ‘*’ token
LCDBitmap_Standard_4bit:4: error: no matching function for call to ‘LCDBitmap::LCDBitmap(LiquidCrystal*, int, int)’
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:108: note: candidates are: LCDBitmap::LCDBitmap()
/home/ydirgan/SCRIPTS/Arduino/arduino-1.0.1/libraries/LCDBitmap/LCDBitmap.h:108: note:                 LCDBitmap::LCDBitmap(const LCDBitmap&)

The first line shows a LCD.h not found statement... where LCD.h header is?. Am I missing something?.

any advice will be appreciated.



I guess I missed this.  I had believed LCDBitmap would work without the "New LiquidCrystal" library.  But, that doesn't seem to be the case.  Attached to this message are replacement library files.  Save and replace these files with the existing files in your Arduino/libraries/LCDBitmap/ folder.  I don't have a 4bit project in front of me to test, but the attached files do compile with a stock Arduino 1.0.1 with the LCDBitmap_Standard_4bit sketch.

Let me know if it works.

385  Using Arduino / Sensors / Re: How do I check if ive got a faulty HC-SRO4? on: June 21, 2012, 10:47:58 am
Thanks guys, ill try all suggestions later today and let you know how I get on.

I did try newping but it didnt make much sense to me, im very much a newbie and this is the first thing ive done othr than making an LED flash and other very simple bits.

NewPing has fairly simple examples.  But, maybe in my side-quest to steer people to an event-driven programming paradigm I've confused some.  Below is an example NewPing sketch using a more common to Arduino, line-by-line with delays which works well for a "hello world" sample:

#include <NewPing.h>

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     13  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.

void loop() {
  delay(50);                // Wait 50 milliseconds between pings (ping about 20 times per second).
  int cm = sonar.ping_cm(); // Send out the ping, get the results in centimeters.
  Serial.print("Ping: ");
  Serial.print(cm);         // Print the result (0 = outside the set distance range, no ping echo)

As you're new to the Arduino I believe the above sketch would make more sense.  Let me know if it's not clear.  I would suggest, however, that you consider an event-driven paradigm instead of the all too common line-by-line with delays.  Line-by-line with delays may be easy to understand and works fine for a example.  But, it doesn't work well when you try to build something complex.  Changing your mindset now to an event-driven paradigm will make it much easier down the road when you want to incorporate motors, servos and sensors in your project and have your sketch do complex tasks.

386  Using Arduino / Sensors / Re: NewPing (Ultrasonic) Library for HC-SR04, SRF05 and SRF06 sensors - v1.3 on: June 21, 2012, 08:19:42 am
yeah, it works when change PING_INTERVAL from 35 to 29.

And now one sonar in the front of bot is not assembled well. so I have only one sonar in the front and one sonar in the back.
I test two sonars on opposite sites of my bot,  with the PING_INTERVAL of 8 ms, and it work.
So i'll modify my code later to shorter the time.

and i have a question that where 35ms , 29ms,  8ms come from ,how it calulate.  The max distance is 2m, so the time of echo is  (2/340) * 2 = 12ms

The time calculations have nothing to do with what you set as the maximum ping distance.  Even if you set a max ping distance to 25cm, the sensor doesn't know that or do something differently.  All that happens is the library will only care about ping echo's within the 25cm range.  What still happens is the sensor sends out a ping and listens for an echo.  That ping echo can be detected from up to 400cm to 500cm away.

So, when one sensor sends out a ping, it can travel up to lets say a maximum of 500cm bounce, and come back and hit a different sensor that you may be reading for a ping echo at the time.  This would be cross-sensor echo.  When calculating the time, you always look at the sensor's maximum detection distance (lets say 500cm as that's what most spec).  500cm * 2 * 28.5uS/sec = 28,500 uS.  There's also around 450uS of delay before a ping starts with the SRF05, which works out to right around 29ms.  In theory, if a sensor is really only able to detect a ping at a maximum distance of 500cm, you could have two sensors right next to each other and ping at 29ms intervals and you should never get any misreadings from cross-sensor echo.

I typically say to ping every 33 to 35ms as a bit of a buffer, just to be sure.  Also, 33ms works out to 30 pings/second which is typically well faster than anyone needs for a single sensor.  Finally, thinking of the sketch being event-driven and doing other things, we'd want to give the ATmega other time to do other things in the sketch other than just ping the sensors.

Your situation is a bit different as you have so many sensors.  A complete sweep at 29ms would take 464ms, so you can only do about 2 sensor sweep cycles per second.  That may be fast enough, and allow time for your sketch to do the other things it needs to do.  Then again, maybe you need it to sweep faster.  The 8ms came from testing of a simple 2 sensor system (pointed in opposite directions) in a small room environment.  At 8ms, it still gave accurate readings without cross-sensor echo.  At 7ms, I started getting random results.  This test by no means is the final decision that 8ms between pings is safe.  It was just what I saw in my test.

For your robot, I would change the ping cycle to trigger the sensors on opposite sides of the robot and rotate around (like drawing a star).  That way, you could limit the possibility of cross-sensor echo and thereby lower the ping rate.  29ms should work really well and I doubt that you could get 8ms to work as reliably as 29ms.  But, maybe somewhere between 29 and 8 will work perfectly for your situation.  It also depends on how fast you need to cycle through the sensors.  If 2 sensor sweeps per second is fast enough, leave it at 29ms.  This gives your sketch more time to do other things than if you tried to make it 8ms.

387  Using Arduino / Sensors / Re: Which Maxsonar rangefinder do you suggest? on: June 21, 2012, 07:52:17 am
excuse me, I just found the Beam width explanation file.. smiley-razz
seems like the ez4 is the one with the narrowest beam width so I'll go for that one smiley

The EZ4 also has the shortest range, keep that in mind if range is important.  I would suggest the EZ3, as it has about the same width beam but the range is much longer.

I have two problems with the Maxsonar sensors.  First, they can't detect objects closer than 6 inches, which in many cases is important.  Secondly, while it has a robust set of interface options (analog voltage, serial & pulse width), it's not compatible with most ultrasonic libraries and sketches.  This limits you to using their interface code/library or developing your own.

I've never used a Maxsonar sensor so I don't know if there's other issues (like ping speed) which could be important when used as a scanner.

388  Using Arduino / Sensors / Re: NewPing (Ultrasonic) Library for HC-SR04, SRF05 and SRF06 sensors - v1.3 on: June 20, 2012, 09:23:41 pm
Did a bunch of testing and the SRF06 will not work as-is using one pin.  However, the SR04 and SRF05 do work with the trigger and echo pins tied to a single Arduino pin.  It appears to work just as well as when using two Arduino pins.  Keep in mind, this is with my slightly modified library, not the release version.

Then I got to thinking; There's probably just a simple component like a diode on the SR04 and SRF05 which makes a one pin connection work.  I quickly figured there wasn't going to be an easy method using diodes alone.  Then I thought maybe a capacitor would isolate the sensor pins.  Sure enough, the SRF06 also works great using only one Arduino pin with just about any capacitor tied to the trigger and echo pins.

So, for the SR04 and SRF05 you can tie both the trigger and echo pins to one Arduino pin using no additional components.  And for the SRF06, tie the trigger and echo pins on the sensor together with a capacitor then tie the trigger pin on the sensor to the Arduino pin.  You don't use a capacitor for the SR04 or SRF05, just for the SRF06.

With duxiaoshi's 15 sensor project, this will save him 15 pins!  He could probably use a Teensy 2.0 "brain" now for that giant robot instead of a Arduino Mega.

I'd like to release v1.4 of NewPing with this one pin modification.  But before doing so, I need someone with a Ping))) sensor that can test it.  I want to test it with a Ping))) sensor first because I believe this modification will also make NewPing compatible with the Ping))) sensor.  If anyone has one and is willing to test, let me know.

389  Using Arduino / Sensors / Re: How do I check if ive got a faulty HC-SRO4? on: June 20, 2012, 04:13:40 pm

 You need to try this new library, it is very nice!,106043.0.html

Very good suggestion!  ;-)

Also, I would try using an echo pin other than 13.  Because the Arduino has an LED on pin 13, that can cause problems when using pin 13 as an input.  Typically, this is not an issue with ultrasonic sensors.  But, I've started to see odd things with just some SR04 sensors and I'm starting to guess the problem has to do with using ping 13 for input, not the sensor at all.

Worth a shot, but I'd still use the NewPing library anyway.  If for no other reason the one pin mode that's being added in the next release.

390  Using Arduino / Sensors / Re: NewPing (Ultrasonic) Library for HC-SR04, SRF05 and SRF06 sensors - v1.3 on: June 20, 2012, 04:04:16 pm
I was thinking about the Ping))) sensor and how simple it would be to implement in the NewPing library.  Then, I figured I'd try connecting a SR04 and SRF05 with the trigger and echo pins tied to just one Arduino pin, just like with the Ping))) sensor.  Guess what, with an adjusted library, it works perfectly.  Even works for crazy-fast ping rates of 8ms.

I figured that if the sensor's trigger pin got the output of the echo pin it would cause another trigger or basically screw things up.  Not the case.  Seems that either the echo output doesn't trigger an echo or the sensor turns off sensing of the trigger pin till it gets an echo or exceeds some time length.  Either way, it works, and works as far as I can tell, perfectly.

From my testing, you only need to use one Arduino pin to control an ultrasonic sensor.  At least the SR04, SRF05 and obviously the Ping))) which was designed to use one control pin.

Pages: 1 ... 24 25 [26] 27 28 ... 31