← If / else with sensors lesson New set →

Electronics Worksheet: If Else with Sensors

Electronics lesson 24: If / else with sensors · Set 124 · 40 questions
TalentJR

Remember (Test, then choose): Put the reading into the condition: true → the if part, false → the else part. > means strictly more and < strictly less; an equal reading makes them false. AND: both true. OR: at least one true. In a chain, the first true condition wins.

NameDateTime takenScore ___ / 40
  1. 1.🤖 if (light < 500) { lamp ON } else { lamp OFF }
    The light sensor reads 556. What happens?
    (a) lamp OFF (b) lamp ON
  2. 2.🤖 In “if (temp > 30)”, what runs when temp is exactly 30? (a) the if part (b) the else part (c) both parts (d) neither part
  3. 3.🤖 if (temperature > 30) { show “Hot” } else if (temperature > 25) { show “Warm” } else { show “Cool” }
    The temperature is 15 °C. What is shown?
    (a) Hot (b) Cool (c) Warm
  4. 4.🤖 if (temperature > 31) { show “Hot” } else if (temperature > 19) { show “Warm” } else { show “Cool” }
    The temperature is 15 °C. What is shown?
    (a) Hot (b) Warm (c) Cool
  5. 5.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 590 and motion is detected (true). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  6. 6.🤖 if (temperature > 38) { show “Hot” } else if (temperature > 26) { show “Warm” } else { show “Cool” }
    The temperature is 28 °C. What is shown?
    (a) Cool (b) Hot (c) Warm
  7. 7.🤖 if (distance < 10) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 8 cm. What happens?
    (a) buzzer beeps (b) buzzer is silent
  8. 8.🤖 if (moisture < 50) { pump ON } else { pump OFF }
    The soil moisture sensor reads 60 %. What happens?
    (a) pump OFF (b) pump ON
  9. 9.🤖 if (distance < 10) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 6 cm. What happens?
    (a) buzzer is silent (b) buzzer beeps
  10. 10.🤖 if (distance < 20) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 26 cm. What happens?
    (a) buzzer is silent (b) buzzer beeps
  11. 11.🤖 if (temperature > 34) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
    The temperature is 27 °C. What is shown?
    (a) Cool (b) Warm (c) Hot
  12. 12.🤖 if (temperature > 33) { show “Hot” } else if (temperature > 22) { show “Warm” } else { show “Cool” }
    The temperature is 37 °C. What is shown?
    (a) Cool (b) Hot (c) Warm
  13. 13.🤖 if (temperature > 32) { fan ON } else { fan OFF }
    The temperature sensor reads 29 °C. What happens?
    (a) fan OFF (b) fan ON
  14. 14.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 370 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  15. 15.🤖 if (moisture < 30) { pump ON } else { pump OFF }
    The soil moisture sensor reads 15 %. What happens?
    (a) pump OFF (b) pump ON
  16. 16.🤖 if (temperature > 30) { show “Hot” } else if (temperature > 18) { show “Warm” } else { show “Cool” }
    The temperature is 19 °C. What is shown?
    (a) Warm (b) Cool (c) Hot
  17. 17.🤖 “if (A AND B)” is true when … (a) only B is true (b) both A and B are true (c) both are false (d) only A is true
  18. 18.🤖 if (temperature > 34) { show “Hot” } else if (temperature > 24) { show “Warm” } else { show “Cool” }
    The temperature is 40 °C. What is shown?
    (a) Warm (b) Hot (c) Cool
  19. 19.🤖 if (temperature > 25) { fan ON } else { fan OFF }
    The temperature sensor reads 21 °C. What happens?
    (a) fan ON (b) fan OFF
  20. 20.🤖 if (temperature > 33) { show “Hot” } else if (temperature > 18) { show “Warm” } else { show “Cool” }
    The temperature is 21 °C. What is shown?
    (a) Cool (b) Warm (c) Hot
  21. 21.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 110 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  22. 22.🤖 if (light < 300) { lamp ON } else { lamp OFF }
    The light sensor reads 155. What happens?
    (a) lamp OFF (b) lamp ON
  23. 23.🤖 if (light < 400 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 350 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  24. 24.🤖 if (moisture < 40) { pump ON } else { pump OFF }
    The soil moisture sensor reads 59 %. What happens?
    (a) pump OFF (b) pump ON
  25. 25.🤖 if (light < 300 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 270 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  26. 26.🤖 if (light < 200) { lamp ON } else { lamp OFF }
    The light sensor reads 223. What happens?
    (a) lamp ON (b) lamp OFF
  27. 27.🤖 if (moisture < 30) { pump ON } else { pump OFF }
    The soil moisture sensor reads 16 %. What happens?
    (a) pump OFF (b) pump ON
  28. 28.🤖 if (light < 300 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 120 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  29. 29.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 380 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  30. 30.🤖 if (temperature > 30) { fan ON } else { fan OFF }
    The temperature sensor reads 31 °C. What happens?
    (a) fan ON (b) fan OFF
  31. 31.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 530 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  32. 32.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 26) { show “Warm” } else { show “Cool” }
    The temperature is 24 °C. What is shown?
    (a) Hot (b) Warm (c) Cool
  33. 33.🤖 if (light < 300 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 370 and motion is detected (true). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  34. 34.🤖 if (light < 400 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 510 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  35. 35.🤖 if (temperature > 32) { show “Hot” } else if (temperature > 25) { show “Warm” } else { show “Cool” }
    The temperature is 22 °C. What is shown?
    (a) Hot (b) Warm (c) Cool
  36. 36.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 70 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  37. 37.🤖 if (temperature > 35) { show “Hot” } else if (temperature > 23) { show “Warm” } else { show “Cool” }
    The temperature is 35 °C. What is shown?
    (a) Hot (b) Warm (c) Cool
  38. 38.🤖 if (light < 400) { lamp ON } else { lamp OFF }
    The light sensor reads 341. What happens?
    (a) lamp OFF (b) lamp ON
  39. 39.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 640 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  40. 40.🤖 if (distance < 10) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 19 cm. What happens?
    (a) buzzer beeps (b) buzzer is silent

Answer key

  1. lamp OFF
  2. the else part
  3. Cool
  4. Cool
  5. porch lamp ON
  6. Warm
  7. buzzer beeps
  8. pump OFF
  9. buzzer beeps
  10. buzzer is silent
  11. Warm
  12. Hot
  13. fan OFF
  14. porch lamp OFF
  15. pump ON
  16. Warm
  17. both A and B are true
  18. Hot
  19. fan OFF
  20. Warm
  21. porch lamp ON
  22. lamp ON
  23. porch lamp OFF
  24. pump OFF
  25. porch lamp ON
  26. lamp OFF
  27. pump ON
  28. porch lamp ON
  29. porch lamp OFF
  30. fan ON
  31. porch lamp OFF
  32. Cool
  33. porch lamp OFF
  34. porch lamp OFF
  35. Cool
  36. porch lamp ON
  37. Warm
  38. lamp ON
  39. porch lamp OFF
  40. buzzer is silent

Free electronics lessons, practice and worksheets at talentjr.in/electronics-for-kids