Electronics Worksheet: If Else with Sensors
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.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
The light reading is 400 and motion is detected (true). What happens? (a) porch lamp ON (b) porch lamp OFF -
2.🤖 if (temperature > 37) { show “Hot” } else if (temperature > 18) { show “Warm” } else { show “Cool” }
The temperature is 16 °C. What is shown? (a) Cool (b) Hot (c) Warm -
3.🤖 if (distance < 20) { buzzer beeps } else { buzzer is silent }
The distance sensor reads 17 cm. What happens? (a) buzzer is silent (b) buzzer beeps -
4.🤖 if (distance < 10) { buzzer beeps } else { buzzer is silent }
The distance sensor reads 11 cm. What happens? (a) buzzer beeps (b) buzzer is silent - 5.🤖 “if (A AND B)” is true when … (a) only B is true (b) both are false (c) both A and B are true (d) only A is true
-
6.🤖 if (temperature > 37) { show “Hot” } else if (temperature > 25) { show “Warm” } else { show “Cool” }
The temperature is 18 °C. What is shown? (a) Warm (b) Hot (c) Cool -
7.🤖 if (temperature > 37) { show “Hot” } else if (temperature > 21) { show “Warm” } else { show “Cool” }
The temperature is 10 °C. What is shown? (a) Warm (b) Hot (c) Cool -
8.🤖 if (temperature > 35) { show “Hot” } else if (temperature > 21) { show “Warm” } else { show “Cool” }
The temperature is 38 °C. What is shown? (a) Warm (b) Hot (c) Cool -
9.🤖 if (temperature > 32) { show “Hot” } else if (temperature > 24) { show “Warm” } else { show “Cool” }
The temperature is 15 °C. What is shown? (a) Warm (b) Cool (c) Hot -
10.🤖 if (temperature > 30) { fan ON } else { fan OFF }
The temperature sensor reads 36 °C. What happens? (a) fan ON (b) fan OFF -
11.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
The light reading is 450 and motion is not detected (false). What happens? (a) porch lamp ON (b) porch lamp OFF -
12.🤖 if (light < 300 AND motion) { porch lamp ON } else { porch lamp OFF }
The light reading is 80 and motion is not detected (false). What happens? (a) porch lamp ON (b) porch lamp OFF -
13.🤖 if (temperature > 28) { fan ON } else { fan OFF }
The temperature sensor reads 34 °C. What happens? (a) fan ON (b) fan OFF -
14.🤖 if (temperature > 33) { show “Hot” } else if (temperature > 18) { show “Warm” } else { show “Cool” }
The temperature is 41 °C. What is shown? (a) Warm (b) Cool (c) Hot -
15.🤖 if (temperature > 34) { show “Hot” } else if (temperature > 19) { show “Warm” } else { show “Cool” }
The temperature is 12 °C. What is shown? (a) Hot (b) Cool (c) Warm -
16.🤖 if (moisture < 30) { pump ON } else { pump OFF }
The soil moisture sensor reads 34 %. What happens? (a) pump ON (b) pump OFF -
17.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
The light reading is 180 and motion is not detected (false). What happens? (a) porch lamp OFF (b) porch lamp ON -
18.🤖 if (light < 300 AND motion) { porch lamp ON } else { porch lamp OFF }
The light reading is 280 and motion is not detected (false). What happens? (a) porch lamp OFF (b) porch lamp ON -
19.🤖 if (temperature > 30) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
The temperature is 37 °C. What is shown? (a) Cool (b) Hot (c) Warm -
20.🤖 if (temperature > 32) { show “Hot” } else if (temperature > 22) { show “Warm” } else { show “Cool” }
The temperature is 16 °C. What is shown? (a) Warm (b) Cool (c) Hot -
21.🤖 if (moisture < 40) { pump ON } else { pump OFF }
The soil moisture sensor reads 37 %. What happens? (a) pump OFF (b) pump ON -
22.🤖 if (light < 200) { lamp ON } else { lamp OFF }
The light sensor reads 83. What happens? (a) lamp OFF (b) lamp ON -
23.🤖 if (temperature > 30) { fan ON } else { fan OFF }
The temperature sensor reads 23 °C. What happens? (a) fan ON (b) fan OFF -
24.🤖 if (sound > 80) { red LED ON } else { green LED ON }
The sound sensor reads 68. What happens? (a) green LED ON (b) red LED ON -
25.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 19) { show “Warm” } else { show “Cool” }
The temperature is 15 °C. What is shown? (a) Cool (b) Hot (c) Warm -
26.🤖 if (temperature > 38) { show “Hot” } else if (temperature > 18) { show “Warm” } else { show “Cool” }
The temperature is 13 °C. What is shown? (a) Hot (b) Cool (c) Warm -
27.🤖 if (light < 300) { lamp ON } else { lamp OFF }
The light sensor reads 334. What happens? (a) lamp OFF (b) lamp ON -
28.🤖 if (temperature > 32) { fan ON } else { fan OFF }
The temperature sensor reads 40 °C. What happens? (a) fan ON (b) fan OFF - 29.🤖 In “if (temp > 30)”, what runs when temp is exactly 30? (a) both parts (b) the if part (c) neither part (d) the else part
-
30.🤖 if (temperature > 30) { show “Hot” } else if (temperature > 26) { show “Warm” } else { show “Cool” }
The temperature is 10 °C. What is shown? (a) Hot (b) Warm (c) Cool -
31.🤖 if (moisture < 50) { pump ON } else { pump OFF }
The soil moisture sensor reads 38 %. What happens? (a) pump OFF (b) pump ON -
32.🤖 if (moisture < 50) { pump ON } else { pump OFF }
The soil moisture sensor reads 48 %. What happens? (a) pump ON (b) pump OFF -
33.🤖 if (sound > 60) { red LED ON } else { green LED ON }
The sound sensor reads 52. What happens? (a) green LED ON (b) red LED ON -
34.🤖 if (light < 200) { lamp ON } else { lamp OFF }
The light sensor reads 279. What happens? (a) lamp ON (b) lamp OFF -
35.🤖 if (moisture < 40) { pump ON } else { pump OFF }
The soil moisture sensor reads 49 %. What happens? (a) pump OFF (b) pump ON -
36.🤖 if (temperature > 33) { show “Hot” } else if (temperature > 19) { show “Warm” } else { show “Cool” }
The temperature is 11 °C. What is shown? (a) Hot (b) Warm (c) Cool -
37.🤖 if (moisture < 50) { pump ON } else { pump OFF }
The soil moisture sensor reads 51 %. What happens? (a) pump ON (b) pump OFF -
38.🤖 if (light < 300 OR motion) { porch lamp ON } else { porch lamp OFF }
The light reading is 130 and motion is not detected (false). What happens? (a) porch lamp ON (b) porch lamp OFF -
39.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
The light reading is 330 and motion is not detected (false). What happens? (a) porch lamp OFF (b) porch lamp ON -
40.🤖 if (temperature > 30) { fan ON } else { fan OFF }
The temperature sensor reads 25 °C. What happens? (a) fan ON (b) fan OFF
Answer key
- porch lamp OFF
- Cool
- buzzer beeps
- buzzer is silent
- both A and B are true
- Cool
- Cool
- Hot
- Cool
- fan ON
- porch lamp OFF
- porch lamp OFF
- fan ON
- Hot
- Cool
- pump OFF
- porch lamp OFF
- porch lamp OFF
- Hot
- Cool
- pump ON
- lamp ON
- fan OFF
- green LED ON
- Cool
- Cool
- lamp OFF
- fan ON
- the else part
- Cool
- pump ON
- pump ON
- green LED ON
- lamp OFF
- pump OFF
- Cool
- pump OFF
- porch lamp ON
- porch lamp OFF
- fan OFF
Free electronics lessons, practice and worksheets at talentjr.in/electronics-for-kids