powered by TinkerSpace.in
Join free
TinkerPy Tutorial ๐Ÿ“˜ Part 1 ยท Starter ยท Chapter 9 of 24

All Digital & Analog Input Modules

Buttons, magnets, flames, rain, smoke, claps and footsteps โ€” your board can feel them all! Meet every input module in TinkerPyโ€™s Circuit Connections, find out what ON means for each one, and learn which ones give a number instead.

๐Ÿ“–Key words

Input module

A small board with a sensor or switch that you connect to a pin. You pick it on the pin in Circuit Connections.

ON meaning

What ON stands for on that module: PRESSED for a button, MOTION for a PIR, DRY for a soil sensor, DARK for a light sensor.

Dual module

A module with two outputs โ€” a digital one (ON/OFF) and an analog one (0โ€“100). You choose which one to use: LDR, soil and gas modules are dual.

Threshold

The point where ON changes to OFF. On many digital sensor modules you set it by turning a tiny screw (a preset) with a screwdriver.

Auto name

Circuit Connections gives every new part a name like motion_sensor_1 or knob_1. You can change it to anything you like.

๐ŸŽฌSee it work

Digital or analog?

Tap the right group for each module: ON/OFF only, 0โ€“100 only, or both.

Three invisible-light sensors

Tap each one: they all use light you canโ€™t see, but they notice different things.

๐Ÿง How it works

Buttons, switches and touch

  • Push button ๐Ÿ”˜ โ€” ON = PRESSED (only while you hold it). Slide switch โ†”๏ธ โ€” stays where you slide it. Switch ๐ŸŽš๏ธ โ€” any plain switch.
  • Limit switch ๐Ÿ›‘ โ€” ON = HIT: a tiny lever that a moving part bumps into, like a door or a robot arm at its end.
  • Touch ๐Ÿ‘† โ€” ON = TOUCHED, no pressing needed. Usual mode active_high.
  • Reed ๐Ÿšช โ€” ON = CLOSED: a magnet on the door comes near. Hall ๐Ÿงฒ โ€” ON = MAGNET nearby. Tilt ๐Ÿ“ โ€” ON = TILTED.
  • All of these are ON/OFF modules, usual mode active_low (except touch), and work on any pin.

Motion, sound, fire, water and gas

  • PIR ๐Ÿšถ ON = MOTION (active_high) ยท IR obstacle ๐Ÿ–๏ธ ON = OBJECT ยท Line โž– ON = BLACK ยท Vibration ๐Ÿ“ณ ON = SHAKING.
  • Sound / clap ๐Ÿ‘ ON = SOUND (a short clap or knock) ยท Flame ๐Ÿ”ฅ ON = FIRE.
  • Rain ๐ŸŒง๏ธ ON = RAIN (drops on its plate) ยท Water leak ๐Ÿ’ง ON = WATER on the floor.
  • Dual modules โ€” ON/OFF or 0โ€“100: Light (LDR) ๐ŸŒ— ON = DARK ยท Soil ๐ŸŒฑ ON = DRY ยท LPG gas (MQ-2/6) โ›ฝ ON = GAS ยท Alcohol (MQ-3) ๐Ÿบ ON = ALCOHOL ยท Air quality (MQ-135) ๐ŸŒซ๏ธ ON = BAD AIR.
  • Gas sensors are for learning and early warning โ€” a real home gas leak needs an adult and a proper safety alarm.

Analog modules: a number from 0 to 100

  • Knob (potentiometer) ๐ŸŽ›๏ธ โ€” how far it is turned. Water level ๐Ÿšฐ โ€” how much of its strip is under water.
  • Temperature ๐ŸŒก๏ธ โ€” a number that changes with heat (warm it with your hand to see which way it moves). For real ยฐC, use the DHT11 (chapter 12).
  • Flex ใ€ฐ๏ธ โ€” how much it bends: great for a glove that reads finger bends.
  • Dual modules in adc mode get a new name: Light level, Soil level, LPG levelโ€ฆ
  • Analog modules work only on input pins: i1โ€“i4 on the Mega, i1โ€“i2 on the Mini.

Picking the right module

  • Ask: do I need yes/no (is there fire?) or how much (how full is the tank)? Yes/no โ†’ digital; how much โ†’ analog.
  • Tap a pin in Circuit Connections โ†’ pick the module โ†’ it writes the setup line with the usual mode and an auto name you can change.
  • Many digital sensor modules have a small preset screw to set the threshold โ€” turn it gently until ON happens at the right moment.
  • Youโ€™ll code readings, thresholds and voltage() in depth in TinkerPy Coder chapter 1.

๐Ÿ’ปCode

Text
Input module          ON means    Usual mode     Pins
--------------------  ----------  -------------  ------------------------
Switch                ON          active_low     any pin (or adc on i1-i4)
Push button           PRESSED     active_low     any pin
Slide switch          ON          active_low     any pin
Limit switch          HIT         active_low     any pin
Touch                 TOUCHED     active_high    any pin
Motion (PIR)          MOTION      active_high    any pin
IR obstacle           OBJECT      active_low     any pin
Sound / clap          SOUND       active_low     any pin
Flame                 FIRE        active_low     any pin
Vibration             SHAKING     active_low     any pin
Reed (door)           CLOSED      active_low     any pin
Hall (magnet)         MAGNET      active_low     any pin
Tilt                  TILTED      active_low     any pin
Rain                  RAIN        active_low     any pin
Water leak            WATER       active_low     any pin
Line (IR)             BLACK       active_low     any pin
Light (LDR)       *   DARK        active_low     any pin (or adc on i1-i4)
Soil moisture     *   DRY         active_low     any pin (or adc on i1-i4)
LPG gas (MQ-2/6)  *   GAS         active_low     any pin (or adc on i1-i4)
Alcohol (MQ-3)    *   ALCOHOL     active_low     any pin (or adc on i1-i4)
Air quality       *   BAD AIR     active_low     any pin (or adc on i1-i4)
Knob (pot)            0-100       adc            i1-i4 only
Water level           0-100       adc            i1-i4 only
Temperature           0-100       adc            i1-i4 only
Flex                  0-100       adc            i1-i4 only

* = dual module: ON/OFF or a 0-100 level.   Mini: input pins are i1-i2.

Every digital and analog input module in Circuit Connections, with what ON means, its usual mode and the pins it can use. โ€œAny pinโ€ means i1โ€“i4 or a free output pin used as an input. DHT11, joystick, TV remote, GPS and GSM have their own wiring โ€” they are in chapter 12.

# Give your pins easy-to-remember names
i1 = set_name("motion")
o1 = set_name("lamp")

# ===== Corridor light =====

# This code block executes only once
setup:
    motion = set_input(pir, active_high)
    lamp = set_output(led)

# This code block executes forever
loop:
    if motion == ON:  # when motion is ON
        lamp = ON  # turn lamp ON
        wait(5000)  # stay on for 5 seconds
    else:  # otherwise
        lamp = OFF  # turn lamp OFF

A corridor light: the PIR on i1 (named motion, usual mode active_high) turns the lamp on for 5 seconds whenever someone walks past.

# Add the libraries you need
import buzzer

# Give your pins easy-to-remember names
i1 = set_name("fire")
i2 = set_name("gas")
o1 = set_name("alarm")

# ===== Kitchen safety alarm =====

# This code block executes only once
setup:
    fire = set_input(flame, active_low)
    gas = set_input(lpg, active_low)
    alarm = set_output(buzzer)

# This code block executes forever
loop:
    if fire == ON or gas == ON:  # when fire is ON or gas is ON
        alarm = ON  # turn alarm ON
    else:  # otherwise
        alarm = OFF  # turn alarm OFF

A kitchen safety alarm: a flame sensor (fire) and an LPG gas sensor (gas), both active_low, sound the buzzer if either one is ON. Practise with a candle only with an adult โ€” never test with a real gas leak.

# Give your pins easy-to-remember names
i1 = set_name("tank")
o1 = set_name("full_light")

# ===== Tank full alarm =====

# This code block executes only once
setup:
    tank = set_input(water_level, adc)
    full_light = set_output(led)

# This code block executes forever
loop:
    level = analog_read(tank)  # 0 (dry) to 100 (deep in water)
    if level > 80:  # when level > 80
        full_light = ON  # turn full_light ON
    else:  # otherwise
        full_light = OFF  # turn full_light OFF
    wait(500)  # pause here for 500 milliseconds before continuing

A tank-full light: the water level sensor on i1 is an analog module (adc), so analog_read(tank) gives 0 to 100. Above 80, the full_light comes on.

Open TinkerPy Code

๐ŸŽ‰Fun examples

๐ŸšชSecret magnet

Many home alarms use a reed switch: a magnet on the door and a switch on the frame. Open the door, the magnet moves away โ€” alarm!

๐Ÿ‘Clap lamp

With a sound sensor you can switch a lamp with a clap. Two claps for ON and one for OFF is a fun coding puzzle.

๐ŸงคTalking glove

Flex sensors on a glove can tell how much each finger bends โ€” inventors use them to turn hand signs into words.

๐ŸŒWhere itโ€™s used

๐Ÿ› ๏ธProject ideas

Smart doorbell plan

On paper, plan a doorbell that rings when the button is pressed AND lights a porch LED when someone walks up (PIR). List each module, its pin, its name, what ON means and its mode โ€” then build it in Circuit Connections.

๐Ÿงฐ You need: push button, PIR sensor, buzzer, LED, TinkerPy board or Simulator
Sensor treasure hunt

Walk around your home or school and list 10 places where one of this chapterโ€™s sensors could help (rain on the terrace, water on the bathroom floorโ€ฆ). For each, write the module name and whether it is digital or analog.

๐Ÿงฐ You need: notebook, pencil

โญPoints to remember

  1. Pick every input module on a pin in Circuit Connections.
  2. Each module has its own meaning of ON (PRESSED, MOTION, FIREโ€ฆ).
  3. Most modules are active_low; touch and PIR are active_high.
  4. ON/OFF modules work on any pin, even a free output pin.
  5. Knob, water level, temperature and flex give 0โ€“100.
  6. Analog modules need an input pin (i1โ€“i4, Mini i1โ€“i2).
  7. LDR, soil and gas modules are dual: ON/OFF or 0โ€“100.
  8. Light sensor ON = DARK; soil sensor ON = DRY.
  9. Reed switch ON = CLOSED (magnet near).
  10. Line sensor ON = BLACK line under it.
  11. Many digital modules have a preset screw for the threshold.
  12. New parts get auto names like motion_sensor_1.
  13. Yes/no question โ†’ digital; how much โ†’ analog.
๐Ÿคฏ
Did you know?

A PIR sensor doesnโ€™t see light at all โ€” it feels the invisible infrared heat that every warm body gives off, so it can spot a person even in a dark room.

โ“Mini quiz

๐Ÿ”‘
Log in to try the mini quiz

5 quick questions to check yourself โ€” free with your TinkerPy account.

Log in