Digital ChallengeArduino × Processing
Side by side

Arduino vs. Processing

ConceptArduino IDEProcessing
Program entry pointsetup() + loop()setup() + draw()
Print to consoleSerial.println()println()
Start serialSerial.begin(9600)new Serial(this, port, 9600)
Read inputSerial.read() / readStringUntil()myPort.readStringUntil('\n')
Send outputSerial.println(x)myPort.write('1')
Delaydelay(ms)avoid in draw() — use millis()
Typesint, float, char, bool, Stringint, float, char, boolean, String
Scale a valuemap(v, a, b, c, d) (integer)map(v, a, b, c, d) (float)
Limit a valueconstrain(x, lo, hi)constrain(x, lo, hi)
Libraries#include <Servo.h>import processing.serial.*;
Arduino essentials
FunctionDoes
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
FunctionDoes
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

Arduino — sendArduino · C++
void loop() {
  float a = readSensorA();
  float b = readSensorB();
  Serial.print(a);
  Serial.print(",");
  Serial.println(b);   // newline ends the message
  delay(200);
}
Processing — receiveProcessing · Java
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

ModuleProblemLikely causeFix
F1Upload fails / “port not found”Wrong COM port or board selectedTools → Port: pick the port that appears when you plug the board in.
F1LED never lightsLED inserted backwardsTurn the LED around: long leg towards the resistor/pin.
F1LED lights but is very dimResistor too large (e.g. 10 kΩ)Check the colour bands: 220 Ω is red-red-brown.
F1Nothing changes after editingCode verified but not uploadedClick Upload, not only Verify.
F2Port not found / empty Serial.list()Arduino not connected or driver missingCheck USB; install the CH340 driver for clone boards.
F2Port busy / in useArduino Serial Monitor still openClose the Serial Monitor in the Arduino IDE first.
F2No data receivedWrong index in Serial.list()[0]Run printArray(Serial.list()) and choose the right index.
F2Garbage charactersBaud rate mismatchUse 9600 on both sides.
F2NullPointerExceptiondata is null (incomplete line)Always check if (data != null).
F2Wrong / garbage values on screenParsing non-numeric textValidate with data.matches("\\d+") or check length after split().
F2Sketch freezesHeavy work or delay() inside draw()Read serial in serialEvent(); never block draw().
P1No data receivedIncorrect COM portUse printArray(Serial.list()) to find the correct port.
P1“Failed to read” messagePoorly connected sensor or wrong pinCheck DATA → pin 2 and that DHTTYPE is DHT11 (not DHT22).
P1Unstable valuesPoor contact on the breadboardPress wires in firmly; avoid long loose jumpers.
P1Processing not receiving dataSerial speed mismatchBoth sides 9600 baud.
P2Value stays at 0LDR not connected or open circuitCheck the LDR leg goes to 5V and the junction to A0.
P2Value stays at 1023Resistor missing or GND not connectedCheck the 10 kΩ resistor goes from A0 to GND.
P2Unstable readingsPoor breadboard contact or flickering lightsPress components in firmly; average several readings.
P2Range is small (e.g. 400–700)Fixed resistor doesn’t match the LDRTry 4.7 kΩ or 22 kΩ, or calibrate with map().
P3Distance always 0No echo (timeout) or TRIG/ECHO swappedCheck pins; aim at a flat object 10–100 cm away.
P3Random big jumpsSoft or angled surfaces absorb/deflect soundUse flat, hard targets; average 3 readings.
P3Servo jitters or Arduino resetsServo draws too much current from USBPower the servo from a separate 5 V supply (common GND).
P3Radar points drawn upside downY-axis points down on screenUse y = cy − r·sin(θ).
P4Shows “no resistor” or a huge valueR_x not connected / open circuitCheck both legs of R_x are in the right rows.
P4Shows ≈ 0 ΩR_x shorted (both legs in the same row)Place each leg in a different row.
P4Reading is inaccurateR_known value in code is wrongMeasure R_known and update the constant.
P4Fluctuating valuesPoor breadboard contactAverage 10 readings; press parts in firmly.
P5Pump does not turn onRelay wiring incorrect or pin mismatchRelay IN must match RELAY_PIN (8). Listen for the relay “click”.
P5Pump is ON when it should be OFFRelay is active-HIGH, not active-LOWSwap the PUMP_ON / PUMP_OFF constants.
P5Sensor always reads maxSensor not in soil or damagedInsert up to the line; never submerge the electronics.
P5Pump runs continuouslyThreshold too low for your soilCalibrate: measure dry and wet values and choose a threshold between them.
P5Relay clicks on/off rapidlyValue hovers around the thresholdAdd hysteresis (exercise P5.4).
P5Processing shows no dataWrong COM port or baud rateprintArray(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
ModuleLessonsCore labsAssessment idea
F1 Arduino Basics2 × 45 minBlink, external LEDQuiz + F1.4 debug task
F2 Processing3 × 45 minLabs 1–4F2.5 live graph
P1 DHT112 × 45 minEx. 1–2P1.6 classroom climate study
P2 LDR2 × 45 minEx. 1–2P2.1 calculations + P2.3 build
P3 Sonar4 × 45 minEx. 1–4Radar project presentation
P4 Ohm meter2 × 45 minSteps 1–3P4.6 accuracy investigation
P5 Irrigation4 × 45 minEx. 1–3P5.6 water-saving study
Errata — changes to the original code and text
WhereIssue in the originalWhat changed
Processing · Lab 1int frameCount = 0; redeclares Processing’s built-in frameCount variable.Uses a separate counter t.
Project 1 · ProcessingSketch was missing import processing.serial.*; and contained HTML entities (&apos;).Import added; reading moved to serialEvent(); bars and alarm included.
Project 2 · TheoryCallout 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. 2Servo sweep used blocking for-loops, so STOP was ignored until a sweep finished.Non-blocking “one step per loop()” sweep.
Project 3 · Ex. 1 & 4pulseIn() without timeout can freeze for 1 s when there is no echo.Timeout of 30 000 µs added.
Project 4 · WiringWiring table (known resistor on the 5V side) contradicted the diagram and formula.Table follows the diagram: unknown 5V→A0, known A0→GND.
Project 4 · ArduinoTypo vconst; division by zero when no resistor is connected.Typo fixed; open-circuit guard sends −1.
Project 5 · Ex. 2Wiring used D8, code used pin 9.Consistently D8 with named constants.
Project 5 · Ex. 3Relay logic (HIGH = ON) contradicted Ex. 2 and the active-LOW explanation.PUMP_ON / PUMP_OFF constants used everywhere.
Project 5 · Equipment12 V supply listed, while the kit pump/battery box is low-voltage.Supply must match the pump rating; safety box added.