Reference
Everything on
one page.
Side by side
Arduino vs. Processing
| Concept | Arduino IDE | Processing |
|---|---|---|
| Program entry point | setup() + loop() | setup() + draw() |
| Print to console | Serial.println() | println() |
| Start serial | Serial.begin(9600) | new Serial(this, port, 9600) |
| Read input | Serial.read() / readStringUntil() | myPort.readStringUntil('\n') |
| Send output | Serial.println(x) | myPort.write('1') |
| Delay | delay(ms) | avoid in draw() — use millis() |
| Types | int, float, char, bool, String | int, float, char, boolean, String |
| Scale a value | map(v, a, b, c, d) (integer) | map(v, a, b, c, d) (float) |
| Limit a value | constrain(x, lo, hi) | constrain(x, lo, hi) |
| Libraries | #include <Servo.h> | import processing.serial.*; |
Arduino essentials
| Function | Does |
|---|---|
pinMode(p, OUTPUT) | Configure a pin |
digitalWrite(p, HIGH) | Set pin to 5 V / 0 V |
digitalRead(p) | Read HIGH / LOW |
analogRead(A0) | 0–1023 from 0–5 V |
analogWrite(p, 0–255) | PWM on ~ pins |
pulseIn(p, HIGH) | Pulse length in µs |
millis() | ms since start |
Processing essentials
| Function | Does |
|---|---|
size(w, h) | Window size |
background(c) | Clear the screen |
fill(r,g,b) / stroke() | Colours |
rect() ellipse() line() arc() | Shapes |
text(s, x, y) / textSize() | Text |
nf(x, l, r) | Format number |
split(s, ",") / trim(s) | Parse text |
Memorise this
The universal serial pattern
void loop() {
float a = readSensorA();
float b = readSensorB();
Serial.print(a);
Serial.print(",");
Serial.println(b); // newline ends the message
delay(200);
}void serialEvent(Serial p) {
String data = p.readStringUntil('\n');
if (data == null) return;
String[] v = split(trim(data), ",");
if (v.length != 2) return;
a = float(v[0]);
b = float(v[1]);
}45 terms
Glossary
- Active-LOWP5
- A module that switches ON when its input is LOW (common for relay boards).
- ADCP2
- Analog-to-Digital Converter: turns 0–5 V into a number 0–1023 (10-bit) on the Uno.
- Analog pinF1
- A pin (A0–A5) that can measure a voltage between 0 and 5 V as a number 0–1023.
- analogRead()P2
- Arduino function that reads an analog pin and returns 0–1023.
- Anode / CathodeF1
- The + (longer leg) and − (shorter leg, flat side) of an LED.
- Baud rateF2
- Speed of serial communication in bits per second (e.g. 9600). Both sides must match.
- BreadboardF1
- A reusable board for building circuits without soldering.
- CalibrationP2
- Measuring real minimum and maximum values so your scale fits reality.
- Capacitive sensorP5
- Measures how well the soil stores electric charge (permittivity) — water changes this a lot.
- Closed loopP5
- A system that measures the result of its own action and corrects itself.
- COM portF2
- The name your computer gives the Arduino’s serial connection (e.g. COM3 or /dev/ttyUSB0).
- CSVF2
- Comma-Separated Values, e.g.
23.5,61.0— several numbers in one line of text. - DHT11P1
- A low-cost digital sensor for temperature (0–50 °C, ±2 °C) and humidity (20–90 % RH, ±5 %).
- Digital pinF1
- A pin that is either HIGH (5 V) or LOW (0 V). The Uno has pins 0–13.
- EchoP3
- A reflected sound wave that returns to the sensor.
- FrameF2
- One execution of
draw(). Processing draws ~60 frames per second. - GND (ground)F1
- The 0 V reference point. Every circuit needs a path back to GND.
- HysteresisP5
- Using two thresholds (switch on at one, off at another) so the system does not flicker.
- IoTP1
- Internet of Things — everyday objects with sensors that share data.
- LDR / photoresistorP2
- A resistor whose resistance falls when light shines on it (≈ 1 MΩ in darkness, ≈ 1 kΩ in bright light).
- LibraryP1
- Ready-made code you include to talk to a component without writing everything yourself.
- MicrocontrollerF1
- A tiny computer on a single chip that reads inputs and controls outputs. On the Uno it is the ATmega328P.
- NaNP1
- “Not a Number” — the value returned when a reading failed. Test with
isnan(). - Ohm’s lawP4
- U = R · I — voltage equals resistance times current.
- ParsingF2
- Turning text (a String) into usable data (numbers).
- PDEF2
- Processing Development Environment — the editor, console and toolbar where you write sketches.
- PermittivityP5
- How strongly a material responds to an electric field. Water ≈ 80, dry soil ≈ 4.
- Polar coordinatesP3
- Describing a point by an angle and a distance from the centre, like a radar does.
- ProcessingF2
- A free, Java-based language and environment for visual and interactive programs, created at the MIT Media Lab in 2001.
- Pull-up resistorP1
- A resistor that keeps a signal line at HIGH when nothing is pulling it LOW.
- pulseIn()P3
- Arduino function that measures how long a pin stays HIGH, in microseconds.
- PWMP3
- Pulse-Width Modulation — switching a signal on and off quickly; the pulse width carries the information.
- Reference resistorP4
- The known resistor (R_known) used to compare against the unknown one.
- Relative humidity (RH)P1
- How much water vapour the air holds compared with the maximum it could hold at that temperature, in %.
- RelayP5
- An electrically operated switch: a small signal from Arduino switches a separate, more powerful circuit.
- ResistorF1
- A component that limits current. Measured in ohms (Ω).
- ResolutionP4
- The smallest change an instrument can detect. The Uno ADC: 5 V / 1023 ≈ 4.9 mV.
- Serial communicationF2
- Sending data one bit after another over a wire — here, the USB cable between Arduino and computer.
- Series circuitP4
- Components connected one after another; the same current flows through all of them.
- Servo motorP3
- A motor that turns to a precise angle (0–180°) controlled by a PWM signal.
- SketchF1
- The name for an Arduino (or Processing) program.
- ThresholdP5
- A limit value at which the system changes its decision.
- ToleranceP4
- How far a real resistor may differ from its printed value (gold band = ±5 %).
- UltrasoundP3
- Sound above human hearing (> 20 kHz). The HC-SR04 uses 40 kHz.
- Voltage dividerP2
- Two resistors in series; the voltage in the middle depends on their ratio.
All modules
Troubleshooting index
| Module | Problem | Likely cause | Fix |
|---|---|---|---|
| F1 | Upload fails / “port not found” | Wrong COM port or board selected | Tools → Port: pick the port that appears when you plug the board in. |
| F1 | LED never lights | LED inserted backwards | Turn the LED around: long leg towards the resistor/pin. |
| F1 | LED lights but is very dim | Resistor too large (e.g. 10 kΩ) | Check the colour bands: 220 Ω is red-red-brown. |
| F1 | Nothing changes after editing | Code verified but not uploaded | Click Upload, not only Verify. |
| F2 | Port not found / empty Serial.list() | Arduino not connected or driver missing | Check USB; install the CH340 driver for clone boards. |
| F2 | Port busy / in use | Arduino Serial Monitor still open | Close the Serial Monitor in the Arduino IDE first. |
| F2 | No data received | Wrong index in Serial.list()[0] | Run printArray(Serial.list()) and choose the right index. |
| F2 | Garbage characters | Baud rate mismatch | Use 9600 on both sides. |
| F2 | NullPointerException | data is null (incomplete line) | Always check if (data != null). |
| F2 | Wrong / garbage values on screen | Parsing non-numeric text | Validate with data.matches("\\d+") or check length after split(). |
| F2 | Sketch freezes | Heavy work or delay() inside draw() | Read serial in serialEvent(); never block draw(). |
| P1 | No data received | Incorrect COM port | Use printArray(Serial.list()) to find the correct port. |
| P1 | “Failed to read” message | Poorly connected sensor or wrong pin | Check DATA → pin 2 and that DHTTYPE is DHT11 (not DHT22). |
| P1 | Unstable values | Poor contact on the breadboard | Press wires in firmly; avoid long loose jumpers. |
| P1 | Processing not receiving data | Serial speed mismatch | Both sides 9600 baud. |
| P2 | Value stays at 0 | LDR not connected or open circuit | Check the LDR leg goes to 5V and the junction to A0. |
| P2 | Value stays at 1023 | Resistor missing or GND not connected | Check the 10 kΩ resistor goes from A0 to GND. |
| P2 | Unstable readings | Poor breadboard contact or flickering lights | Press components in firmly; average several readings. |
| P2 | Range is small (e.g. 400–700) | Fixed resistor doesn’t match the LDR | Try 4.7 kΩ or 22 kΩ, or calibrate with map(). |
| P3 | Distance always 0 | No echo (timeout) or TRIG/ECHO swapped | Check pins; aim at a flat object 10–100 cm away. |
| P3 | Random big jumps | Soft or angled surfaces absorb/deflect sound | Use flat, hard targets; average 3 readings. |
| P3 | Servo jitters or Arduino resets | Servo draws too much current from USB | Power the servo from a separate 5 V supply (common GND). |
| P3 | Radar points drawn upside down | Y-axis points down on screen | Use y = cy − r·sin(θ). |
| P4 | Shows “no resistor” or a huge value | R_x not connected / open circuit | Check both legs of R_x are in the right rows. |
| P4 | Shows ≈ 0 Ω | R_x shorted (both legs in the same row) | Place each leg in a different row. |
| P4 | Reading is inaccurate | R_known value in code is wrong | Measure R_known and update the constant. |
| P4 | Fluctuating values | Poor breadboard contact | Average 10 readings; press parts in firmly. |
| P5 | Pump does not turn on | Relay wiring incorrect or pin mismatch | Relay IN must match RELAY_PIN (8). Listen for the relay “click”. |
| P5 | Pump is ON when it should be OFF | Relay is active-HIGH, not active-LOW | Swap the PUMP_ON / PUMP_OFF constants. |
| P5 | Sensor always reads max | Sensor not in soil or damaged | Insert up to the line; never submerge the electronics. |
| P5 | Pump runs continuously | Threshold too low for your soil | Calibrate: measure dry and wet values and choose a threshold between them. |
| P5 | Relay clicks on/off rapidly | Value hovers around the threshold | Add hysteresis (exercise P5.4). |
| P5 | Processing shows no data | Wrong COM port or baud rate | printArray(Serial.list()) and use 9600 on both sides. |
Read before every lab
Lab safety rules
Power
Unplug USB before changing wiring. Never connect 5V directly to GND. Use only low-voltage batteries or adapters (≤ 12 V) — never mains electricity.Heat & smell
If a component gets hot, smells or smokes: disconnect immediately and tell your teacher. Don’t touch it until it has cooled down.Water
In Project 5, keep electronics and laptops away from the water container. Dry your hands before touching the circuit and wipe up spills immediately.Good practice
Keep your workspace tidy, return components to the kit, and double-check polarity (LEDs, sensors, batteries) before powering up.For teachers
Teacher notes
This edition keeps every lab from the original Digital Challenge handbook and adds learning objectives, vocabulary, 42 levelled exercises with solutions, 36 quiz questions, reflection prompts and safety guidance — designed for students aged 14–18.
The Basic exercises can be completed by every student; Intermediate exercises consolidate the lesson; Advanced and Challenge tasks suit differentiation, homework or project weeks.
Suggested scheme of work
| Module | Lessons | Core labs | Assessment idea |
|---|---|---|---|
| F1 Arduino Basics | 2 × 45 min | Blink, external LED | Quiz + F1.4 debug task |
| F2 Processing | 3 × 45 min | Labs 1–4 | F2.5 live graph |
| P1 DHT11 | 2 × 45 min | Ex. 1–2 | P1.6 classroom climate study |
| P2 LDR | 2 × 45 min | Ex. 1–2 | P2.1 calculations + P2.3 build |
| P3 Sonar | 4 × 45 min | Ex. 1–4 | Radar project presentation |
| P4 Ohm meter | 2 × 45 min | Steps 1–3 | P4.6 accuracy investigation |
| P5 Irrigation | 4 × 45 min | Ex. 1–3 | P5.6 water-saving study |
Errata — changes to the original code and text
| Where | Issue in the original | What changed |
|---|---|---|
| Processing · Lab 1 | int frameCount = 0; redeclares Processing’s built-in frameCount variable. | Uses a separate counter t. |
| Project 1 · Processing | Sketch was missing import processing.serial.*; and contained HTML entities ('). | Import added; reading moved to serialEvent(); bars and alarm included. |
| Project 2 · Theory | Callout said “R2 is the LDR”, but in the wiring the LDR is on the 5V side. | Formula rewritten as V_A0 = 5 V × R_fixed / (R_LDR + R_fixed). |
| Project 3 · Ex. 2 | Servo sweep used blocking for-loops, so STOP was ignored until a sweep finished. | Non-blocking “one step per loop()” sweep. |
| Project 3 · Ex. 1 & 4 | pulseIn() without timeout can freeze for 1 s when there is no echo. | Timeout of 30 000 µs added. |
| Project 4 · Wiring | Wiring table (known resistor on the 5V side) contradicted the diagram and formula. | Table follows the diagram: unknown 5V→A0, known A0→GND. |
| Project 4 · Arduino | Typo vconst; division by zero when no resistor is connected. | Typo fixed; open-circuit guard sends −1. |
| Project 5 · Ex. 2 | Wiring used D8, code used pin 9. | Consistently D8 with named constants. |
| Project 5 · Ex. 3 | Relay logic (HIGH = ON) contradicted Ex. 2 and the active-LOW explanation. | PUMP_ON / PUMP_OFF constants used everywhere. |
| Project 5 · Equipment | 12 V supply listed, while the kit pump/battery box is low-voltage. | Supply must match the pump rating; safety box added. |