Challenge - 5 Problems
Soil Moisture Sensor Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Reading soil moisture sensor value
What is the output on the serial monitor when this Arduino code runs with the sensor reading analog value 600?
Arduino
int sensorPin = A0; void setup() { Serial.begin(9600); } void loop() { int sensorValue = analogRead(sensorPin); Serial.println(sensorValue); delay(1000); }
Attempts:
2 left
💡 Hint
The analogRead function returns a value between 0 and 1023 based on the sensor voltage.
✗ Incorrect
The analogRead function reads the voltage on the sensor pin and returns a value from 0 (0V) to 1023 (5V). If the sensor outputs a voltage corresponding to 600, that value is printed.
🧠 Conceptual
intermediate1:30remaining
Understanding soil moisture sensor output range
Which statement correctly describes the soil moisture sensor output when connected to Arduino analog pin?
Attempts:
2 left
💡 Hint
Think about how analog sensors work with Arduino analog pins.
✗ Incorrect
Soil moisture sensors output an analog voltage that changes depending on the moisture level. Arduino reads this voltage as an analog value.
🔧 Debug
advanced2:00remaining
Fixing incorrect sensor reading code
What error does this Arduino code produce when trying to read soil moisture sensor value?
int sensorPin = A0
void setup() {
Serial.begin(9600);
}
void loop() {
int moisture = analogRead(sensorPin);
Serial.println(moisture);
delay(1000);
}
Arduino
int sensorPin = A0; void setup() { Serial.begin(9600); } void loop() { int moisture = analogRead(sensorPin); Serial.println(moisture); delay(1000); }
Attempts:
2 left
💡 Hint
Check the line where sensorPin is declared.
✗ Incorrect
In Arduino C++, each statement must end with a semicolon. Missing it causes a syntax error.
❓ Predict Output
advanced2:00remaining
Calculating moisture percentage from sensor value
What is the output of this code if analogRead returns 512?
int sensorPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(sensorPin);
int moisturePercent = map(sensorValue, 0, 1023, 0, 100);
Serial.println(moisturePercent);
delay(1000);
}
Arduino
int sensorPin = A0; void setup() { Serial.begin(9600); } void loop() { int sensorValue = analogRead(sensorPin); int moisturePercent = map(sensorValue, 0, 1023, 0, 100); Serial.println(moisturePercent); delay(1000); }
Attempts:
2 left
💡 Hint
The map function converts a number from one range to another.
✗ Incorrect
The map function converts 512 from range 0-1023 to 0-100. 512 is about half of 1023, so output is about 50.
🧠 Conceptual
expert2:30remaining
Choosing correct sensor pin and reading method
Which option correctly explains why soil moisture sensor must be connected to an analog pin and read with analogRead() on Arduino?
Attempts:
2 left
💡 Hint
Think about the difference between analog and digital pins on Arduino.
✗ Incorrect
Soil moisture sensors output analog voltages. Arduino digital pins read only HIGH or LOW (digital). Analog pins can read varying voltages using analogRead().
