A. Serial.print() should be Serial.println() to add a new line.
B. Serial.begin() must be called inside loop().
C. delay() cannot be used inside loop().
D. analogRead() should use A0 instead of 0.
Solution
Step 1: Check analogRead() argument
Using analogRead(0) reads digital pin 0, which is incorrect for analog input.
Step 2: Use A0 for analog pin 0
The correct syntax is analogRead(A0) to read analog pin A0.
Final Answer:
analogRead() should use A0 instead of 0. -> Option D
Quick Check:
Use A0 constant for analog pins [OK]
Hint: Use A0, A1, etc. for analogRead() pins [OK]
Common Mistakes:
Using integer 0 instead of A0 in analogRead()
Thinking Serial.print() must be println() always
Believing delay() is not allowed in loop()
Calling Serial.begin() inside loop()
5.
You want to turn on a water pump when the soil moisture is below 300. Which code snippet correctly implements this using a soil moisture sensor on A0 and a pump connected to digital pin 7?