📘 CodingMarble Learn

Open-Source Hardware Projects: Pins, Input/Output Modules, Communication and Workflow

An open-source hardware board is a small computer with pins. Digital pins read or write ON/OFF (HIGH or LOW). Analog pins read a changing level as a number, usually 0 to 1023. Power pins give 5 V, 3.3 V and ground. Input modules (button, sensor) send information in; output modules (LED, buzzer, motor) act on it. Boards talk to a computer or other boards by serial communication using TX and RX. A project runs setup once, then repeats a loop: read, decide, act and report.

🎬 Step-by-step story

  1. The board has pins along its edges. Digital pins are ON/OFF, analog pins read levels, and power pins give 5 V and ground.
  2. An input module tells the board about the world. Press the button: pin 2 changes from LOW to HIGH.
  3. An output module obeys the board. The board makes pin 13 HIGH and the LED lights up.
  4. Communication: the board sends words through its TX wire to the computer's RX. The message shows on screen.
  5. The work order: setup runs once, then the loop repeats again and again: read, decide, act, report.
  6. Free play: press the button and move the sensor and limit sliders. The LED turns on by a rule you can read.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

What is the difference between digital and analog pins?

A digital pin knows only HIGH or LOW. An analog pin measures a level and gives a number from 0 to 1023. See the three coloured pin groups in the 3D.

Why does pressing a button change a number on the pin?

Pressing joins the pin to the supply, so the pin reads HIGH. Without pressing, it reads LOW. Press the button and watch the pin reading.

Why can't I connect an LED straight to a pin?

Too much current can burn the LED. A resistor in series limits the current. The output module in step 2 is always used with a resistor.

Why do I connect TX to RX and not TX to TX?

One device talks while the other listens. The talker's TX must reach the listener's RX. Follow the wire in step 3.

What is the difference between setup() and loop()?

setup() runs once at the start to prepare pins and serial. loop() runs again and again. The purple ring shows the repeating loop.

How do button and sensor decide the LED together?

The rule in the readout says: LED is ON if the button is pressed OR the sensor is above the limit. Change both and check the readout.

What is open-source hardware?

Open-source hardware is hardware whose design files are shared openly: the circuit diagram, the board layout and the code. Anyone can study it, build it and improve it. Popular examples are Arduino-style boards, Raspberry Pi and many sensor modules.

A microcontroller board is a tiny computer on one chip with pins to connect the outside world.

Pins: digital, analog and power

A pin is a metal connector that joins the board to a wire or module.

Pins are set as INPUT or OUTPUT in the setup. Wrong direction is a common mistake.

Input and output modules

A module is a small ready-made board for one job.

Reading and writing in code looks like digitalRead(2), analogRead(A0) and digitalWrite(13, HIGH). A button needs a pull-up or pull-down resistor so the pin never floats between HIGH and LOW. An LED needs a resistor (for example 220 Ω) so too much current does not burn it.

Communication between board and computer

Boards send data as bits. Serial communication sends bits one after another on a wire.

Serial printing (Serial.println) is also the easiest way to see what your program is doing while you fix mistakes.

Project workflow: setup and loop

Most programs for these boards have two parts.

  1. setup() runs once: set pin directions, start serial.
  2. loop() runs again and again: read inputs → decide → write outputs → print.

A good project workflow is: list inputs and outputs → draw the circuit → write a small program → test one module at a time → combine → test the whole project → write down what you did.

Try it: button and light rule

In the 3D, go to the last step. Set the limit to 600. Slide the sensor value from 300 to 800 and watch when the LED turns on. Now predict: if the limit is 200 and the sensor value is 300, will the LED be ON or OFF? Check it.

At home with real parts: connect a button to pin 2 and an LED (with 220 Ω resistor) to pin 13. Write if (digitalRead(2) == HIGH) digitalWrite(13, HIGH); else digitalWrite(13, LOW); inside loop().

Key formulas and definitions

Worked examples

1. A board reads a sensor on an analog pin powered with 5 V. The sensor gives 2.5 V. What number does analogRead show (10-bit)?

Value = (2.5 ÷ 5) × 1023 ≈ 512.

2. An LED needs 20 mA and drops 2 V. The supply is 5 V. What resistor is needed?

R = (5 − 2) ÷ 0.020 = 150 Ω. Use the next standard value, 180 Ω or 220 Ω.

3. A serial link runs at 9600 baud with 10 bits per character (8 data + start + stop). About how many characters per second?

9600 ÷ 10 = 960 characters per second.

4. Write the rule for a night lamp: the LED must turn on when the light sensor reads below 300.

if (analogRead(A0) < 300) digitalWrite(13, HIGH); else digitalWrite(13, LOW);

5. A project needs 2 buttons, 1 sensor, 3 LEDs and 1 buzzer. How many digital and analog pins does it need if the sensor is analog?

Digital: 2 + 3 + 1 = 6. Analog: 1. Total 7 pins, plus power and ground.

Common mistakes

Practice quiz

1. Which pin type gives only HIGH or LOW?
2. Which of these is an output module?
3. TX of board A should be joined to:
4. The part of a program that repeats forever is:
5. A 10-bit analog read gives numbers from:

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is open-source hardware?

Hardware whose design files (circuit and layout) are shared openly so anyone can study, build and improve it.

What is the difference between an input and an output module?

An input module sends information into the board (button, sensor). An output module acts on the world (LED, buzzer, motor).

What is serial communication?

Sending bits one after another on a wire. Boards use TX and RX pins and the same baud rate to talk to a computer or another board.

Where this is taught

China高三Sel.6 Open-source hardware projects

Learn first

Learn next

Related lessons

All Computer Science lessons