Pages: [1]   Go Down
Author Topic: Ultrasonic range sensor not working correctly with Nano  (Read 770 times)
0 Members and 1 Guest are viewing this topic.
Rio de Janeiro
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello guys,

I have an ultrasonic range sensor HC-SR04, I made a prototipe with an Arduino duemilanove, which worked correctly.

The problem is, when I switch the sensor to my arduino Nano, it reacts differently. I start to read '0' cm most of the time, and it just read the correct distance when the surface in front of the sensor is flat and perpendicular (90º) with the sensor.

With the Duemilanove, it reads almost any surface and support a greater range on angles and never displays '0'. Sometimes display huge distances but never '0'.
For example, with duemilanove I can read the dist to my t-shirt while with nano it just read the wall or flat surfaces.

The code is absolutely the same and for anything else, the Nano board is working alright.

Any clues? help  smiley-sad

**The code which works well with duemilanove but not with Nano:
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#define echo A5
#define trig A4
unsigned long duration;

void setup() {
  lcd.begin(16, 2);
  pinMode(echo,INPUT);
  pinMode(trig,OUTPUT);
  pinMode(7,OUTPUT);
  digitalWrite(7,HIGH);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo,HIGH);
  Serial.println(duration/59,DEC);
  lcd.setCursor(0,0);
  lcd.print(duration/59,DEC);
  lcd.print("  ");
  delay(500);
}

Moderator edit: code tags added
« Last Edit: April 19, 2012, 01:47:57 pm by AWOL » Logged

Rio de Janeiro
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Almost sure this is not a programming question, but anyway.

Also noted that it can't read ranges above 2m with Nano, while with duemilanove it works correctly.

Thanks for any help,
Logged

West Des Moines, Iowa USA
Offline Offline
Sr. Member
****
Karma: 2
Posts: 428
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Could it be a voltage/power issue?
Logged

There's always a better way!

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

I came across this issue with my recent project. The issue was actually happening only when I power the nano from USB. This is a Power issue. I powered Nano with a battery (6 - 9v is enough) and it started work fine.
Logged

Pages: [1]   Go Up
Jump to: