Complete the code to read the IR sensor value.
int sensorValue = analogRead([1]);The IR sensor is connected to analog pin A0, so we use analogRead(A0) to get its value.
Complete the code to set the IR sensor pin as input in setup().
pinMode([1], INPUT);The IR sensor is connected to analog pin A0, which should be set as input using pinMode(A0, INPUT);.
Fix the error in the if statement to detect obstacle when sensor value is less than threshold.
if (sensorValue [1] threshold) { Serial.println("Obstacle detected"); }
When the IR sensor detects an obstacle, the sensor value is usually less than the threshold, so the condition should be sensorValue < threshold.
Fill both blanks to complete the code that reads sensor and prints "No obstacle" when value is above threshold.
sensorValue = analogRead([1]); if (sensorValue [2] threshold) { Serial.println("No obstacle"); }
The sensor is read from analog pin A0, and when the value is greater than the threshold, it means no obstacle is detected.
Fill all three blanks to create a dictionary-like structure that maps sensor states to messages.
const char* messages[] = {"[1]", "[2]"};
int sensorValue = analogRead(A0);
Serial.println(sensorValue [3] threshold ? messages[0] : messages[1]);The messages array holds the two messages. The condition uses < to check if sensorValue is below threshold, printing "Obstacle detected" if true, otherwise "No obstacle".
