You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LM35与LDR共接Arduino时LM35输出不稳定的原因咨询

Troubleshooting Unstable LM35 Readings When Paired with LDR

Hey Zacknov, let's break down why your LM35 is spitting out wonky values (like jumping to 45℃) when used alongside the LDR—since both sensors work perfectly alone, the issue is definitely interference between the two. Here are the most likely causes and straightforward fixes:

1. Power Supply Noise (The Top Suspect)

LM35 is hyper-sensitive to voltage fluctuations—it outputs 10mV per ℃, so even tiny ripples in the 5V supply will directly skew your temperature readings. When the LDR's resistance changes with light levels, it draws varying amounts of current from the 5V rail, creating small voltage spikes/dips that throw the LM35 off.

Fix:

Add a 100nF ceramic decoupling capacitor directly across the VCC and GND pins of both sensors. Place the capacitor as close to the sensor as possible—this absorbs sudden current changes and stabilizes the local power supply instantly.

2. ADC Channel Switching Artifacts

Arduino's analog-to-digital converter (ADC) shares a single input circuit across all analog pins. When you switch from reading the LDR (A1) to the LM35 (A0), residual charge from the previous channel can linger on the ADC's input, causing the first LM35 reading to be inaccurate.

Fix:

Modify your code to read the LM35 twice, discarding the first reading to flush out leftover charge:

void loop() {
  // First read clears residual charge from the ADC
  analogRead(lm35);
  // Second read gives the accurate temperature value
  temperature = analogRead(lm35);
  temperature = temperature*(5.0*100.0/1024.0);
  
  ldr_value = analogRead(ldr);
  
  Serial.print("Temperature : ");
  Serial.print(temperature);
  Serial.print(" | ");
  Serial.print("LDR : ");
  Serial.println(ldr_value);
  delay(1000);
}

Alternatively, you can read an unused grounded pin (like A2) between the LDR and LM35 readings to reset the ADC.

3. Poor Grounding (Common Path Interference)

If your sensors are connected to different GND points on the Arduino, or share a long, daisy-chained ground wire, current from the LDR can create a small voltage drop along the ground line. Since the LM35 uses this same ground as a reference, the drop will make its output appear higher than it actually is.

Fix:

Use single-point grounding: connect both the LM35's GND and LDR's GND directly to the same Arduino GND pin. Avoid串接 ground wires between sensors—this eliminates voltage differences across the ground path.

Quick Test to Confirm

To narrow it down, disconnect the LDR while keeping the LM35 connected. If the temperature readings stabilize, you know the interference is coming from the LDR's interaction with the power/ADC system. Then apply the fixes above one by one to find the exact solution.

内容的提问来源于stack exchange,提问作者Zacknov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:30:06