Electronics · lesson 24 of 30 · free

If / else with sensors — Electronics for kids

Microcontroller programs make decisions with if / else. “if (temperature > 30) { fan ON } else { fan OFF }” switches the fan on only when the reading is more than 30 — exactly 30 is not more, so the else part runs. A chain like if / else if / else picks one of three answers, and AND needs both conditions true while OR needs at least one.

▶ Watch how it works

Got it? Practise ↓

Remember

Test, then choose — “if the condition is true do the first part, otherwise the else part”

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

Use it for: Programming sensors on a microcontroller board, automatic lights and fans, and coding logic lessons.

Worked example: 🤖 if (temperature > 30) { fan ON } else { fan OFF } The temperature sensor reads 32 °C. What happens? → fan ON

  1. Is 32 more than 30? Yes — the condition is true.
  2. So the if part runs: fan ON.

Check: At 30 °C the condition is false — fan OFF ✓

▶ Watch it animated

✏️ Practice

Work it out in your head or on paper, type the answer and press Check. Stuck? Press “Show me how”.

Right: 0 · Tried: 0

🏁 Lesson 24 test

20 questions. Check each answer, then go to the next one. Get 16 or more right to pass.

🏅 Sign in with Google to earn the 🔀 Sensor Decider badge when you pass — and a certificate when you finish all 10 lessons of Part 3 · Microcontrollers and IoT. You can still take the test without signing in.

🖨️ Electronics Worksheet: If Else with Sensors

✨ Free AI tutor

Ask the AI tutor about this lesson

Why does it work? When should you use it? Ask in English, मराठी or हिंदी.

Sign in with Google to ask Free — 20 questions a day.

👩‍🏫 Electronics classes near you — online or at home

Prefer a real teacher? TalentJR teachers take live online classes anywhere in India and visit homes in selected cities. Tell us what you need and our team will call you with timings and fees.

Live online classesSmall groups or 1:1 with a teacher, from home, any city.
Teacher at homeA TalentJR teacher visits your home (selected cities).
At a centreClasses at a TalentJR partner centre near you, where available.
Badges, certificates & gifts A badge for every lesson you pass, a certificate for every part you finish, plus TalentJR Points for daily practice. Computer worksheets Flowcharts, block coding and spreadsheets.