Go Down

Topic: Sharp IR sensor works on UNO but not on NANO (Read 142 times) previous topic - next topic

hzd1977

Hi there.

New to this world, so bear with me.

I get the Sharp IR sensor to work on my UNO board but not on my NANO board.

I've tried the Blink sketch on the NANO and that works, so the communication and IDE works.


Code: [Select]
/*
SharpDistSensorBasic.ino
Source: https://github.com/DrGFreeman/SharpDistSensor

MIT License

Copyright (c) 2017 Julien de la Bruere-Terreault <drgfreeman@tuta.io>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

/*
This example shows how to use the SharpDistSensor library to continuously
read the sensor and display the analog value and the corrseponding distance
in mm.

The library default values corresponding to the Sharp GP2Y0A60SZLF 5V sensor
are used.

See the library README for how to use pre-defined sensor models or custom
fit functions.
*/

#include <SharpDistSensor.h>

// Analog pin to which the sensor is connected
const byte sensorPin = A0;

// Window size of the median filter (odd number, 1 = no filtering)
const byte mediumFilterWindowSize = 5;

// Create an object instance of the SharpDistSensor class
SharpDistSensor sensor(sensorPin, mediumFilterWindowSize);


void setup() {
  Serial.begin(9600);
}

void loop() {
  // Get distance from sensor
  unsigned int distance = sensor.getDist();

  // Print distance to Serial
  Serial.println(distance);

  // Wait some time
  delay(50);
}


F.i. this works on UNO but not NANO.

Am I missing something painfully obvious?

Thx.

mudassir9999

Hello,
I think you are incorrectly connecting analog pin of Sharp Sensor to NANO, please re-check your connections should matach with your decleration..


Code: [Select]
const byte sensorPin = A0;

BTW! did you tried troubleshooting the problem, used A1,A2,A3 instead of A0.? did you checked voltage supply.?
you can also test voltage at the Sharp IR signal pin while pressing button on a remote - Reading in voltmeter should bounce..

Wawa

How did you power the Nano.
If powered from USB, the Nano has a simple USB backflow protection diode (an Uno has a mosfet).
Because of that, USB supply of a Nano is about 0.4volt lower than an Uno.
Not sure if the sensor is ok with that. Check the datasheet.
Not sure if you use the 3.3volt pin for anything.
The Uno can deliver 150mA there, an official Nano <=50mA, and a clone <=15mA.
Leo..

hzd1977

This is from the Sharp datasheet:
4. Consumption current : Typ. 30 mA
5. Supply voltage : 4.5 to 5.5 V

And I meassured the voltage delivered by the NANO. It was, as you say, around 4.6 V.

I bought the NANO of eBay. Don't know how to identify it as a clone or an official.
http://www.ebay.com/itm/162002876661?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

It doesn't mention Arduino anywhere, so maybe it is a clone? Then it can only deliver 15ma and the consumption of the Sharp is 30 mA.
Sounds like an explanation to me.

Well...

CrossRoads

How does that clone create 3.3V? I don't see a regulator, and have never seen a CH340 datasheet, don't know if it creates 3.3V like the FT232 does.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Wawa

If the sensor is powered from the 5volt pin, and that is 4.6volt, it should be ok.
Decoupling of the Nano is also less. Try a (~100uF) cap from supply to ground near the sensor.

@CrossRoads
A poorly writen datasheet can be found on the net.
https://cdn.sparkfun.com/datasheets/Dev/Arduino/Other/CH340DS1.PDF
V3 (pin5) is the 3.3volt output.
This is what I just measured.
No load: 3.30volt.
10mA: 3.26volt
20mA: 3.23volt
30mA: 3.21volt
Didn't want to increase current beyond that.
Leo..

Go Up