Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set the sensor pin as input.
Arduino
const int sensorPin = 2; void setup() { pinMode([1], INPUT); } void loop() {}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the buzzer pin instead of the sensor pin.
Setting the pin mode to OUTPUT instead of INPUT.
✗ Incorrect
The sensor pin must be set as input to read sensor data.
2fill in blank
mediumComplete the code to read the sensor value inside the loop.
Arduino
const int sensorPin = 2; int sensorValue; void setup() { pinMode(sensorPin, INPUT); } void loop() { sensorValue = [1](sensorPin); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using digitalWrite() instead of digitalRead().
Using analogRead() for a digital sensor.
✗ Incorrect
Use digitalRead() to read a digital sensor value from the sensor pin.
3fill in blank
hardFix the error in the code to turn on the buzzer when the sensor is triggered.
Arduino
const int sensorPin = 2; const int buzzerPin = 8; void setup() { pinMode(sensorPin, INPUT); pinMode(buzzerPin, OUTPUT); } void loop() { if (digitalRead(sensorPin) == [1]) { digitalWrite(buzzerPin, HIGH); } else { digitalWrite(buzzerPin, LOW); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing sensor reading to LOW instead of HIGH.
Using pin modes instead of HIGH/LOW values.
✗ Incorrect
The buzzer should turn on when the sensor reads HIGH (triggered).
4fill in blank
hardFill both blanks to make the buzzer beep for 1 second when triggered.
Arduino
const int sensorPin = 3; const int buzzerPin = 9; void setup() { pinMode(sensorPin, INPUT); pinMode(buzzerPin, OUTPUT); } void loop() { if (digitalRead(sensorPin) == [1]) { digitalWrite(buzzerPin, HIGH); delay([2]); digitalWrite(buzzerPin, LOW); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using LOW instead of HIGH for sensor trigger.
Using 500 ms delay instead of 1000 ms.
✗ Incorrect
The buzzer should turn on when sensor reads HIGH and delay 1000 milliseconds (1 second).
5fill in blank
hardFill all three blanks to create a dictionary-like structure that maps sensor states to buzzer actions.
Arduino
const int sensorPin = 4; const int buzzerPin = 10; void setup() { pinMode(sensorPin, INPUT); pinMode(buzzerPin, OUTPUT); } void loop() { int state = digitalRead(sensorPin); switch(state) { case [1]: digitalWrite(buzzerPin, [2]); break; case [3]: digitalWrite(buzzerPin, LOW); break; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up HIGH and LOW values in cases.
Using pin modes instead of HIGH/LOW values.
✗ Incorrect
When sensor state is HIGH, buzzer turns HIGH; when LOW, buzzer turns LOW.
