Bird
0
0
Arduinoprogramming~10 mins

Alarm system with sensor and buzzer in Arduino - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A13
BOUTPUT
CbuzzerPin
DsensorPin
Attempts:
3 left
💡 Hint
Common Mistakes
Using the buzzer pin instead of the sensor pin.
Setting the pin mode to OUTPUT instead of INPUT.
2fill in blank
medium

Complete 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'
AanalogRead
BdigitalWrite
CdigitalRead
DanalogWrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using digitalWrite() instead of digitalRead().
Using analogRead() for a digital sensor.
3fill in blank
hard

Fix 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'
AHIGH
BLOW
CINPUT
DOUTPUT
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing sensor reading to LOW instead of HIGH.
Using pin modes instead of HIGH/LOW values.
4fill in blank
hard

Fill 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'
AHIGH
BLOW
C1000
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using LOW instead of HIGH for sensor trigger.
Using 500 ms delay instead of 1000 ms.
5fill in blank
hard

Fill 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'
AHIGH
BLOW
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up HIGH and LOW values in cases.
Using pin modes instead of HIGH/LOW values.