Show Posts
Pages: 1 ... 23 24 [25] 26 27 ... 31
361  Using Arduino / Sensors / Re: new to arduino and confused with a sensor shield on: July 02, 2012, 12:19:44 pm
might have it figured out after a lot of looking found this bit about 4 pin sockets on sensor shields
"This connector can go to external Bricks or other devices that have more complex Communications Protocols to work with Arduino. Examples are GPS receivers, Ethernet interfaces, and other complex devices. These are 4-pin connectors."

There's no logic on these types of boards, they do nothing more than re-arrange the pins (and provide a lot of ground and power connections).  Just use a multimeter and test continuity with each pin.  I'm sure after you map out one or two, you'll see the pattern and know what the rest of them do.

362  Using Arduino / Sensors / Re: Read 2 HC-SR04 on: July 02, 2012, 12:07:57 pm
Changed the code so the returned signal measured in a function. (easier to view)
Attached code for whoever wants to use and modify.

For reading 2 or more ultrasonic sensors, you may want to try using the NewPing library as it supports timer interrupts for an event-driving programming style.  While NewPing doesn't ping two sensors at the same time, it allows you to ping sensors very quickly (less than 30ms apart), which should almost always give the same result.  As a bonus, your sketch can be doing something else while it is in the ping process as it uses a timer interrupt while waiting for the ping echo.

Using NewPing, one user has 15 sensors connected to a single project and with the event-driven method there's time to process this information.  Below is a link to the NewPing library as well as the 15 sensor example sketch (which could be easily adjusted to just ping 2 or any number of sensors).


15 Sensor Example Sketch

363  Using Arduino / Sensors / Re: NewPing (Ultrasonic) Library for HC-SR04, SRF05 and SRF06 sensors - v1.3 on: July 02, 2012, 08:38:50 am
HC-SR04 not working for me with the latest sketch.

The HC-SR04 seem to be a real hit or miss in the quality department.  Or, there's several manufactures with different specs.  I have 4 of them, and they all work.

Try this, set MAX_SENSOR_DELAY in NewPing.h from 18000 to 180000 and in NewPing.cpp change "delayMicroseconds(10)" (line 48 in the 1.4 pre-release) to "delayMicroseconds(1000)".  And let me know if that changes anything.

Also, what Arduino hardware are you using and what sketches have you tried?

364  Using Arduino / Displays / Re: LCD Bitmap - Updated v1.5 on: June 29, 2012, 06:36:21 pm
You are awesome! I was thinking of this a couple of weeks ago!
It's like  you read my mind  smiley-wink

I am going to try this out!
I had made this myself:
a lcd controled by a IO expander.
and had written a library for it,
you say your code works with the standard lcd library smiley?

I'll give it a try with my code tomorrow and will let you know smiley

just can\t say it enough, this is so awesome!   smiley


LCDBitmap works with the standard LiquidCrystal library if your LCD connection is standard 4-bit parallel (6 wires).  If your LCD's connection is I2C or uses a shift register, you'll also need the New LiquidCrystal library in addition to the LCDBitmap library.

365  Using Arduino / Sensors / Re: NewPing (Ultrasonic) Library for HC-SR04, SRF05 and SRF06 sensors - v1.3 on: June 29, 2012, 06:28:43 pm
I wanted to add that I have a HC-SR04 that doesn't work with NewPing 1.2, 1.3, or the 1.4 pre-release, using either the Simple NewPing Example Sketch or the 15-sensor example, modified for 1 HC-SR04.  It works fine with the example code at though.

How can I help debug the library for the HC-SR04?

EDIT: Forgot to add that I'm using an Arduino Uno r3 with the v1.0 Arduino IDE.

EDIT2: I get 0cm like everyone else with an HC-SR04 reported. I even tried getting the raw timing data instead, in case it was an obscure bug in the distance conversion. Everything I get is 0.

EDIT3: In case it's helpful, I note that I can hear the HC-SR04 sending out its sonar pings when I try NewPing. So I would guess that the bug doesn't involve actually sending out the pings.

I have (4) HC-SR04 sensors and they all work just fine with the Arduino Uno R3 using every library version of NewPing as well as every example sketch.  I've also run with Arduino 0023, v1.0 and have just switched to v1.0.1 all of which work.  So, I believe it's unfair to say "I get 0cm like everyone else with an HC-SR04 reported".  There's only a couple people that have reported a problem, it's running just fine for me with 4 different sensors, so not everyone is having a problem.

There's differences between my example sketches and the sketch at the link you provided.  For example, it's only doing 2 pings a second while my examples are typically doing 20 pings a second.  So, maybe your sensor can't ping that frequently.  To diagnose this, I've modified my example sketch to duplicate what that other example is doing.


#include <NewPing.h>

#define trigPin 12
#define echoPin 11

NewPing sonar(trigPin, echoPin);

void setup() {

void loop() {
  int distance = sonar.ping_cm();

If this still doesn't work, it could be the VERY long trigger delay in the example you provided.  It's waiting 1000 microseconds when the sensor specs state it should only require 10 microseconds.  If your sensor is way out of spec, maybe it needs longer than 10 microseconds.  To change this in the NewPing library, look for the "delayMicroseconds(10)" in the NewPing.cpp file (line 48 in the 1.4 pre-release) and change it from 10 microseconds to 1000 microseconds.

If it still doesn't work, try changing the MAX_SENSOR_DELAY in the NewPing.h file from 18000 to 180000 (add a zero at the end).  This will give your sensor more time to finish the ping before waiting for the echo.  The longest I've ever measured is around a 17000 microsecond delay, but maybe your sensor requires longer.

If it's still not working for you, you could send me your sensor.  If I had the sensor, I could hopefully duplicate it and see what exactly is happening.  Of course, I'd send it back when I was done with the diagnosis.

Let me know what you find or if you want to send me the sensor for diagnosis.

366  Using Arduino / Sensors / Re: Motor and Ping sensor seem incompatible? on: June 29, 2012, 07:34:20 am
Why not just connect the sensor and servo directly to the Arduino without the shield?


It's mounted on the chassis of an RC car that I've constructed, and doing it that way would mean I have to use a breadboard because more than two things need a 5v rail. The breadboard takes up extra space and requires fastening down, whereas the shield fits compactly right on top of the Arduino. Combine that with the fact that a friend is currently borrowing my breadboard, and that I'd have to wait til tomorrow to use it, and I'm basically left with the shield option-- or making my own rails. How hard can that be?

I'm trying to find the exact sensor shield that I have, but I can't find so much as a brand name or other identifying title on it! -_-

If you're having a problem as simple as this, you should taken to a breadboard level, it could be as simple as the ports you're using share the same Arduino pins.  Have you tried using different ports on the shield?

367  Using Arduino / Sensors / Re: Sonar range finders in ANALOG input pins or DIGITAL pins? on: June 29, 2012, 07:31:53 am
Hello everyone,

I have been ask to extend a robot project which was previously designed by someone else.

I have been following some tutorials on the net, it seems most of people uses digital pins to connect ultrasonic range finders. but, in this robot these sonar sensors are connected to pins 3 and 4 analog Input.

I was wondering which one is the best approach and what is the difference.

I do appreciate your time answering my questions.

Thank you very much

Since both pins are attached to analog pins, it sounds like the project just used the analog pins because they ran out of digital pins.  Analog pins can be used as digital pins, which is probably causing the confusion.

We would need to know the model of the sensor to tell you for sure.

368  Using Arduino / Sensors / Re: HC-SR04 on one pin only - possible? on: June 29, 2012, 07:28:19 am
OK, my question has been answert at page 8 and 9 of this thread:,106043.0.html - thanks for the great library - waiting for my sensors to arrive.

If someone can/wants to add some informaiton or experience ...


It won't work with normal ultrasonic sensor libraries.  NewPing is specifically written to control sensors using only one pin. NewPing's 1-pin support is only available in a pre-release build which can be downloaded at the bottom of the following linked message:,106043.msg838337.html#msg838337

As I'm getting positive feedback on it working, I'll probably be making a release version later today.  In addition to 1-pin support, NewPing is faster (both ping speed and with the use of port registers for pin manipulation/reading), produces smaller sketches (from port registers and discrete commands), and has a method using timers to produce event-driven sketches (say goodbye to "delay" commands that slow your robot down).

369  Using Arduino / Sensors / Re: NewPing (Ultrasonic) Library for HC-SR04, SRF05 and SRF06 sensors - v1.3 on: June 29, 2012, 07:17:30 am
So far everything is working fine with the single pin version. I've only had time to wire up 2 of the sonars so far.


Basically, because the library is designed specifically to communicate with ultrasonic sensors instead of using stock commands like pulseIn, it waits for all the correct pin states between the trigger and echo stages.  So, it can both trigger and echo using the same Arduino pin because the output and input stages are clearly defined.

The idea came when I wired a sensors incorrectly (trigger and echo pins reversed) with no ill effect while looking at adding support for the Ping))) sensor which only uses 1 pin for both trigger and echo.  I knew it wouldn't break anything to try (from my incorrect wiring experience) and it also seemed logical that the sensor was only ever listening for a trigger during certain situations and only sending an echo output during other situations.  Sure enough, I believe 3 lines of code were modified and it worked perfectly.

On projects where you have multiple sensors (which many have) reducing the number of pins needed by half is huge.  Projects that at once needed a large Arduino Mega could be done with a thumbnail-sized Teensy 2.0.

Keep us updated!

370  Using Arduino / Displays / Re: LCD Bitmap - Updated v1.5 on: June 28, 2012, 02:40:37 pm
Version 1.5 released:

4bit method now works without the New LiquidCrystal library (was always supposed to work this way, oversight on my part). Update switch now optional on all functions, defaults to NO_UPDATE.

Download LCDBitmap Library v1.5

371  Using Arduino / Displays / Re: LCD Bitmap - Updated v1.4 on: June 28, 2012, 01:54:46 pm
Hi, thanks for this great library. I got it working successfully using an Arduino Leonardo, running IDE v1.0.1, with your modified version of the library attached on an above post. However, I've been playing around with the bars function and can't figure out: How could I use your library to display the value (graphical) of some analog inputs? Suppose I have 3 analog inputs. I read them, re-map or convert them, and display those values with a bar, with the highest possible value creating a full bar, and the lowest possible value giving an empty bar. Any help or suggestions would be great.

The barGraph method is fairly straight-forward, the syntax is as follows:

bitmap.barGraph(bars, *graph, color, update);

<bars> is the number of bar graphs you want to display.
<graphics> is an array of height values (these values are in pixels, with the range from 0 to 16).
<color> is either ON or OFF.
<update> is etiher UPDATE or NO_UPDATE (in the next release, v1.5, all functions default to NO_UPDATE if not specified).

So, if you want 3 bar graphs for your 3 analog sensors, you would do something like this:

#include <LiquidCrystal.h>
#include <LCDBitmap.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LCDBitmap bitmap(&lcd, 0, 0);  // Set the bitmap to the &lcd display at character position 0,0.
byte graph[3]; // Bar graph with 3 columns.

int analogPin1 = A1;
int analogPin2 = A2;
int analogPin3 = A3;

void setup() {
  lcd.begin(16,2); // Initalize the LCD display, do this before you initalize LCDBitmap.
  bitmap.begin();  // Then initalize the LCD bitmap.

void loop() {
  // analogRead returns values from 0 to 1023, the barGraph displays values from 0 to 16 (1023+13)/61=16.98.
  // This does the conversion without using floating point math keeping your compiled code small.
  graph[0] = (analogRead(analogPin1) + 13) / 61;
  graph[1] = (analogRead(analogPin2) + 13) / 61;
  graph[2] = (analogRead(analogPin3) + 13) / 61;
  bitmap.barGraph(3, graph, ON, UPDATE);  // Display the bar graph.

Note: code compiles, but is untested.

372  Using Arduino / Sensors / Re: NewPing (Ultrasonic) Library for HC-SR04, SRF05 and SRF06 sensors - v1.3 on: June 27, 2012, 11:58:51 pm
At the moment, I only have the two sensors. There seems to be something wrong with one sensor. It works fine by itself, but as soon as I apply power to the second sensor, the reading of the first sensor shows that something is 5cm away. If I take power away from the second, the first sensor then works fine. With the new library and example sketch, everything else seems to be working. I'll have to get some more of the HC-SR04s and try them out.

You're not sharing pins to both sensors are you?  Or having the sensors face each other?

When you say as soon as you apply power to the second sensor, what exactly do you mean?  Do you have a sketch that's connected to these two sensors?  Could you share the sketch?

What it sounds to me like is that you're doing two things at once, or have two sensors connected together.  So each work on their own, but as soon as you try to use both there's a failure.  Seeing your sketch and how you have them wired up would help greatly.

For testing multiple sensors at once, I would suggest using the 15 sensors test sketch found here:

For 2 sensors you would change SONAR_NUM to 2, and the "sonar" array would be changed to something like this:

NewPing sonar[SONAR_NUM] = {     // Sensor object array.
  NewPing(12, 11, MAX_DISTANCE), // Each sensor's trigger pin, echo pin, and max distance to ping.
  NewPing(10, 9, MAX_DISTANCE)

Obviously, the pins would need to be correctly entered or changed to match.

373  Using Arduino / Sensors / Re: NewPing (Ultrasonic) Library for HC-SR04, SRF05 and SRF06 sensors - v1.3 on: June 27, 2012, 11:50:07 pm
I have 8 sonars on my robot, all SRF05 which I want to use in single pin mode. I'd be happy to test out a single pin version of the new library.

I attached the version of the library that works with only one pin to the message right before your post.  Here's a link to that message (two links at the bottom of the message):,106043.msg838337.html#msg838337

For testing, you may want to start with communicating directly to all the sensors without the rest of the bot sketch.  I have a sample 15 sensor sketch that you could easily modify to test your 8 sensors.  The sketch can be found here:

For 8 sensors, you would change SONAR_NUM to 8 and the "sonar" array to only have 8 NewPing objects.  To make them only use one sensor, simply make the trigger and echo pin numbers the same.  For example:

NewPing sonar[SONAR_NUM] = {
  NewPing(3, 3, MAX_DISTANCE),
  NewPing(4, 4, MAX_DISTANCE),
  NewPing(5, 5, MAX_DISTANCE),
... complete for rest of sensors ...

After the test is complete, you could then update your full bot sketch to work with the NewPing library.  For a simple non-event-driven example of how to implement the NewPing library, see this very basic "hello world" sketch (again, make the trigger and echo pins the same for one pin wiring):

That is, unless your current bot sketch is already event-driven, in which case you may want to look more at the 15 sensor example sketch for how to implement it in your project.

Just so you know, I've tested this release with 5 sensors using only one Arduino pin each and it worked without a hitch.  The only exception is the SRF06 which needed a 0.1uf cap across trigger and echo.  So, if it works for 5 there's no reason it shouldn't work for 8 sensors.

374  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?

375  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:

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