简体   繁体   English

Arduino UNO + 以太网扩展板 + 超声波传感器 = 失败

[英]Arduino UNO + Ethernet Shield + Ultrasonic Sensor = Fail

With my Arduino Uno I measure the distance using HC-SR04 ultrasonic sensor with no problems at all using the wiring below.使用我的 Arduino Uno,我使用 HC-SR04 超声波传感器测量距离,使用下面的接线完全没有问题。 When I attach ethernet shield, my ultrasonic sensor does not measure distance any more, it constantly says 0cm no matter what.当我连接以太网屏蔽时,我的超声波传感器不再测量距离,无论如何它总是显示 0cm。 I have tried different digital pin pairs such as 5-7, 6-8, 5-9, 3-5, 2-8 but no luck.我尝试了不同的数字引脚对,例如 5-7、6-8、5-9、3-5、2-8,但没有成功。

I suspect that HC-SR04 is not compatible with my Ethernet shield but I haven't seen such warning anywhere on the net.我怀疑 HC-SR04 与我的以太网屏蔽不兼容,但我在网上的任何地方都没有看到这样的警告。

  • There are no components attached to arduino besides ethernet shield and the ultrasonic sensor itself.除了以太网屏蔽和超声波传感器本身之外,arduino 没有附加任何组件。
  • There is no SD Card in SD Card slot. SD 卡插槽中没有 SD 卡。
  • My ethernet shield works fine while running a web server or web client script.我的以太网屏蔽在运行 Web 服务器或 Web 客户端脚本时工作正常。
  • Digital pins of ethernet shield works fine with all other components such as temperature sensor, motion sensor etc.以太网屏蔽的数字引脚与所有其他组件(如温度传感器、运动传感器等)配合良好。

Here is the ethernet shield I have;这是我拥有的以太网屏蔽; http://www.ezshopfun.com/product_info.php?products_id=169 http://www.ezshopfun.com/product_info.php?products_id=169

Here is my actual circuit;这是我的实际电路;

Here is my code;这是我的代码;

#define trigPin 6
#define echoPin 7

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  int duration, distance;
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH) / 2;
  distance = duration / 29.1;
  Serial.print(distance);
  Serial.println(" cm");
  delay(500);
}

电路

Today I bought a multimeter and tested my circuit.今天我买了一个万用表并测试了我的电路。 Here are the results;这是结果;

When my circuit directly attached to Arduino itself;当我的电路直接连接到 Arduino 本身时;

4.80V & 5.7mA 4.80V & 5.7mA

When my circuit attached to ethernet shield;当我的电路连接到以太网屏蔽时;

3.06V & 3.8mA 3.06V & 3.8mA

I think the problem is that 3.06V is not enough for my HC-SR04 to operate.我认为问题是 3.06V 不足以让我的 HC-SR04 运行。

Yeah based on this photo是的,基于这张照片

在此处输入图片说明

you're not grounding your sensor.您没有将传感器接地。 You have two power supplies going into it.你有两个电源进入它。 This, needless to say, is bad for a number of reasons.不用说,出于多种原因,这很糟糕。 First and foremost because it wont work ungrounded lol首先也是最重要的,因为它不会在不接地的情况下工作,哈哈

As others have said, it looks like the main issue is that you need this connected to 5V and check your wiring generally.正如其他人所说,看起来主要问题是您需要将其连接到 5V 并通常检查您的接线。

However, there is another potential issue:然而,还有一个潜在的问题:

digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);

You only need to set the trigger pin high for 10 microseconds, not 1000 microseconds.您只需将触发引脚设置为高电平 10 微秒,而不是 1000 微秒。 I don't know if this is an issue or not but there is no need to wait this long.我不知道这是否是一个问题,但没有必要等待这么长时间。 You could potentially be missing some or all of the incoming pulse by waiting that long.等待那么长时间,您可能会错过部分或全部传入脉冲。

You might want to checkout out some HC-SR04 tutorials too, like this one:您可能还想查看一些 HC-SR04 教程,例如:

http://superawesomerobots.com/tutorials/hc-sr04-tutorial-for-arduino/ http://superawesomerobots.com/tutorials/hc-sr04-tutorial-for-arduino/

Hope that helps.希望有帮助。

I had a similar problem with a wifi shield + ultrasonic sensor.我在 wifi 屏蔽 + 超声波传感器上遇到了类似的问题。 I found switching from pins 13(trig) and 11(echo) to 8(trig) and 3(echo) fixed it.我发现从引脚 13(trig) 和 11(echo) 切换到 8(trig) 和 3(echo) 修复了它。

See here: http://forum.arduino.cc/index.php?topic=201827.0见这里: http : //forum.arduino.cc/index.php?topic=201827.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM