Complete the code to set the sensor pin as input.
const int sensorPin = 2; void setup() { pinMode([1], INPUT); } void loop() {}
The sensor pin must be set as input to read sensor data.
Complete the code to read the sensor value inside the loop.
const int sensorPin = 2; int sensorValue; void setup() { pinMode(sensorPin, INPUT); } void loop() { sensorValue = [1](sensorPin); }
Use digitalRead() to read a digital sensor value from the sensor pin.
Fix the error in the code to turn on the buzzer when the sensor is triggered.
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); } }
The buzzer should turn on when the sensor reads HIGH (triggered).
Fill both blanks to make the buzzer beep for 1 second when triggered.
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); } }
The buzzer should turn on when sensor reads HIGH and delay 1000 milliseconds (1 second).
Fill all three blanks to create a dictionary-like structure that maps sensor states to buzzer actions.
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; } }
When sensor state is HIGH, buzzer turns HIGH; when LOW, buzzer turns LOW.
