Schaltwerk

Manual for the web app that lets you build and wire Arduino circuits in your browser and simulate them with your own sketch.

Contents

Description

Schaltwerk simulates an Uno board, a Raspberry Pi Pico or an ESP32 profile with connected parts. You need neither hardware nor an account. The page works without a server, and everything runs on your computer or, in the Android app, on your phone.

The circuit is calculated electrically and not just logically. A reversed LED therefore stays dark, and an LED without a series resistor triggers a warning.

Starting the app

Schaltwerk runs as a page in the browser, locally with npm start and as an Android app. The steps here are for the local version. You only need Node.js, and npm install is not required. With arduino-cli, real AVR code runs as well. Run this in the project folder:

npm start

The app then runs at http://localhost:8765. If PowerShell blocks npm because of its script policy, use npm.cmd start.

The app starts in your browser's language if that is German or Spanish, and in English otherwise. Use DE, EN and ES at the top to switch, in the Android app the menu ⋮. This manual uses the English names of the interface. The code of the examples is always in English, including its comments; only their titles follow the language.

Android app

The Android app contains the same simulation as the page. Only the controls around it belong to the app:

Differences from the local version: the app has no compiler. Uno and ATtiny sketches run in the interpreter, the Pico only with Python. Real HTTP from the ESP32 profile works, the app sends the requests itself. Projects are stored in the app on the device. Keyboard shortcuts need a hardware keyboard. The app needs Android 8 or newer.

Tutorial: LED with a button

In about five minutes you add a button to the blinking LED. After that, the LED only lights up while the button is held down.

1. Load the example and start it

Click Open example … at the top, choose Blink an LED and click Start. The LED blinks once per second. Then click Stop, because the circuit can only be changed while it is stopped.

Note: An example opens as its own project. Your previous work is kept.

2. Add a button

Open the Controls group in the parts bar and drag the Button to a free spot next to the board.

3. Wire the button

To add a wire, click one pin and then the other. When you hold the mouse pointer over a pin or tap it, the app shows its name.

4. Change the sketch

Replace the code in the editor with this sketch:

const int LED = 13;
const int BUTTON = 2;

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT_PULLUP);
  Serial.begin(9600);
  Serial.println("Ready");
}

void loop() {
  if (digitalRead(BUTTON) == LOW) {
    digitalWrite(LED, HIGH);
  } else {
    digitalWrite(LED, LOW);
  }
}

INPUT_PULLUP pulls the pin up to 5 V internally. Pressing the button connects it to GND. That is why LOW means "pressed" here.

5. Try it out

Click Start. Ready appears in the serial monitor. Hold the button down: the LED lights up, and it goes out when you let go.

6. Introduce a mistake

Stop the simulation and change INPUT_PULLUP to INPUT. As soon as the sketch reads the pin, the monitor reports that D2 is floating. While the button is open, the pin reads random values. The LED then keeps switching and only glows faintly.

Change the pin mode back afterwards. You now know all the basic steps.

Using the app

The window has three areas: the mat with the parts bar, the code editor and the serial monitor. On a phone, switch between them with the Circuit, Code and Monitor tabs. On wide screens they are side by side; drag the dividers between them to make the mat wider or the monitor taller. Arrow keys move a divider, a double-click resets it. The layout is kept on the device.

On your first visit a short introduction shows in eight steps where parts, wires, code, Start, the monitor and the examples are. You can skip it and open it again at any time with ? at the top right of the mat.

Building a circuit

To change the language of the app, use DE, EN and ES at the top, in the Android app the menu ⋮. The examples and your own code stay as they are.

Projects

Each circuit is its own project with parts, wires and code. Changes are saved automatically, and the header shows Saved. Press Ctrl + S to save right away. The Android app always saves on its own and only reports Not saved under the project name. Click the project name at the top to open the projects window:

Important: Projects are stored only in this browser, or in the Android app only in the app. Other browsers and devices cannot see them, and they are gone if you clear your browser data. Back up important projects by exporting them. If Not saved appears at the top, the browser does not allow saving, and only an export keeps your work.

Above the list of examples is a search field. It finds names, parts, boards and libraries, German words too: "keypad", "running light", "Lauflicht" or "esp32 python oled". Several words narrow it down. Choose with the arrow keys, Enter opens the example, Esc clears the search and closes the list.

Opening an example creates a new project. Only an unchanged example or an empty circuit is replaced, because nothing is lost there.

Simulation

Start compiles the sketch and runs it. The clock in the header shows the simulated time, in the Android app it is under the project name. While the simulation runs, you operate the parts like this:

The circuit is locked during this time. Code changes take effect at the next start. The simulation pauses in a background tab.

Keyboard shortcuts

KeyEffect
Delete or BackspaceDelete the selection
RRotate the selected part by 90°
EscCancel a wire you have started
Ctrl + ZUndo the last change to the circuit
Ctrl + SSave right away, also in the editor
F8Pause and continue
F9Breakpoint at the cursor line
F10Step
F11Step into
Shift + F11Step out

The first four shortcuts apply outside input fields. In the editor, Ctrl + Z undoes the last text change. In the Android app, the shortcuts work with a hardware keyboard.

Parts

PartConnectionsNotes
Uno boardD0–D13, A0–A5, 5V, 3V3, VIN, 3 × GNDPWM on D3, D5, D6, D9, D10, D11. The "L" LED is connected to D13.
LEDAnode (+), cathode (−)Six colors. Needs a series resistor.
Resistor2100 Ω to 100 kΩ.
CapacitorPlus, minus100 nF to 470 µF. It really charges and discharges, see Transistors and capacitors. Polarised from 1 µF.
DiodeAnode (+), cathode (−)Drops 0.7 V, blocks in the other direction. For example as a flyback diode.
NPN transistorC, B, ELike BC547, up to 100 mA. Needs a base resistor.
PNP transistorC, B, ELike BC557, switches on the plus side.
N-MOSFETG, D, SLike IRLZ44N, for larger loads. Fully on from about 4.5 V.
RelayA1, A2, COM, NO, NCCoil for 5 V (70 Ω) or 12 V (400 Ω), selectable in the panel. Pulls in from 70 % of the rated voltage and drops out below 30 %. Without a flyback diode the app warns when it switches off.
Stepper 28BYJ-48 (ULN2003)IN1–IN4, VCC, GNDStepper motor on its driver board, 4096 half steps per turn. Needs 5 V. See Stepper motor.
Stepper with A4988EN, MS1–MS3, RST, SLP, STEP, DIR, VMOT, GND, VDDBipolar stepper with driver, steps via STEP and DIR, microsteps down to 1/16. See Stepper with A4988.
L298N motor driverOUT1–OUT4, 12V, GND, 5V, ENA, IN1–IN4, ENBTwo H-bridges for two DC motors, direction via IN, speed via PWM. See L298N motor driver.
MotorPlus, minusDC motor with 25 Ω. Speed follows the voltage, direction the polarity.
Power supplyPlus, minus9 V battery, 4 or 3 AA cells, lithium cell or adjustable bench supply up to 30 V, see External power supply.
Voltage regulator 7805IN, GND, OUTTurns 7 to 35 V at the input into 5 V, see External power supply.
Power railTwo rows of 10 holes eachLike the strips on the edge of a breadboard: all holes in a row are connected. Spreads a supply to several parts, see External power supply.
HC-SR04VCC, TRIG, ECHO, GNDUltrasonic sensor, 2 to 400 cm, set by dragging while running. Needs 5 V. On the ESP32, ECHO must go through a voltage divider.
OLED SSD1306GND, VCC, SCL, SDA128 × 64 pixels over I²C, address 0x3C or 0x3D. See Displays and sensors.
ILI9341 TFTVCC, GND, CS, RST, DC, MOSI, SCK, LED, MISOColour display, 240 × 320 pixels over hardware SPI. See Colour TFT.
microSDCD, DO, GND, SCK, VCC, DI, CSCard with 8 MB and FAT16 on SPI. See microSD card.
RFID RC522SDA, SCK, MOSI, MISO, IRQ, GND, RST, 3.3VRFID reader for 13.56 MHz on SPI with three MIFARE cards to click. See RFID reader.
BME280VCC, GND, SCL, SDATemperature, humidity and pressure over I²C, address 0x76 or 0x77.
BMP180VCC, GND, SCL, SDAAir pressure and temperature over I²C, address 0x77. See BMP180.
DHT22VCC, DATA, GNDTemperature and humidity over one wire.
WS2812B LEDGND, VCC, DIN, DOUTA single individually coloured LED on a small board, chainable through DOUT with more LEDs or rings. See LED ring.
WS2812 LED ringGND, VCC, DIN, DOUT8 to 60 individually coloured LEDs on one data wire, chainable through DOUT. See LED ring.
MCP23017 (I²C)GPA0–GPA7, GPB0–GPB7, SDA, SCL, A0–A2, RESET, INTA, INTB, VDD, VSS16 inputs and outputs over I²C. See MCP23017.
PCA9685 (16× PWM)GND, OE, SCL, SDA, VCC, PWM0–PWM1516 PWM outputs for servos and LEDs. See PCA9685.
ADS1115 (16-bit ADC)VDD, GND, SCL, SDA, ADDR, ALRT, A0–A3Four analog inputs over I²C. See ADS1115.
DS18B20 (OneWire)GND, DQ, VCCTemperature over one wire, needs 4.7 kΩ. See DS18B20.
MPU6050 (accel, gyro)VCC, GND, SCL, SDA, XDA, XCL, AD0, INTOrientation, rotation rate and temperature over I²C. See MPU6050.
DIP switch (8)1a to 8a, 1b to 8bEight switches. See DIP switch.
PIR motion sensorVCC, OUT, GNDA click is a motion. See PIR.
IR receiverDAT, GND, VCCOutputs the remote's NEC signal, LOW with infrared. See IR receiver.
Gas sensor MQ-2AOUT, DOUT, GND, VCCAnalog value and a switching output with a threshold. See MQ-2.
HX711 with load cellVCC, DT, SCK, GND24-bit converter with a load cell up to 5 kg. See HX711.
NTC temperature sensorVCC, OUT, GNDVoltage divider with an NTC. See NTC.
Rotary encoder KY-040CLK, DT, SW, VCC, GNDTwo offset signals per step and a button. See Rotary encoder.
IR remotenone20 keys, click them while running, holding repeats. See IR receiver.
JoystickVCC, VERT, HORZ, SEL, GNDTwo pots and a button. See Joystick.
Membrane keypadR1 to R4, C1 to C416 or 12 keys as a switch matrix. See Membrane keypad.
Button2Conducts only while it is pressed.
Switch2Keeps its position.
Slide switch1, 2, 3Changeover: the middle pin 2 connects to 1 on the left and to 3 on the right. A click flips it.
PotEnd A, wiper, end B1 kΩ, 10 kΩ or 100 kΩ.
Slide potentiometerGND, SIG, VCCLike a pot, the knob is dragged sideways. SIG is at GND on the left, at VCC on the right. 1 kΩ, 10 kΩ or 100 kΩ.
Photoresistor2About 1 kΩ when bright to 100 kΩ when dark.
RGB LEDRed, green, blue, common pinCommon cathode or anode.
BuzzerPlus, minusPlays the frequency from tone() or TimerFreeTone(), otherwise 1 kHz when voltage is applied.
SpeakerPlus, minus8 Ω. Sounds like the buzzer with tone() directly on a pin (and draws too much current), on the DFPlayer it plays its tracks.
DFPlayer MiniVCC, RX, TX, SPK_1, SPK_2, GND, BUSY, IO_1, IO_2 and moreMP3 player with its own card, UART at 9600 baud. See DFPlayer Mini.
GPS module NEO-6MVCC, RX, TX, GNDSends NMEA sentences at 9600 baud every second, position and satellites in the inspector. See GPS module NEO-6M.
ServoGND, 5 V, signalOnly turns with power and a signal, 0° to 180°.
7-segmentSegments a–g, dp, plus COM or with several digits DIG1–DIG4, optionally CLN1 to 4 digits, common cathode or anode, six colours, optionally a colon. Set this in the panel. You drive several digits by switching quickly between them.
LED bar graph (10)A1–A10, C1–C10Ten LEDs in one housing, segment 1 on the left. Each segment has its own anode and cathode and needs its own series resistor. Colour in the inspector.
LCD 16×2VSS, VDD, V0, RS, RW, E, D0–D7, A, KText display, see below.
LCD 16×2 I²CGND, VCC, SDA, SCLSee I²C. Like the LCD 16×2, it can also be set to 16×4 in the panel.
TM1637 (4 digits)CLK, DIO, VCC, GNDFour digits with a colon over two lines, see TM1637.
MAX7219 MatrixVCC, GND, DIN, CS, CLK, DOUT8 × 8 LEDs, see LED matrix.
LED matrix 4×8×8 (MAX7219)VCC, GND, DIN, CS, CLK, DOUTFour matrices, 32 × 8 LEDs, see LED matrix.
PCF8574 (I²C)A0–A2, P0–P7, INT, SDA, SCL, VCC, GNDPort expander, see I²C.
NE555 (Timer)VCC, GND, TRIG, THR, DIS, OUT, RESET, CTRLTimer, see NE555 and LM358.
LM358 (OpAmp)VCC, GND, two each of IN+, IN-, OUTTwo operational amplifiers, see NE555 and LM358.
DS1307 (I²C)SDA, SCL, VCC, GNDReal-time clock, see I²C.
DS3231 (I²C)SDA, SCL, VCC, GND, SQW, 32KAccurate real-time clock with alarms and thermometer, see DS3231.
CD4017CLK, INH, RST, Q0–Q9, CO, VDD, VSSDecade counter, see below.
74HC595DS, SHCP, STCP, OE, MR, Q0–Q7, Q7S, VCC, GNDShift register, see below.
74HC165PL, CP, CE, DS, D0–D7, Q7, Q7N, VCC, GNDReads eight inputs, see below.
74HC00 (NAND)Four gates A, B, YLogic gate, see below.
74HC04 (NOT)Six gates A, YLogic gate.
74HC08 (AND)Four gates A, B, YLogic gate.
74HC32 (OR)Four gates A, B, YLogic gate.
74HC14 (NOT, Schmitt)Six gates A, YInverter with hysteresis, see logic gates.
74HC86 (XOR)Four gates A, B, YLogic gate.
74HC02 (NOR)Four gates A, B, YLogic gate, note the pinout: the output comes first.
74HC74 (D-FF)Two flip-flops D, CLK, PRE, CLR, Q, QNStores one bit each, see logic gates.
74HC4051 (MUX)Z, Y0–Y7, S0–S2, E, VEE, VCC, GNDAnalog switch, one of eight channels. See 74HC4051.
Logic analyzer (8 channels)D0–D7, GNDRecords every level change, shown in the Logic tab, exported as VCD. See Logic analyzer.
Multimeter+, COMRanges V, A and Ω on the dial. V measures across with 10 MΩ, A in series through 0.1 Ω, Ω with a 1 V test voltage and only with the power off. Shows the average, so PWM reads as its mean voltage. See Multimeter.

LCD 16×2

The display behaves like an HD44780 module and shows 2 lines of 16 characters each. The Text on the LCD example shows the finished circuit in the usual 4-bit mode.

PinConnect to
VSS, RW, KGND
VDD5 V
AThrough 220 Ω to 5 V, for the backlight
V0Wiper of a pot between 5 V and GND, for the contrast
RS, E, D4–D7Six pins of the board. D0–D3 stay free in 4-bit mode.

The sketch drives the display with LiquidCrystal.h. If you only see black bars in line 1, it has not received a command yet: This behaves like the real module and points to swapped data or control lines. If no text appears, check the contrast on the pot.

With real AVR code, the library must be installed, in the Arduino IDE under Tools > Manage Libraries. It is built into the interpreter, with begin, print, write, setCursor, clear, home, createChar, display, cursor, blink, the scroll and direction commands and the constructor with six pins. The display shows the usual ASCII characters, and non-ASCII letters appear wrong, as on the real module. The busy status does not exist, so commands sent too fast go unnoticed.

I²C: PCF8574, DS1307 and LCD with adapter

I²C modules share two wires: SDA goes to A4, SCL to A5, plus VCC to 5 V and GND to GND. The sketch addresses them with Wire.h. If nobody answers at an address, the monitor gives the reason.

ModuleAddressNotes
PCF85740x20, plus A0–A2Eight pins. HIGH is only a weak pull-up: An LED therefore connects to 5 V and lights at LOW. An input is read while the pin is HIGH. Connect A0–A2 to GND or 5 V.
DS13070x68Real-time clock, registers 0 to 6 hold the time as BCD. It starts with the computer's time and runs on simulated time. Only the 24-hour format exists. More under DS1307 real-time clock.
DS32310x68Real-time clock with two alarms and temperature, see DS3231.
LCD 16×2 I²C0x27 or 0x3F, set on the partThe LCD with adapter, driven with LiquidCrystal_I2C.h. The sketch switches the backlight with backlight().

On a 16×4, LiquidCrystal_I2C always uses the addresses of a 20×4. Rows 3 and 4 therefore land four columns too far right, on the real display too. Write lcd.setCursor(col - 4, row) there. LiquidCrystal.h calculates correctly. The example LCD with four rows shows this.

The Port expander PCF8574 and Clock with DS1307 and I²C LCD examples show the circuits. Wire.h is part of the Arduino core. For real AVR code, LiquidCrystal_I2C.h must be installed, in the Arduino IDE under Tools > Manage Libraries as "LiquidCrystal I2C".

The simulation works at protocol level: It checks that the wires are connected correctly, but pull-up resistors and signals on the wires are not simulated. On a real build, SDA and SCL each need a pull-up of about 4.7 kΩ to the supply, and ready-made modules usually have one already. The examples with the bare PCF8574 therefore show them, even though the simulation also runs without them. I²C rebuilt with digitalWrite therefore does not reach the modules.

DS1307 real-time clock

Set the start time in the module's panel, like initTime in Wokwi: the computer's clock (default), 2000-01-01 00:00:00 or a fixed time in local time, for example to test an alarm clock. When the sketch sets the clock, it runs on from there. As in the original, the chip only counts the weekday on; the program decides which value means which day when it sets the clock.

LanguageWhat you use
C in the interpreterRTClib.h is rebuilt and sends real I²C bytes: RTC_DS1307 with begin(), isrunning(), now(), adjust(), writeSqwPinMode(), readSqwPinMode(), readnvram() and writenvram(). DateTime with year() to second(), dayOfTheWeek(), unixtime(), timestamp(), toString(buffer) and isValid(), built from year to second, from F(__DATE__), F(__TIME__), from a text like "2026-01-31T12:00:00" or from seconds since 1970. TimeSpan for arithmetic: now + TimeSpan(1, 0, 0, 0), a - b and comparisons.
Real AVR or RP2040 codeThe real RTClib, installed in the Arduino IDE as "RTClib", or Wire.h directly.
Pythonds1307 is already there, with the interface of micropython-tinyrtc: rtc = ds1307.DS1307(i2c), rtc.datetime() returns (year, month, day, weekday, hour, minute, second, 0) and sets it with the same tuple, plus halt() and square_wave(). On a real board, ds1307.py has to be added as a file.

SQW outputs a square wave of 1 Hz, 4, 8 or 32 kHz according to register 7, or sits at a fixed HIGH or LOW (RTClib: DS1307_SquareWave1HZ, DS1307_ON and so on). The output only pulls to GND, as on the chip: an LED goes to the supply through a resistor, a board pin needs INPUT_PULLUP. At 1 Hz it really switches, so an interrupt sees every change of second; the fast rates count as an average like PWM. The RTC: RTClib clock with 1 Hz interrupt example shows both.

DS3231 real-time clock

The DS3231 has the same time registers as the DS1307 and the same address 0x68, plus two alarms, a thermometer and a 32.768 kHz output. Set the start time and temperature in the panel. With the start time 2000-01-01 it reports lostPower() like a chip after a dead battery, until the clock is set.

LanguageWhat you use
C in the interpreterRTC_DS3231 from RTClib.h with begin(), lostPower(), now(), adjust(), getTemperature(), setAlarm1(), setAlarm2(), getAlarm1(), getAlarm2(), disableAlarm(), clearAlarm(), alarmFired(), writeSqwPinMode(), readSqwPinMode(), enable32K(), disable32K() and isEnabled32K().
Real AVR or RP2040 codeThe real RTClib.
Pythonds3231 is already there, a version of our own: rtc = ds3231.DS3231(i2c), datetime() as with ds1307, plus lost_power(), temperature(), square_wave(freq), alarm1(hour, minute, second, day), alarm2(hour, minute, day), alarm_fired(n), clear_alarm(n) and disable_alarm(n). Missing alarm fields count as "don't care". This module does not exist on a real board.

On a Pico or ESP32, VCC goes to 3V3, otherwise SQW sits at 5 V through the pull-up. The RTC: DS3231 alarm every 10 seconds example sets the next alarm every 10 seconds.

LED matrix with MAX7219

The module drives 8 × 8 LEDs over three wires. Connect VCC to 5 V, GND to GND, and DIN, CLK and CS to three pins of the board. For several modules, DOUT leads to DIN of the next, and they share CLK and CS. The LED matrix with MAX7219 example shows the circuit.

The LED matrix 4×8×8 carries four such modules on one board like the common FC-16 module, 32 × 8 LEDs in all. The input is on the right, where module 0 sits; module 3 is on the left, and DOUT on the left leads to a further module. In LedControl give 4 as the number of modules (or more if others follow). Chains work with any pins, which the library switches itself, and with hardware SPI (SPI.h, machine.SPI) on MOSI and SCK: each module passes the byte it shifts out on to the next. The Scrolling text on a 4-in-1 LED matrix example runs a text from right to left.

For scrolling text most people use MD_Parola.h with MD_MAX72xx.h by MajicDesigns. MD_Parola P(MD_MAX72XX::FC16_HW, 10, 4); talks over hardware SPI (Uno: DIN to D11, CLK to D13, CS any pin), with five values (type, DIN, CLK, CS, count) over own pins. displayText(text, align, speed, pause, effectIn, effectOut) sets up the animation, displayAnimate() moves it on in loop() and returns true when it is finished; there are also print(), displayScroll(), displayReset(), displayClear(), setIntensity(), setInvert(), setSpeed() and setPause(). All effects are modelled: PA_SPRITE with your own images via setSpriteData(images, width, count, images, width, count), plus scrolling in all directions and diagonally, PA_WIPE, PA_OPENING, PA_CLOSING, PA_SCAN_…, PA_GROW_…, PA_SLICE, PA_BLINDS, PA_MESH, PA_FADE, PA_DISSOLVE and PA_RANDOM; all run frame by frame as on the real chip. With begin(2) to begin(4), setZone(zone, firstModule, lastModule) and displayZoneText(zone, …) up to four zones run side by side, each with its own text, effect and speed; the settings then take the zone number first, such as setIntensity(1, 3) or getZoneStatus(1). As in the library, Parola only keeps a pointer to the text: change a char array and call displayReset(), and the new content appears. The font is our own with the same character widths as in Parola (lower case mostly four columns, descenders in the bottom row), so texts sit and move as on the real module; only some characters look slightly different. MD_MAX72XX alone offers setPoint(), setColumn(), setRow(), setChar(), transform(), clear(), update() and control() with MD_MAX72XX::INTENSITY, ::UPDATE or ::SHUTDOWN. As in the library, column 0 is at the far right by the input. Every hardware type (FC16_HW, GENERIC_HW …) appears the right way round here; a real 4-in-1 module usually needs FC16_HW.

MicroPython has the module max7219 with the interface of the common driver: max7219.Matrix8x8(spi, Pin(17), 4) is a FrameBuffer with 32 × 8 dots, so text(), pixel(), fill(), scroll(), rect() and the other drawing commands work. show() writes the picture, brightness(0 to 15) sets the brightness. See MD_Parola: text effects on the 4-in-1 matrix and Pico: scrolling text with max7219.

The sketch uses LedControl.h. The module starts shut down, so shutdown(0, false) belongs in setup(). Row 0 is at the top, bit 7 on the left. With real AVR code, the library must be installed, in the Arduino IDE under Tools > Manage Libraries as "LedControl". It is built into the interpreter, with shutdown, setIntensity, setScanLimit, clearDisplay, setLed, setRow, setColumn and getDeviceCount.

The BCD decoder for 7-segment displays is not simulated, and with hardware SPI (SPI.h, machine.SPI) only the first module of a chain gets the bytes: DIN to MOSI, CLK to SCK. For chains, LedControl and shiftOut() switch the pins and reach every module.

TM1637

A module with four 7-segment digits and a colon, as used for clocks. It needs only two lines: CLK and DIO to any two pins, VCC to 5 V or 3.3 V, GND to GND. The 10 kΩ pull-ups sit on the module. The protocol looks like I²C but isn't: it has no address, the bits come lowest first, and Wire can't talk to it. See Stopwatch on a TM1637 display.

In C, use TM1637Display.h (library "TM1637" by Avishay Orpaz): TM1637Display display(CLK, DIO);, plus setBrightness(0 to 7, on), showNumberDec(number, leading_zeros, length, position), showNumberDecEx and showNumberHexEx with dots, setSegments(array, length, position), clear() and encodeDigit(), as well as the constants SEG_A to SEG_G and SEG_DP. As with the real library, the display stays dark until setBrightness() has run once. Bit 7 of the second digit is the colon, so showNumberDecEx(1234, 0b01000000) lights it. One update takes just over 20 ms, as on the Uno. Real AVR code needs the library installed; the interpreter has it built in.

In Python, tm1637 is already there, with the interface of micropython-tm1637: tm = tm1637.TM1637(clk=Pin(16), dio=Pin(17)), plus brightness(), write(), number(), numbers(a, b, colon), hex(), temperature(), show(text, colon) and scroll(). On a real board, tm1637.py has to be copied over as a file.

Limits: reading keys (command 0x42) always returns "no key", because the module has none. Digits 5 and 6, which the chip also knows, are not shown. This module has no decimal points, only the colon.

IR receiver and remote

The receiver behaves like a VS1838B: DAT to a pin, VCC to 5 V or 3.3 V, GND to GND. When idle, DAT is HIGH through the built-in pull-up; while infrared arrives it is LOW, as the red LED shows. The remote has no wires. While running, a click on a key sends an NEC frame with address 0 to every powered receiver; held down, a repeat code follows every 108 ms as with a real one. The codes are Wokwi's, for example POWER 0xA2, + 0x02, − 0x98, the digits 1 to 9 from 0x30 to 0x52. See IR remote dims an LED.

In C, use IRremote.hpp (library "IRremote"): IrReceiver.begin(pin, ENABLE_LED_FEEDBACK), then if (IrReceiver.decode()) { … IrReceiver.resume(); }, and in between IrReceiver.decodedIRData.command, .address, .protocol (NEC), .flags (IRDATA_FLAGS_IS_REPEAT for a repeat) and .decodedRawData. The old style IRrecv receiver(pin); receiver.enableIRIn(); works too. As with the library, decode() returns the same key until resume(), and whatever arrives in the meantime is lost. In the interpreter, IRremote reads the frames of the receiver on the pin from begin(); if none is connected there, a hint says so. Real AVR code and your own decoding with micros() see the pulses themselves. printIRResultShort() and the sending functions are not available in the interpreter.

In Python, ir_rx is already there, with the interface of micropython_ir: from ir_rx.nec import NEC_8, then NEC_8(Pin(15, Pin.IN), callback). callback(data, addr, ctrl) gets the command and the address; a repeat code arrives as data −1. On a real board the package has to be copied over as files.

Limits: NEC only, no line of sight, no ambient light. A key pressed during a frame waits until it has finished.

DFPlayer Mini (MP3 player)

The module plays MP3 and WAV files from its own microSD card. VCC goes to 3.3 to 5 V and GND to GND; TX goes to RX of the board and RX to its TX, on the Uno through 1 kΩ, because the module works with 3.3 V inside. A speaker (8 Ω, in the group "Displays and sound") belongs on SPK_1 and SPK_2; without one it stays silent. BUSY is LOW while a track plays, and the blue LED shows the same. IO_1 and IO_2 are buttons to GND: short for the previous and next track, long for quieter and louder.

The tracks are on the card of the module: select it, click Files on the card and upload MP3 files in the SD card tab; the field next to the button puts them into a folder such as MP3 or 01. As on the real module, play(n) counts in the order the files are on the card, not by name; playMp3Folder(1) plays /MP3/0001.mp3, playFolder(1, 2) plays /01/002.mp3, and advertise(1) interrupts with /ADVERT/0001.mp3. The card in the project holds at most 256 KB, enough for short sounds at 32 kbit/s.

In C, use DFRobotDFPlayerMini.h (library "DFRobotDFPlayerMini") with SoftwareSerial on two free pins (Uno) or Serial2.begin(9600, SERIAL_8N1, 16, 17) (ESP32). begin(serial) resets the module and waits for the card as the library does; available(), readType() and read() report finished tracks (DFPlayerPlayFinished) and errors. In Python, dfplayer is already there, a small module of its own: DFPlayer(UART(1, 9600, tx=Pin(4), rx=Pin(5))) with play, play_mp3, play_folder, volume, pause, resume, stop and event(); on a real board it has to be copied over as a file.

Limits: 9600 baud only, other baud rates arrive as garbage. No USB stick and no equalizer sound, the line outputs DAC_R and DAC_L are silent, and ADKEY has no function. The sound plays in real time and stops with the simulation.

RFID reader RC522

The module reads and writes MIFARE Classic 1K cards at 13.56 MHz and talks SPI: SDA is the chip select (CS) and goes to any pin, SCK, MOSI and MISO go to the SPI pins of the board (Uno D13, D11, D12; ESP32 18, 23, 19; Pico for example GP2, GP3, GP4), and RST to a free pin. It needs 3.3 V; at 5 V a warning appears. Next to the reader are two cards and a key fob with fixed UIDs (7A 3F 9C 21, D5 18 66 B4 and 93 E2 4D 0F): while running, a click lays a card on the reader and a second click takes it away. The antenna field lights up while a card is on it.

Each card has 1 KB in 16 sectors of four blocks, and keys A and B are FF FF FF FF FF FF as on new cards. What a sketch writes stays on the card and is saved in the project when the simulation stops. The reader itself works like the MFRC522 chip: registers, FIFO, REQA, anticollision and SELECT, MIFARE READ and WRITE after authenticating with the key of the sector; Crypto1 is not calculated, the chip simply compares the key.

In C, use MFRC522.h (library "MFRC522" by miguelbalboa) with SPI.begin(), mfrc522.PCD_Init(), PICC_IsNewCardPresent(), PICC_ReadCardSerial(), uid.uidByte, PCD_Authenticate(), MIFARE_Read(), MIFARE_Write(), PICC_HaltA() and PICC_DumpToSerial(), including MFRC522::MIFARE_Key and &(mfrc522.uid) as in the library's examples. In Python, mfrc522 is already there with the interface of the common Pico driver: MFRC522(spi_id, sck, miso, mosi, cs, rst), request(reader.REQIDL), SelectTagSN(), auth(), read() and write(); on a real board it has to be copied over as a file.

Limits: only cards with a 4-byte UID, no Ultralight or NTAG, no value blocks (increment, decrement), no collision of several cards, and the access bits are not enforced: whoever has the right key may read and write every block except block 0. IRQ has no function.

GPS module NEO-6M

The GY-GPS6MV2 module with the u-blox NEO-6M sends the NMEA sentences RMC, VTG, GGA and GSA to TX every second at 9600 baud, as it does out of the box. TX goes to an RX pin of the board: on the Uno to two free pins with SoftwareSerial, on the ESP32 to Serial2 (GPIO16), on the Pico to a UART (for example GP5 for UART1). RX is only needed for settings and may stay unconnected. VCC takes 3.3 to 5 V, and the LED blinks once per second as soon as the module has a fix.

The inspector has latitude and longitude in degrees (south and west negative), altitude, number of satellites, speed and course. With 0 satellites the module has no fix and leaves the fields empty. With a speed the position moves along the course while running; new values apply from the next second. The time is UTC, either the current time or a fixed one.

In C use TinyGPS++.h (library "TinyGPSPlus" by Mikal Hart): every character goes to gps.encode(), the values are in gps.location, date, time, speed, course, altitude, satellites and hdop, each with isValid(), isUpdated() and age(). There are also TinyGPSPlus::distanceBetween(), courseTo() and cardinal(). As in the library, only RMC and GGA are evaluated. In MicroPython there is the module micropyGPS with MicropyGPS(), update(char), latitude, longitude, timestamp, date, speed, satellites_in_use and more. See GPS position and distance travelled, ESP32: GPS on Serial2 and Pico: GPS with micropyGPS.

Transistors and capacitors

A pin supplies only a few milliamps. A transistor switches larger loads. The NPN transistor sits between load and GND: base through about 1 kΩ to the pin, emitter to GND, collector to the load. The PNP transistor sits between plus and load and conducts when its base is LOW. The N-MOSFET needs no gate current. A pull-down of about 100 kΩ keeps it safely off until the pin takes over.

The app warns about a missing base resistor, more than 100 mA at the collector, a floating gate, and a MOSFET with too little gate voltage at high current, such as the 3.3 V of an ESP32.

The capacitor charges and discharges in small time steps. The time constant is resistance times capacitance, so 1 s for 10 kΩ and 100 µF. This makes RC delays, debouncing and smoothed PWM work. If that changes an input without a pin switching, the sketch still finds out.

External power supply

For loads that need more voltage or current than the board provides, there is the power supply. Pick the type in the panel: 9 V battery, 4 × AA (6 V), 3 × AA (4.5 V), lithium cell (3.7 V) or a bench supply with adjustable voltage up to 30 V. Each type has an internal resistance, so a battery sags a little under load.

The Motor on a 9 V battery with MOSFET example shows a motor on its own battery, controlled with PWM.

NE555 and LM358

Both work without a program, the board only supplies the voltage. The NE555 compares THR with ⅔ and TRIG with ⅓ of the supply and switches OUT accordingly. While OUT is LOW, DIS pulls to GND and so discharges the capacitor. As a blinker this gives a period of 0.693 × (Ra + 2 × Rb) × C. RESET belongs on 5 V, CTRL may stay open. The examples LED blinks with a 555, no code, Tone from a 555 and One-shot timer with a 555 show the basic circuits.

The LM358 contains two operational amplifiers. With feedback to the minus input it amplifies, without feedback it compares, with feedback to the plus input it becomes a Schmitt trigger. See Light switch with LM358 and Amplifier with LM358.

Displays and sensors

All three parts behave like the real ones on their wires: The OLED understands the SSD1306 commands, the BME280 has real registers with calibration, and the DHT22 sends its single-wire protocol with real timing. Set the temperature by dragging the sensor while running, and humidity and pressure in the panel while stopped.

LanguageWhat you use
C in the interpreterAdafruit_SSD1306.h, Adafruit_BME280.h and DHT.h are rebuilt with the usual methods. If one is missing, the app says so. Your own classes and other libraries do not work.
Real AVR or RP2040 codeThe real libraries, installed in the Arduino IDE. An Uno has little memory for an OLED, so the program can fail on that.
Pythonssd1306, bme280 and dht are already there. On a real board, ssd1306.py and bme280.py have to be added as files.

Limits: The OLED cannot scroll using the chip's commands. bme280 in Python is an own driver with the interface of the common version, other drivers can differ. The BME280 always measures at once, modes and averaging are not modelled. On a breadboard, a bare DHT22 needs a pull-up of about 10 kΩ on DATA, the part here is the module.

BMP180

Air pressure and temperature over I²C, as the GY-68 module with a voltage regulator: VCC to 5 V or 3.3 V, GND to GND, SDA and SCL to the I²C pins (Uno A4 and A5). The address is fixed at 0x77. It does not measure humidity; the BME280 does. Set the temperature by dragging the sensor while running and the pressure in the inspector. See Air pressure and altitude with a BMP180.

On the bus it behaves like the real one: ID 0x55, eleven calibration values from 0xAA (those from the worked example in the datasheet), a conversion starts with 0x2E (temperature) or 0x34 plus accuracy × 64 (pressure) in 0xF4, and the result is at 0xF6 a few milliseconds later. Reading too early returns the old value. In C, use Adafruit_BMP085.h (the library also covers the BMP180): begin(mode), readTemperature(), readPressure() in Pa, readAltitude(sea_level_pressure) and readSealevelPressure(altitude), with the same waits and integer formulas as the library. Real AVR code needs it installed. In Python, bmp180 is already there, with the interface of micropython-IMU: bmp = BMP180(i2c), then bmp.temperature in °C, bmp.pressure in Pa, bmp.altitude in m, plus oversample_sett (0 to 3) and baseline. On a real board, bmp180.py has to be copied over as a file.

Limits: conversions finish a little faster than the datasheet's maximum times, and there is no noise or drift.

Colour TFT

The ILI9341 is a colour display with 240 × 320 pixels on SPI. It understands the controller's commands: window, pixel data in 16 or 18 bits, rotation with MADCTL, invert, on and off, and the read commands for its status. On the Uno, MOSI goes to D11, SCK to D13, MISO to D12 only for reading. On the Pico, SPI0 is GP19, GP18 and GP16 (or what machine.SPI chooses), on the ESP32 VSPI is GPIO23, GPIO18 and GPIO19 (HSPI: 13, 14, 12). CS and DC may be any pins. RST and LED (backlight) are not simulated, as in Wokwi.

LanguageWhat you use
C in the interpreterAdafruit_ILI9341.h with Adafruit_GFX.h is rebuilt: begin(), fillScreen(), pixels, lines, rectangles, rounded rectangles, circles, triangles, text with size and colour, setRotation(), invertDisplay(), color565() and readcommand8(). Only the constructor with CS and DC works, software SPI does not. Other fonts and bitmaps are missing.
Real AVR or RP2040 codeThe real library, installed in the Arduino IDE. The SPI unit of the chip hands every byte to the display.
Pythonili9341 is already there, following micropython-ili9341: Display(spi, cs, dc, rotation=0), color565(), clear(), fill_rectangle(), draw_pixel(), lines, rectangles, circles and draw_text8x8(). The rotations 0, 90, 180 and 270 turn as in Adafruit_ILI9341. On a real board, ili9341.py has to be added as a file.

Hardware SPI arrives as whole bytes, like I²C: The display listens while its CS is LOW and reads DC for every byte. That keeps it fast, but the Logic Analyzer sees nothing on MOSI and SCK. Pins switched with shiftOut() also work, bit by bit. A full fillScreen() takes about 150 ms as on a real Uno, so animations should only redraw what changes. In the ESP32 profile, machine.SPI hands its buffers over in one go; that is much faster here than SoftSPI, whose edges the slower processor hardly manages. The ATtiny85 has no hardware SPI here.

microSD card

The card sits on SPI as in Wokwi: DI to MOSI, DO to MISO, SCK to SCK, CS to any pin. On the Uno these are D11, D12 and D13, CS usually D10, on the Pico SPI0 with GP19, GP16 and GP18 (CS for example GP17), on the ESP32 VSPI with GPIO23, GPIO19 and GPIO18 (CS GPIO5). It understands the SD protocol in SPI mode (start-up, reading and writing single and multiple blocks) and holds 8 MB with FAT16. CD reports nothing because a card is always inserted.

LanguageWhat you use
C in the interpreterSD.h is rebuilt and speaks the real protocol over SPI: SD.begin(cs), SD.open() with FILE_READ or FILE_WRITE, exists(), remove(), mkdir(), rmdir(). A File has print(), println(), write(), read(), peek(), available(), readStringUntil(), seek(), size(), name(), isDirectory(), openNextFile(), flush() and close(). Names are 8.3 as in the library.
Real AVR or RP2040 codeThe real SD or SdFat libraries, on the Pico the core's SD library. The SPI unit of the chip hands every byte to the card.
Python on the Picosdcard is already there, with the interface of sdcard.py from micropython-lib: sd = sdcard.SDCard(spi, Pin(17, Pin.OUT)), then os.mount(os.VfsFat(sd), "/sd") and ordinary files under /sd. On a real board, sdcard.py has to be added as a file.
Python in the ESP32 profilemachine.SDCard(slot=2, sck=18, miso=19, mosi=23, cs=5) as in the ESP32 firmware, then os.mount(sd, "/sd"). Only the SPI mode works here (slot 2 or 3); the SD/MMC mode of slots 0 and 1 does not fit this module. sdcard works too.

What the sketch writes shows up in the SD card tab next to the monitor after you stop, and it stays in the project. There you can also create, edit, upload and delete files before starting, for example a settings file for the sketch to read. The project holds at most 64 entries and 256 KB. As on the board, text is only safely on the card after close() or flush(), in Python after close(), the end of a with block or os.umount().

LED ring

The ring follows WS2812: Each LED takes 24 bits on DIN, and a HIGH of about 0.4 µs means 0, about 0.8 µs means 1. After 50 µs of quiet it takes over the colours. Whatever goes beyond its own LEDs runs on through DOUT to the next ring. LED 0 sits at the top here, continuing clockwise. The single WS2812B LED is the same part with exactly one LED; several in a row, DOUT to DIN, make a strip, and rings and single LEDs can be mixed in one chain.

LanguageWhat you use
C in the interpreterAdafruit_NeoPixel.h is rebuilt: begin, show, clear, setPixelColor, fill, Color, ColorHSV, gamma32, setBrightness, numPixels, getPixelColor.
Real code on Uno, ATtiny85 and PicoThe real library, installed in the Arduino IDE as "Adafruit NeoPixel", or FastLED (FastLED.addLeds<WS2812B, PIN, GRB>). The ring then reads the edges on the pin, and the Pico produces them through its PIO. FastLED is only available here, not in the interpreter.
Pythonneopixel.NeoPixel(Pin(n), count) with write() and fill(), on Pico and ESP32.

Limits: In the interpreter and Python the bytes arrive directly, with no edges on the wire. Only the wiring is checked then. The high LED current, up to 60 mA per LED, is not calculated. On the ESP32 and Pico, 3.3 V on the data wire is often too low for LEDs at 5 V, and the simulation does not warn about it. Use a level shifter on a real build.

Membrane keypad

A pressed key connects its row to its column, and no other parts are needed. While running, click a key or type 0 to 9, A to D, * and # on the keyboard, as long as the cursor is not in the code or monitor. In the inspector you choose 4 or 3 columns. With 3, the right column and C4 go away.

LanguageWhat you use
C in the interpreterKeypad.h is rebuilt: Keypad k = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS) plus getKey, getState, keyStateChanged, setDebounceTime, setHoldTime and NO_KEY.
Real codeThe real library, installed in the Arduino IDE as "Keypad".
PythonScanning by hand with machine.Pin, see the example.

The ATtiny85 has too few pins for eight lines. The example ATtiny85: keypad over PCF8574 therefore connects the keypad to a PCF8574 and scans it itself over Wire.h, without the Keypad library.

Limits: Only one key can be pressed at a time, and the keys do not bounce. Custom labels as on Wokwi are not available, but you can freely choose the key map in the sketch. The interpreter has no waitForKey, getKeys or addEventListener.

Joystick

The joystick consists of two pots between VCC and GND and a button. HORZ gives the full voltage at the left and 0 V at the right, VERT the full voltage at the top and 0 V at the bottom. At rest both sit at half the voltage, so on the Uno analogRead returns about 512. SEL connects to GND when pressed and floats otherwise. So use INPUT_PULLUP and check for LOW.

While running, drag the knob. When released, it springs back to the centre. A click without dragging presses the button. The keyboard works too: The arrow keys move fully, also diagonally, the space bar presses the button. The cursor must not be in the code or the monitor. The directions apply on screen, even if you rotate the joystick: Right is always right. On the ESP32, power the joystick from 3.3 V, since the inputs take no more.

Limits: The keyboard only knows full deflection, positions in between need the mouse. The button does not bounce.

Rotary encoder KY-040

Every step pulls CLK and DT LOW one shortly after the other and releases them again. Clockwise, CLK goes LOW first, counterclockwise DT. So if the program reads DT the moment CLK falls, it gets the direction: HIGH means clockwise. One step takes 8 ms here. CLK and DT have pull-ups on the module, which need VCC connected. SW connects to GND when pressed and needs INPUT_PULLUP.

While running, the arrows next to the knob or the mouse wheel over it turn it one step. A click on the knob presses it. On the keyboard: click the encoder, then the arrow keys turn it (right and up clockwise), continuously while held, and the space bar presses it.

Polling only in loop() misses steps as soon as the loop takes longer than a few milliseconds. That is what interrupts are for. The interpreter supports attachInterrupt(digitalPinToInterrupt(pin), function, mode) with RISING, FALLING or CHANGE, plus detachInterrupt, interrupts and noInterrupts. The Uno has interrupts on D2 and D3, the ATtiny85 on PB2, the ESP32 on every GPIO. IRAM_ATTR may precede the function. In Python, use Pin.irq.

Limits: The contacts do not bounce. The interpreter looks for edges every 20 µs, also during delay(). LOW and HIGH are not available as a mode there.

MCP23017

16 inputs and outputs over I²C, in two ports of eight pins: GPA0–GPA7 and GPB0–GPB7. The address is 0x20 to 0x27 via A0 to A2, which belong at VSS or VDD. RESET belongs at VDD. After power-up all pins are inputs. Unlike the PCF8574, registers set the direction (IODIR), switch on pull-ups (GPPU) and invert inputs (IPOL). Reading is from GPIO, writing to OLAT, and the register address counts on while reading and writing.

INTA and INTB report changes on the inputs that have GPINTEN set: compared with the last level or with DEFVAL (INTCON). INTF shows the pin, INTCAP the levels at that moment, and reading GPIO or INTCAP clears the interrupt. IOCON mirrors the two outputs, makes them open drain or inverts their polarity. That way a button reaches the ESP32 through attachInterrupt without the program asking all the time.

The interpreter has the Adafruit_MCP23X17 library with begin_I2C, pinMode, digitalWrite, digitalRead, readGPIOA/B/AB, writeGPIOA/B/AB, setupInterrupts, setupInterruptPin, disableInterruptPin, getLastInterruptPin, getCapturedInterrupt and clearInterrupts. Pins 0 to 7 are GPA0 to GPA7, 8 to 15 GPB0 to GPB7. Real code needs the "Adafruit MCP23017 Arduino Library".

Limits: Only IOCON.BANK = 0, the usual register layout. The pull-ups have 10 kΩ here instead of 100 kΩ.

PCA9685

16 PWM outputs with 12 bits over I²C, meant for servos and LEDs: One chip drives up to 16 servos over two wires. The address is 0x40 to 0x47 via the solder jumpers, set in the inspector. Like the real chip it also answers writes at 0x70 (ALLCALL), so an I²C scanner finds two addresses. OE may stay open, HIGH switches all outputs off.

After power-up it sleeps and all outputs are off. The frequency follows from PRE_SCALE, 25 MHz / (4096 × (PRE_SCALE + 1)), and can only be changed while asleep. Each channel has four registers for the on and off point within the period, plus full on and full off. An LED shines with the average current, a servo reads the pulse width: 544 µs is 0°, 2400 µs is 180°, as with the Servo library. Servos need 5 V on their V pin, on the real module through V+.

The interpreter has the Adafruit_PWMServoDriver library with begin, setPWMFreq, setPWM, setPin, writeMicroseconds, getPWM, sleep, wakeup, reset, setOutputMode and setOscillatorFrequency. Real code needs the "Adafruit PWM Servo Driver Library". Many examples online call setOscillatorFrequency(27000000) because real chips run a little fast. The simulated one runs at exactly 25 MHz, so without that call the pulse widths are right.

Limits: no external clock, no sub-addresses, and all channels start their period at the same time.

ADS1115

A 16-bit analog-to-digital converter with four inputs over I²C, on SDA and SCL like other I²C parts. The address depends on ADDR: open or at GND 0x48, at VDD 0x49, at SDA 0x4A, at SCL 0x4B. Open is allowed, the module pulls ADDR to GND. Each input is measured against GND or as the difference of two inputs (A0–A1, A0–A3, A1–A3, A2–A3). The range goes from ±6.144 V to ±0.256 V, the data rate from 8 to 860 readings per second.

Like the real chip, a single reading starts with bit 15 in the config register, and that bit reads as 0 until the reading has finished after 1/data rate. Continuous mode is there too. The interpreter has the Adafruit_ADS1X15 library with begin, setGain, setDataRate, readADC_SingleEnded, readADC_Differential_0_1 and the other differences, computeVolts, startADCReading, conversionComplete and getLastConversionResults. Real code needs the "Adafruit ADS1X15" library. In Python you write the registers yourself, see the example.

Limits: ALRT and the comparator have no function, and the converter has no noise.

DS18B20

A temperature sensor with OneWire: data and clock share one line, DQ. It is open, so a 4.7 kΩ pull-up belongs between DQ and VCC, otherwise it floats and the app says so. Several sensors may share the same line: Each has its own 64-bit address (family 0x28), which the inspector shows and the search finds.

Set the temperature by dragging while running, from -55 to 125 °C. Like the real chip, the register holds 85 °C after power-up until the first conversion has finished. A conversion takes 94 ms (9 bits) to 750 ms (12 bits) depending on the resolution. Simulated are reset, read and write slots, the ROM commands READ, SKIP, MATCH and SEARCH, and CONVERT, READ and WRITE SCRATCHPAD with CRC.

The interpreter has OneWire (reset, write, read, skip, select, search, reset_search, crc8) and DallasTemperature (begin, getDeviceCount, requestTemperatures, getTempCByIndex, getTempC, getAddress, setResolution, setWaitForConversion and more), plus DeviceAddress. They work with real timing on the line. Real code needs the "OneWire" and "DallasTemperature" libraries. MicroPython already includes onewire and ds18x20.

Limits: no parasite power, no alarms, no EEPROM. Like the DallasTemperature library, the app reports -55 °C as disconnected.

MPU6050

Acceleration, rotation rate and temperature over I²C, on SDA and SCL like other I²C parts. The address is 0x68, with AD0 at VCC 0x69. AD0 may stay open, the module has a pull-down. XDA, XCL and INT have no function here.

While running, dragging tilts the sensor: to the right lowers the right edge (pitch), down lowers the bottom edge (roll), up to 90° each. The bubble on the board runs to the higher side. Set the rotation rates around X, Y and Z and the temperature in the inspector, where roll and pitch can also be set to the degree.

Like the real chip it sleeps after power-up and returns zeros until the program writes a 0 to register 0x6B. The ranges in 0x1C and 0x1B are honoured. The interpreter has the Adafruit_MPU6050 library with begin, getEvent(&a, &g, &temp), setAccelerometerRange, setGyroRange and setFilterBandwidth. a.acceleration.x is in m/s², g.gyro.x in rad/s, temp.temperature in °C. Real code needs the "Adafruit MPU6050" library. In Python, read the registers with readfrom_mem.

Limits: no FIFO, no DMP, no interrupt, and the sensor has no noise.

DIP switch (8)

Eight switches in one package. A switch that is on connects na to nb, slider up means on. Usually one side goes to GND and the other to pins with INPUT_PULLUP: A switch that is on then reads LOW. While running, a click on a slider toggles it, after clicking the switch also the keys 1 to 8. The positions are saved with the project.

PIR motion sensor

Like the HC-SR501: After a motion, OUT stays HIGH for the delay time (default 5 s), then the sensor ignores motion for the inhibit time (1.2 s). With retrigger, every further motion extends the delay time. All three are set in the inspector. While running, a click on the sensor is a motion, the red LED shows OUT. It needs 5 V on VCC, but outputs only 3.3 V on OUT, so it also suits the ESP32, powered from VIN there.

NTC temperature sensor

A voltage divider like the module on Wokwi: 10 kΩ from VCC to OUT, the NTC (10 kΩ at 25 °C, beta 3950) from OUT to GND. When it gets warmer, the NTC's resistance falls and so does the voltage on OUT. Set the temperature by dragging while running, from -40 to 125 °C, and the beta coefficient in the inspector. Convert the value with 1 / (log(1 / (1023. / value - 1)) / BETA + 1.0 / 298.15) - 273.15. On the ESP32 use 4095 instead of 1023, and power the module from 3.3 V so it has the same voltage as the ADC.

CD4017 counter

A decade counter from the CMOS 4000 series: Every rising edge on CLK moves the one HIGH output from Q0 through Q1 to Q9 and then back to Q0. RST HIGH resets to Q0, INH HIGH stops it. For normal operation both belong on GND. CO is HIGH at counts 0 to 4 and clocks a second CD4017 for the tens. It is powered through VDD and VSS with 3 to 15 V.

Connecting RST to an output makes it count only up to there: RST on Q5 gives five steps. The outputs supply only a few mA, so an LED on them is dimmer than on a board pin. The example Running light with 555 and CD4017, no code shows the running light with an NE555 as the clock.

74HC595 shift register

The 74HC595 drives eight outputs over three pins. For normal operation, connect VCC and MR to 5 V, and GND and OE to GND. DS, SHCP and STCP go to any three pins of the board. The LED chaser with 74HC595 example shows the finished circuit.

One output may supply 35 mA, the whole IC 70 mA. Eight LEDs with 220 Ω are already above that, so the example uses 470 Ω. The Debug tab shows both registers during a run. SPI.h also works: DS to MOSI, SHCP to SCK, STCP as usual on a pin. A second 74HC595 on Q7S only sees bits from shiftOut(). Signal delays are not simulated.

74HC165 shift register

The 74HC165 is the counterpart of the 74HC595: It reads eight inputs over three pins. Connect VCC to 5 V, and GND and CE to GND. PL, CP and Q7 go to three pins of the board, and unused inputs and DS to GND. The Read switches with 74HC165 example shows the finished circuit.

Note: shiftIn() only reads after the rising edge. If the clock is LOW beforehand, D7 is lost. Set CP HIGH before loading, because after loading that would be the first edge. The same applies on a real board.

HX711

A 24-bit converter for load cells, here with a cell up to 5 kg. Drag the load cell while running to set the weight, or type it in the inspector. Like the real chip it has its own clock: DT goes LOW when a reading is ready, about 10 times per second. Each rising edge on SCK then shifts one bit out, most significant first. After the 24 bits, one more pulse selects channel A with gain 128 for the next reading, two select channel B with 32, three channel A with 64. The new gain only applies from the next reading, and the first one after power-up is always A with 128.

The raw value is a fixed zero offset plus about 420 steps per gram at gain 128, so tare() and set_scale(420) give grams. Channel B has nothing connected and only returns the offset. SCK held HIGH switches the chip off, taking it back LOW starts it like after power-up. The datasheet says 60 µs; here it is 150 µs, because the simulated MicroPython needs about 80 µs for sck.on(); sck.off(), much longer than a real ESP32.

The interpreter has the HX711 library by Bogdan Necula with begin, is_ready, wait_ready, wait_ready_timeout, read, read_average, get_value, get_units, tare, set_scale, get_scale, set_offset, get_offset, set_gain, power_down and power_up. Real code needs the "HX711 Arduino Library". Limits: no noise, no drift, and the weight is the same at every gain apart from the factor.

Stepper motor

A 28BYJ-48 on its ULN2003 driver board. IN1 to IN4 switch the four coils, the LEDs A to D on the board show which ones are on, and the pointer on the motor shows the shaft. The direction follows from the order of the patterns: one coil, then two, then the next one is a half step, two coils at a time a full step. 4096 half steps or 2048 full steps make one turn. The motor needs 5 V on VCC; the inputs also work with 3.3 V.

If the patterns come in the wrong order, the motor only vibrates and the app says so. That is the classic mistake with the Arduino Stepper library: it expects the pins in the order IN1, IN3, IN2, IN4, so Stepper motor(2048, 8, 10, 9, 11) for IN1 to IN4 on D8 to D11. The motor also stops if the steps come faster than about 15 turns per minute. The interpreter has the Stepper library with setSpeed and step, which waits like the original until all steps are done. Stepper comes with the Arduino IDE.

Stepper with A4988

A bipolar stepper (NEMA 17, 200 steps per turn, 1.8° per step) with the A4988 driver, as on the Pololu module. Every rising edge at STEP turns it by one step, DIR HIGH means clockwise. MS1 to MS3 pick the resolution: all open is full steps, MS1 half, MS2 quarter, MS1 and MS2 eighth, all three sixteenth steps. VDD gets the logic voltage (3 to 5.5 V), VMOT the motor voltage of 8 to 35 V, for example from the power supply set to a 12 V bench supply; its minus goes to the board's GND. See Stepper motor with A4988 driver.

As on the module, EN and MS1 to MS3 have pull-downs and SLP a pull-up. RST is open and has to be HIGH, so it is usually connected to the neighbouring SLP pin. The motor stays put when EN is HIGH, RST or SLP is LOW or VMOT is below 8 V, and a hint says which. Without ramping up it manages about 1000 full steps per second; faster, it stalls. No library is needed, digitalWrite on STEP and DIR is enough, likewise with Pin in Python. AccelStepper is not available in the interpreter.

Limits: the coil current, the current-limit pot and the holding torque are not modelled, and the power supply sees no load.

L298N motor driver

The red module with the heat sink drives two DC motors in both directions: motor A on OUT1 and OUT2, motor B on OUT3 and OUT4. IN1 and IN2 pick the direction of motor A (HIGH and LOW forwards, LOW and HIGH backwards, both the same brakes), IN3 and IN4 that of motor B. ENA and ENB switch the motors on; on the real module jumpers tie them to 5 V, so when open they count as HIGH. For speed control you pull the jumper and connect a PWM pin to ENA or ENB; PWM on an IN pin works too. The motor then turns with the average voltage.

12V gets the motor voltage of 7 to 35 V, for example from the power supply, and GND also goes to the board's GND. The chip loses about 2 V, so at 12 V the motor gets around 10 V; at 5 V from the board barely anything would be left, and a hint says so. The regulator on the module supplies 5 V at the 5V pin as soon as 12V has at least 7 V. The inputs see HIGH from 2.3 V, so the Pico and the ESP32 with 3.3 V work. See Two DC motors with L298N and Pico: motor speed and direction with a pot.

MQ-2

A gas sensor module. Drag it while running to add gas; the label shows it as 200 to 10000 ppm. AOUT gives 10 to 90 % of VCC, rising with the gas. DOUT is LOW above a threshold, which a pot sets on the real module and the inspector sets here, and the second LED on the module shows it. The curve of the real sensor is bent and depends on the gas, the temperature and the humidity; here it is smoothed to a straight line, and it needs no heating time.

Logic gates

Gates only need VCC at 5 V and GND at GND, and no sketch at all. The Half adder with gates example shows this. One package holds several gates, and the number in the pin name belongs to the gate: 1A, 1B and 1Y form the first.

ICABY
Example 74HC00, NAND110, otherwise 1
Example 74HC08, AND111, otherwise 0
Example 74HC32, OR000, otherwise 1
Example 74HC86, XORA and B differ1, otherwise 0

The 74HC14 is an inverter with a Schmitt trigger. Its input only counts as HIGH above about 53 % of the supply and only as LOW again below about 31 %, so above 2.65 V and below 1.55 V at 5 V. In between, the output stays as it was. That cleans up slow or noisy signals, for example from a photoresistor or a capacitor, and with one resistor and one capacitor a single gate becomes a blinker. The examples Blinker with one Schmitt trigger, no code and Night light with Schmitt trigger, no code show both.

Unused gates may stay open, and the app says nothing about them. On a used gate, an open input counts as LOW and triggers a warning. On a real IC, its behavior is undefined. An output that leads back to its own input and oscillates gets reported, because the simulation has no signal delays.

The 74HC02 is a NOR gate like the others, but with its own pinout: on each gate the output comes before the two inputs, 1Y is pin 1. Two NOR gates feeding each other remember one bit, see Set-reset latch with 74HC02, no code. Such a latch has two stable states; the simulation starts it in one of them, while a ring of three inverters still gets reported because it has none.

The 74HC74 holds two D flip-flops. A rising edge on CLK takes over the level on D, Q shows it and QN the opposite. PRE and CLR are active LOW: LOW on PRE sets Q, LOW on CLR clears it, both LOW give HIGH on Q and QN. For normal operation they belong at VCC. With QN wired back to D each edge toggles the output, see Toggle with a 74HC74 flip-flop, no code.

74HC4051

An analog switch with eight channels: S0 to S2 pick one of Y0 to Y7 in binary, and it connects that channel to Z with about 80 Ω. Signals pass in both directions, so it can spread one analog pin over eight pots or one output over eight LEDs. E is the enable input and must be LOW, HIGH disconnects all channels. VEE is the lower limit of the signals and belongs at GND for signals between 0 V and VCC. See 74HC4051: four pots on one analog pin. Limits: no negative voltages on VEE.

Logic analyzer

Eight channels, D0 to D7, that only measure and load nothing. While the simulation runs it records every level change with its time, to a fraction of a microsecond. GND belongs on the circuit's GND, otherwise a hint says that a real one would only show noise. The LEDs on the part light up on activity, the display counts the changes.

The recording is in the Logic tab next to the serial monitor, live while running and complete after stopping. The mouse wheel zooms about the pointer, + and − about the marker or, without one, about the middle, dragging moves, All shows the whole recording, Follow keeps the end in view. With Shift the wheel scrolls through the channels. Hovering over a trace measures: level, how long it lasts, period, frequency and share HIGH. A click sets a marker, after which the distance to the marker is shown too. On the keyboard: arrow keys move, Enter sets the marker, Escape clears it. Dashed in the middle means Z: nothing drives the line.

In the inspector: channel names, separated by commas, such as DATA,CLOCK,LATCH. Trigger: off records everything; edge starts as soon as the trigger channel changes to the trigger level and runs to the end; level records only while the level is present and pauses in between. As at Wokwi, only the change counts, not a level already present at the start. Buffer: each change takes one slot, one million by default. When it is full, recording ends.

Save VCD writes the recording as a Value Change Dump with a 1 ns time base. PulseView opens it with "Import Value Change Dump" and decodes UART, I²C, SPI and more there; GTKWave reads it too. If no download starts in the browser, Copy copies the text. See Logic analyzer on a shift register.

What the simulation only knows as a duty cycle becomes a square wave again for the recording: analogWrite at 490 Hz (D5 and D6 on the Uno 980 Hz, ESP32 1 kHz or the frequency from ledcAttach), tone, the Servo library at 50 Hz and the PWM outputs of the PCA9685. Real AVR code and the Pico report every edge themselves, so the phase is right there too.

Serial and I²C: the simulation passes both on as whole bytes. For the recording they become bits again, as they would be on the lines. On TX (Uno D1, ESP32 GPIO1, ATtiny PB0) each character is a frame with start bit, eight data bits and stop bit, at the baud rate from Serial.begin() or, with real AVR code, from the register. On SDA and SCL there are START, the address with the write or read bit, the bytes with ACK or NACK, and STOP, at 100 kHz, the frequency from Wire.setClock(), or 400 kHz where a library sets that. PulseView decodes the saved VCD file like a real recording. Bits are only made where a channel is connected, and only for the recording: the voltage calculation does not change. Your own bit-banging, SoftwareSerial on the ATtiny and SoftI2C on the Pico are real edges anyway. Limits: the bits sit evenly on the clock; there is no clock stretching and none of the real library's pauses between bytes. The Pico sends print over USB, so there is no TX there. If a program sends faster than the line can carry, frames are dropped once they would fall 0.2 s behind. The voltage is only compared against half the board's supply; there is no in-between range.

Multimeter

Two probes like a real one: + is the red one, COM the black one and the reference. Choose the range in the inspector; while running, a click on the dial switches on: V, A, Ω. The display picks the unit itself (mV, V, mA, kΩ …) and shows four digits. When stopped it shows -.---.

Voltage (V): across whatever you want to measure, so + to the point and COM to GND or to the other end of the part. The input has 10 MΩ and hardly loads the circuit. With the probes swapped, a minus sign appears. Like a real one on the DC range it shows the average and updates about three times a second. A PWM pin therefore reads as its mean voltage: analogWrite(9, 128) shows about 2.5 V.

Current (A): in series. Break the connection whose current you want to know and put the multimeter in between, for example between the series resistor and the LED. On the current range it has only 0.1 Ω. Across a source or a pin it is therefore a short circuit: the app then reports the current at the pin or the supply, and above 10 A the multimeter reports that its current range can't take it. The average counts here too, a PWM pin shows the mean current.

Resistance (Ω): only with the power off. The multimeter applies 1 V through 10 kΩ itself and works out the resistance from the voltage. Best measure a part that is not connected to the board. If it sits in the circuit, you also measure everything in parallel with it. If there is a voltage between the probes, a hint says the reading is wrong. OL means open or more than 20 MΩ. LEDs don't conduct at 1 V and therefore also show OL, as does a reverse-biased diode. Forward-biased, a diode shows a few tens of kΩ: that is not a resistance but its threshold voltage, converted. A capacitor charges up and then shows OL.

Limits: DC only, no AC range, no diode test, no continuity beeper and no capacitance measurement. There is a single jack for all ranges, and no fuse blows.

Examples

ExampleShowsTry
Traffic light with buttonA sequence with delay()Press the button
Blink an LEDSwitching outputsJust start it
Dimmer with potanalogRead, analogWrite, millisDrag the pot
Night lightVoltage divider, thresholdDrag the photoresistor
Melody on the buzzertone() and arraysPress the button
Servo with potServo.h, map()Drag the pot
RGB color wheelThree PWM channels, sin()Just start it
Digit counterBit patterns, edge detectionPress the button
LED chaser with 74HC595Shift register, shiftOut()Just start it
Text on the LCDLiquidCrystal.h, contrastDrag the pot
Port expander PCF8574Wire.h, writing and readingPress the button
RTC: RTClib clock with 1 Hz interruptRTClib.h, DateTime, SQW on an interrupt, LED on SQWJust start it, pick a start time in the clock's panel
Pico: DS1307 clockds1307 in MicroPython, SQW at 1 HzJust start it
RTC: DS3231 alarm every 10 secondsRTC_DS3231, alarm 1 on SQW, interrupt, temperatureJust start it, change the temperature in the panel
Clock with DS1307 and I²C LCDTwo modules on one busJust start it
LED matrix with MAX7219LedControl.h, bit patternsJust start it
Scrolling text on a 4-in-1 LED matrixLedControl.h with four modules, own fontJust start it
MD_Parola: text effects on the 4-in-1 matrixMD_Parola.h over hardware SPI, four effects in turnJust start it
MD_Parola: a sprite carries the textsetSpriteData(), PA_SPRITE with a robot of its ownJust start it
MD_Parola: counter and scrolling text in two zonessetZone(), displayZoneText(), text in a char arrayJust start it
Pico: scrolling text with max7219max7219 in MicroPython, text() and show()Just start it
IR remote dims an LEDIRremote.hpp, decodedIRData, repeat codesClick POWER, then click and hold + or − on the remote
Level meter on an LED bar graphTen outputs via an array, map()Drag the pot
Stopwatch on a TM1637 displayTM1637Display.h, showNumberDecEx with colon, millis()Just start it, the button resets to 00:00
Pico: blink an LEDMicroPython, Pin, LED on the boardJust start it
Pico: button toggles an LEDPin.PULL_UP, detecting an edgePress the button
Pico: dimmer with pot and PWMADC, PWMDrag the pot
Pico: running light over I²CI2C, scan(), PCF8574Just start it
Pico in C: blink an LEDArduino C on the RP2040, breakpointsSet a breakpoint
Pico in C: button countsSingle steps, call stackBreakpoint in report()
Pico in C: dimmer with potanalogRead(), analogWrite()Drag the pot
ESP32: blink an LEDGPIO2, Serial.printf()Just start it
ESP32: dimmer with ledcWrite12-bit ADC, ledcWrite()Drag the pot
ESP32: LED over I²CWire.begin(21, 22), PCF8574Just start it
ESP32 in Python: blink an LEDmachine.PinJust start it
ESP32 in Python: dimmerADC, PWM.duty()Drag the pot
ESP32 in Python: LED over I²CI2C, scan()Just start it
ESP32: buttons over PCF8574Saving inputs, INTPress the buttons
ESP32 in Python: buttons over PCF8574Saving inputs, INTPress the buttons
Half adder with gatesLogic with no sketch at allClick the switches
Read switches with 74HC165Saving inputs, shiftIn()Click the switches
NPN transistor switches an LEDBase resistor, PWMJust start it
Capacitor charging curveRC time constant, analogReadWatch the monitor
Smooth PWM with a capacitorLow-pass from 10 kΩ and 10 µFDrag the pot
ESP32: MOSFET switches a 5 V loadGate pull-down, flyback diodeJust start it
Relay with transistorFlyback diode, COM and NOJust start it
LED blinks with a 555, no codeNE555 as a blinkerLook at the voltages on the 555
Running light with 555 and CD4017, no codeNE555 as the clock, decade counter, one resistor for ten LEDsJust start it
Measuring with a multimeterMeasuring voltage across and current in series, average with PWMDrag the pot and compare the meters with the Serial Monitor, click the dial while running
Logic analyzer on a shift registershiftOut to a 74HC595 and PWM, recorded by the logic analyzerMeasure a clock in the Logic tab, set the trigger to LATCH, open the VCD in PulseView
Logic analyzer on I2C and SerialRead a DS1307 clock over I²C, print the time over Serial, both as bits in the logic analyzerFind START, the address and the NACK in the Logic tab, open the VCD in PulseView with the I²C and UART decoders
Tone from a 555NE555 as a tone generatorChange the resistor or capacitor
One-shot timer with a 555NE555 as a one-shotPress the button briefly
Light switch with LM358LM358 as a comparatorAdjust the light and the pot
Blinker with one Schmitt trigger, no code74HC14 with R and C as an oscillatorJust start it, look at the voltage on the 74HC14
Night light with Schmitt trigger, no codeHysteresis against flickerDrag the light slowly back and forth
Set-reset latch with 74HC02, no codeTwo NOR gates remember one bitPress S, then R
Toggle with a 74HC74 flip-flop, no codeD flip-flop with QN back to DPress the button several times
74HC4051: four pots on one analog pinChannel select in binary, one ADC pin for four inputsTurn the pots
Amplifier with LM358LM358 as an amplifier, limit at 3.5 VMove the pot, watch the monitor
Distance with HC-SR04pulseIn()Drag the sensor
ESP32: distance with HC-SR04Voltage divider on ECHODrag the sensor
ESP32 in Python: distance with HC-SR04time_pulse_us()Drag the sensor
ESP32: motor speed with MOSFETPWM with ledcWrite(), flyback diodeDrag the pot
Motor on a 9 V battery with MOSFETExternal power supply, common ground, PWM on a MOSFETDrag the pot
Power rail: three LEDs on a batteryPower rail, transistors as switches, common groundJust start it
Pico: SD card data loggersdcard, os.VfsFat, appending to a fileStart it, after stopping open the SD card tab
ESP32 in Python: SD card with machine.SDCardmachine.SDCard, reading and writing a settings fileBefore starting, edit SETTINGS.TXT in the SD card tab
SD card: data loggerSD.h, appending to a file, listing a directoryStart it, after stopping open the SD card tab
TFT: Hello, TFT!Adafruit_ILI9341.h, text in colourJust start it
Pico: colour TFTili9341, machine.SPIJust start it
ESP32: colour TFTAdafruit_ILI9341.h on VSPIJust start it
ESP32 in Python: colour TFTili9341 in landscapeJust start it
TFT: bouncing ballsetRotation(), redraw only what changesJust start it
ESP32: OLED displayText and graphics, display()Just start it
ESP32 in Python: OLED displayssd1306, framebufJust start it
ESP32: BME280 weather sensorRegisters over I²C, Serial.printf()Drag the sensor
ESP32 in Python: BME280 weather sensorbme280Drag the sensor
ESP32: DHT22 sensorDHT.h, isnan()Drag the sensor
ESP32 in Python: DHT22 sensordhtDrag the sensor
ESP32: weather over Wi-FiWiFi.h, HTTPClient.h, temperature from open-meteo.comJust start it; HTTP under npm start and in the apps
ESP32: web server with two LEDsWebServer.h, UriBraces, lambda, raw stringOpen the Web tab, click the buttons
ESP32: NTP clock on the I²C LCDconfigTzTime(), getLocalTime(), strftime(), summer timeJust start it
ESP32: alarm clock with weatherKeypad, I²C LCD, NTP and HTTP together, JSON without a library; after a Wokwi projectA sets the alarm, C the clock (hhmmss, then #), # silences, * snoozes
ESP32 in Python: weather over Wi-Finetwork, urequests, json()Just start it; HTTP under npm start and in the apps
ATtiny85: blink an LEDPin numbers, debuggerJust start it
ATtiny85: on a 9 V battery with 7805Voltage regulator, capacitors at regulator and chip, VCC as an inputWire the battery straight to VCC
ATtiny85: WS2812B stripAdafruit_NeoPixel.h, single WS2812B chained through DOUTTake one LED out of the chain
ATtiny85: dimmer with potanalogRead(A3), PWM on PB1Drag the pot
ATtiny85: more pins with PCF8574Wire.h over USI, pull-upsJust start it
ATtiny84: table dice with WS2812BSeven WS2812B as dice pips, four buttons with pull-downs, random, 9 V battery through a 7805Press a button. Move the data pin to PA5: NeoPixel only drives port B on the ATtiny84
ATtiny84: two dimmersClockwise pin numbers, PWM from Timer 0 and Timer 1, A0 and A3Drag the pots
ATtiny84: I²C LCDLiquidCrystal_I2C.h over USI on 6 and 4Drag the pot
ATtiny84: binary clock with DS1307TinyWireM.h, 74HC595 for the minutes, BCD from the clockJust start it, the clock runs from the computer's time
ATtiny85: keypad over PCF8574Eight keypad lines over two pins, one column LOW at a timeType 1234 and #
Four digits with multiplexingMultiplexing, bit patternsJust start it
LCD with four rows16×4, setCursor in rows 3 and 4Just start it
LED ring: rainbowAdafruit_NeoPixel.h, ColorHSVJust start it
ESP32: LED ringsetPixelColor, ring on VINJust start it
ESP32 in Python: LED ringneopixelJust start it
MCP23017: 16 more pins over I²CAdafruit_MCP23X17, writeGPIOA, pull-upPress the button
ESP32: MCP23017 buttons with interruptINTA to attachInterrupt, getLastInterruptPinPress the buttons
ESP32 in Python: MCP23017Registers by handPress the button
PCA9685: servos and an LED over I²CAdafruit_PWMServoDriver, writeMicroseconds, setPWMJust start it
ESP32: servo over PCA9685A pot controls a servo on the PCA9685Turn the pot
ESP32 in Python: PCA9685PRE_SCALE while asleep, channel registers by handJust start it
ADS1115: 16 bits against the UnoThe same voltage with 10 and with 16 bitsTurn the pot
ESP32: ADS1115 16-bit ADCGAIN_ONE, fastest data rateTurn the pot
ESP32 in Python: ADS1115Registers by hand, waiting for bit 15Turn the pot
DS18B20 thermometerOneWire and DallasTemperature, pull-upDrag the sensor
Two DS18B20 on one wireSearch, DeviceAddress, getAddressDrag both sensors
ESP32: DS18B20 thermometersetResolution(10), faster conversionDrag the sensor
ESP32 in Python: DS18B20 thermometeronewire, ds18x20Drag the sensor
MPU6050 tilt and rotationAdafruit_MPU6050, getEvent, atan2Drag the sensor
MPU6050 without a libraryRegisters over Wire, waking up with 0x6BDrag the sensor
ESP32: spirit level with MPU6050 and OLEDTwo parts on one I²C busDrag the sensor
ESP32 in Python: MPU6050readfrom_mem, struct.unpackDrag the sensor
DIP switch as a binary numberINPUT_PULLUP, building bits, Serial.println(x, BIN)Toggle the sliders
PIR motion sensorAn edge on an input, millisClick the sensor
NTC thermometeranalogRead, log, beta formulaDrag the sensor
ESP32: NTC thermometer12 bits, powered from 3.3 VDrag the sensor
ESP32 in Python: NTC thermometerADC, math.logDrag the sensor
ESP32 in Python: PIR motion sensorPin.irq on both edgesClick the sensor
Slide potentiometer and slide switchChangeover switch without pull-up, analogWriteDrag the knob, click the switch
Gas alarm with MQ-2Analog value and threshold output, tone()Drag the sensor, click it for the threshold
Scale with HX711 and load cellHX711 library, tare(), set_scale()Drag the load cell
ESP32: scale with HX711The same library at 3.3 V, is_ready()Drag the load cell
ESP32 in Python: scale with HX711The protocol by hand, 24 bits and one more pulseDrag the load cell
Stepper motor 28BYJ-48 with ULN2003Stepper library, pin order IN1, IN3, IN2, IN4Just start it
Air pressure and altitude with a BMP180Adafruit_BMP085.h, pressure in hPa, altitude from air pressureDrag the sensor, change the pressure in the inspector
Stepper motor with A4988 driverSTEP and DIR, 200 full steps per turn, bench supply at VMOTJust start it
Two DC motors with L298NDirection via IN1 and IN2, speed with PWM at ENA, ENB on through the jumperJust start it
ESP32 in Python: stepper in half stepsEight patterns per cycle, motor on VINJust start it
Rotary encoderWatch for the edge on CLK, direction from DTTurn it, watch the monitor
Rotary encoder with interruptattachInterrupt, volatileTurn quickly: No step is lost despite delay(500)
ESP32: rotary encoder with OLEDInterrupt with IRAM_ATTR, bar on the OLEDTurn it, press the knob
ESP32 in Python: rotary encoderPin.irqTurn it, press the knob
Analog joystickanalogRead, map, INPUT_PULLUPDrag the knob, watch the monitor
Joystick: draw on the LED matrixThresholds on two axes, setLedSteer, press the knob to clear
ESP32: analog joystick12 bits, powered from 3.3 VDrag the knob
ESP32 in Python: analog joystickADC and Pin.PULL_UPDrag the knob
Membrane keypadKeypad.h, getKeyPress keys, watch the monitor
Keypad: PIN codeString collects the inputType 1234 and #
ESP32: membrane keypadKeypad.h on the ESP32Press keys
ESP32 in Python: membrane keypadScanning the matrix by handPress keys
MP3 player with DFPlayer MiniSoftwareSerial, DFRobotDFPlayerMiniListen, press the button for the next track
ESP32: MP3 player on Serial2Serial2 on GPIO16/17, finished tracksListen
ESP32 in Python: MP3 playermachine.UART and dfplayerListen
Pico: MP3 player with DFPlayer MiniUART1 on GP4/GP5, BUSYListen, press the button
GPS position and distance travelledTinyGPS++ on SoftwareSerial, distanceBetweenChange speed and course in the inspector
ESP32: GPS on Serial2TinyGPS++, date, altitude, HDOPSet the satellites to 0
Pico: GPS with micropyGPSmicropyGPS on UART1Watch the position move
RFID access controlMFRC522.h, comparing the UIDClick the key fob, then a card
RFID music box with DFPlayerRC522 and DFPlayer together, like the TonUINOClick a card
ESP32: read RFID cardsVSPI, PICC_GetTypeNameClick a card
Pico: RFID visit counter on the cardmfrc522, writing a blockLay a card on, take it away, lay it on again
ESP32 in Python: RFID visit countermfrc522 on VSPILay a card on several times
Pico: motor speed and direction with a potPWM at ENA, ADC, dead zone in the middleDrag the pot
Assembler: blink an LEDsbi and cbi on PORTB, a counting loop as delay, start and loopJust start it. Set a breakpoint on cbi
Assembler: button switches an LEDPull-up through PORTD, sbic on PINDPress the button
Assembler: timer interruptTimer 1 in CTC mode, TIMER1_COMPA_vect, retiJust start it
Assembler: dimmer with ADC and PWMlds and sts, ADC and fast PWM with Timer 1Drag the pot
Assembler: text over the serial portUSART registers, text in flash with .asciz and lpmOpen the monitor
ATtiny85 in assembler: blink an LEDsbi PINB toggles, 8 MHz, rcall instead of callJust start it

Language

This section describes the interpreter. With real AVR code, full Arduino C++ applies. As on the board, sketches need setup() and loop(). Data types behave as they do on the Uno: int has 16 bits, 5 / 2 gives 2, and 1000 * 60 overflows. Write 1000L * 60 if the result does not fit in 16 bits.

What the language covers

Built-in functions

AreaFunctions
PinspinMode, digitalWrite, digitalRead, analogRead, analogWrite
Timedelay, delayMicroseconds, millis, micros
Soundtone, noTone, with TimerFreeTone.h also TimerFreeTone(pin, frequency, duration, volume). It blocks like delay() and uses no timer. As in the library, the volume 1 to 10 is the duty cycle (10 = 50 %), so an LED on the pin also gets dimmer. For real code the library has to be installed by hand, the Arduino IDE library manager does not have it.
ShiftingshiftOut, shiftIn
Mathmap, constrain, min, max, abs, sq, pow, sqrt, sin, cos, tan, floor, ceil, round, random
BitsbitRead, bit, lowByte, highByte
Serialbegin, print, println, write, available, read, peek, readString, readStringUntil, parseInt, parseFloat
Stringlength, charAt, indexOf, substring, toInt, toFloat, equals, startsWith, endsWith, trim, toUpperCase, toLowerCase
Formatting textsprintf(buf, format, …), snprintf(buf, sizeof(buf), format, …) and dtostrf(value, width, digits, buf) write into a char array, for example sprintf(buf, "%02d:%02d", hours, minutes) for "07:09". As on the board, sprintf cannot do %f on the Uno and the ATtiny, a ? appears there, and int has 16 bits: long needs %ld in the format text. If placeholders and values don't match or the buffer is too small, the app reports it instead of overwriting other variables like the board would.
LiquidCrystalSee LCD 16×2
LiquidCrystal_I2CPlus init, backlight, noBacklight
LedControlSee LED matrix
TM1637DisplaySee TM1637
IrReceiver, IRrecvSee IR receiver
Wirebegin, beginTransmission, write, endTransmission, requestFrom, available, read, peek
Servoattach, detach, write, read, writeMicroseconds

Warnings and errors

All messages appear in the serial monitor. Clicking an error with a line number takes you to that place in the code. The rows about analogWrite, Serial, array index and division apply only to the interpreter.

Message aboutMeaningFix
LED with too much currentMore than 30 mA flow through the LED.Add a series resistor, for example 220 Ω.
Pin with too much currentA pin supplies more than 40 mA.Reduce the load or add a resistor.
Short circuitThe supply is connected directly to GND.Check the wires at 5V and GND.
Power supplyMinus not on GND, voltage at VIN outside the limits, too much current, current into the battery.See External power supply.
7805Below 7 V or above 35 V at the input, above 1.5 A, too hot without a heat sink.See External power supply.
Voltage at a pin or ICMore than the board voltage or less than −0.5 V at a pin, too much voltage at an IC.Use a voltage divider, level shifter or matching supply, check the polarity.
Floating pinAn input is connected to nothing and reads random values.Use INPUT_PULLUP or a resistor to GND or 5 V.
analogWrite without PWMThe pin can only switch on and off.Use D3, D5, D6, D9, D10 or D11.
Serial without beginThe output does not arrive.Call Serial.begin(9600) in setup().
IC without power, open inputThe IC lacks VCC or GND, or an input is floating.Connect the pins as described under CD4017, 74HC595, 74HC165 and Logic gates.
I²C address not answeringWrong address, no power or wrong wires.Check the address, connect SDA to A4 and SCL to A5.
Servo without powerThe signal arrives, but the supply is missing.Connect the servo to 5 V and GND.
Array indexThe access is outside the array. The sketch stops.Check the index. A real board would silently overwrite other memory.
Division by 0, full stackThe sketch stops with a message.Check the divisor or the recursion depth.

Real AVR code and interpreter

Schaltwerk runs sketches in two ways. The one in use is shown at the right above the editor. Click it to switch when both are available. The Android app has no compiler and always uses the interpreter. The app assembles programs in assembler itself: they run everywhere as machine code on the emulated chip, in the apps as well.

Real AVR codeInterpreter
How it worksavr-gcc compiles the sketch, and an emulated ATmega328 runs it.The app runs the sketch itself.
Needsnpm start and arduino-cli with the arduino:avr core, for example from the Arduino IDE.Nothing, it runs anywhere.
LanguageFull Arduino C++ with pointers, classes, interrupts and registers.The subset under Language.
TimingCycle-accurate at 16 MHz.Approximate.
ErrorsCompiler messages. Runtime errors go unnoticed, as on the board.Friendly messages, and array errors and division by 0 stop the sketch.
Current line in the editorYes, from the compiler's debug data.Yes.

If arduino-cli is available, real AVR code is used. The circuit calculation is the same in both cases, so warnings about current and short circuits always appear. The first start can take a minute because the Arduino core gets compiled.

Libraries come from your Arduino installation. Servo.h is not part of every installation. If it is missing, install it in the Arduino IDE under Tools > Manage Libraries. A library also compiles without a matching part, but nothing will be visible: Many modules are not in the app yet.

Debugger

The debugger pauses the sketch so you can follow what happens line by line. Simulated time also stands still while paused. The circuit stays usable: press a button while paused and click Continue, and the sketch sees the press.

When paused, the lower area switches to the Debug tab. It shows the pins with mode and voltage and, depending on how the sketch runs, more details:

Real AVR codeInterpreter
VariablesNot by name yet, but registers, SREG and memory.Local and global variables with value and type.
Call stackApproximate, worked out from the stack.Exact.

With real AVR code, the mapping from machine code to lines comes from the compiler, which optimizes the sketch. Steps therefore sometimes jump, and a function can be inlined into its caller. In that case, Step out runs on to the next breakpoint. A line with no code of its own, such as a variable optimized away, pauses at the next line with code.

Raspberry Pi Pico with Python or C

Beside the Uno there is the Raspberry Pi Pico. A project has exactly one board. On the Uno you program in C. On the Pico you choose the language in the project menu with New: Pico (Python) or New: Pico (C). The examples have their own groups.

With Python the real MicroPython 1.29 firmware runs on an emulated RP2040. This also works without npm start, because no compiler is needed. Error messages come from MicroPython itself. The app jumps to the line they name.

With C real ARM code from the compiler runs. This needs npm start, arduino-cli and Earle Philhower's rp2040:rp2040 core. The first compile can take a few minutes. Pin numbers are the GP numbers, LED_BUILTIN is GP25, and A0 to A2 are GP26 to GP28. The debugger works as on the Uno, with registers r0 to r12 and memory from 0x20000000.

from machine import Pin
import time

led = Pin("LED", Pin.OUT)

while True:
    led.toggle()
    time.sleep(0.5)
WhatPython
VoltageThe pins work at 3.3 V. An LED is therefore dimmer than on the Uno, and a blue LED barely lights. The app warns when a pin sees more than 3.6 V.
CurrentA pin supplies 12 mA. The app warns above that.
Supply3V3 supplies 3.3 V, VBUS and VSYS supply 5 V, for example for a servo.
LED on the boardPin("LED", Pin.OUT) or GP25
AnalogADC(26) to ADC(28) on GP26 to GP28. read_u16() returns 0 to 65535. ADC(4) is the temperature sensor and always reports about 27 °C.
PWMPWM(Pin(n)) on any GP pin
I²CI2C(0, sda=Pin(4), scl=Pin(5)) or SoftI2C. Your program chooses the pins, the app checks that the module is connected to them.
Monitorprint() writes to it, input() reads the line you send there.

This has limits:

ESP32 as a profile

The ESP32 DevKit board (V1 with 30 pins) is a profile: pins, voltages and rules match the ESP32, but no ESP32 code runs, because there is no free emulator for it. You use it to test the circuit and the program logic. The project menu offers New: ESP32 (C) and New: ESP32 (Python). Both run without npm start.

The profile has limits:

ATtiny85

The ATtiny85 is the chip itself here, in a DIP-8 package: 8 KB flash, 512 bytes RAM, 8 MHz, and only five freely usable pins. The project menu offers New: ATtiny85 (C). VCC supplies a fixed 5 V here, in a real circuit you have to power the chip yourself.

Under npm start with arduino-cli and the ATTinyCore:avr core, real code runs on the emulated chip, with the debugger. Without them, and always in the Android app, the interpreter runs. The interface switches as on the Uno.

WhatOn the ATtiny85
PinsIn code the numbers 0 to 5 for PB0 to PB5. PB5 is the reset pin, and the app warns if it is wired.
PWMPB0, PB1 and PB4
AnalogA0 to A3 are PB5, PB2, PB4 and PB3. Careful: analogRead(3) means the channel, digitalRead(3) means pin PB3.
I²CPB0 is SDA, PB2 is SCL. Wire.h belongs to the core and uses the USI unit. Older sketches with TinyWireM.h run as well, see below.
MonitorSerial.print() appears in the monitor.

This has limits:

ATtiny84

The ATtiny84 in a DIP-14 package has eleven freely usable pins, eight of them analog, otherwise the same 8 KB flash, 512 bytes RAM and 8 MHz. The project menu offers New: ATtiny84 (C). The pin numbers are those of ATTinyCore, clockwise (in the Arduino IDE Pin Mapping: Clockwise, the default); the drawing shows each pin's number next to it.

WhatOn the ATtiny84
Pins0 to 7 are PA0 to PA7, 8 is PB2, 9 PB1, 10 PB0, 11 PB3 (reset). LED_BUILTIN is 8.
PWM5, 6, 7 and 8 (PA5, PA6, PA7, PB2). Timer 1 has 16 bits here, PWM is right in both duty cycle and frequency.
AnalogA0 to A7 on PA0 to PA7, that is pins 0 to 7.
I²C6 (PA6) is SDA, 4 (PA4) is SCL, over the USI unit, with Wire.h or TinyWireM.h.
InterruptattachInterrupt(digitalPinToInterrupt(8), …) on PB2.
MonitorSerial.print() appears in the monitor. On a real chip, Serial sends on PA1 (pin 1), so A1 is then no use as an analog input.

Smaller variants

The ATtiny25 and 45 are electrically an ATtiny85, the ATtiny24 and 44 an ATtiny84; they only have less memory: the 45 and 44 4 KB flash and 256 bytes RAM, the 25 and 24 2 KB and 128 bytes. Pick the variant under Type in the chip's panel. Real code is then compiled for it and has to fit its flash; the interpreter does not check the memory.

Assembler

The Uno and the ATtiny can also be programmed entirely in AVR assembler. The project menu offers New: Uno (Assembler), New: ATtiny85 (Assembler) and New: ATtiny84 (Assembler), and the examples have their own groups. The app assembles the program itself and runs the machine code on the emulated chip, cycle accurate at 16 MHz on the Uno and 8 MHz on the ATtiny. This needs neither npm start nor arduino-cli: it works in the browser, in the artifact and in the apps, offline too. There is no assembler for the Pico and the ESP32.

The syntax is that of GNU as, the one used by .S files in the Arduino IDE and in avr-gcc. The bytes produced are the same as there; the tests compare them with avr-gcc.

How a program runs

A program consists of the assembler file only. The app's startup code sets up the vector table, points the stack pointer to RAMEND, clears r1, copies .data to RAM, clears .bss and then calls your program:

LabelEffect
start (or setup)Called once, ends with ret.
loopCalled again and again after that, ends with ret.
mainCalled once instead of start and loop. If it returns, the program stops.
TIMER1_COMPA_vect and the other vector namesThe label is the interrupt routine and ends with reti.
none of theseThe program begins with the first line at address 0, without startup code and vector table. The stack pointer is at RAMEND as in the chip. This also applies when instructions come before loop and there is no start.

There is no Arduino core. Serial, delay(), millis() and pinMode() do not exist, the program works with the registers only. A delay is a counting loop or a timer, serial output writes the USART registers itself; the examples show both. The mix of .ino and .S shown in many tutorials does not work either: what setup() and loop() call from C there, you call yourself in start and loop, and you put parameters into the register first, for example ldi r24, 1 before rcall led.

Registers

The names from avr/io.h apply to the selected chip: registers such as PORTB, TCCR1B and UDR0, bits such as PB5, CS12 and ADSC, plus RAMEND and the vector names. #include "avr/io.h" may be there, but is not needed. As in avr-gcc, the names are memory addresses unless told otherwise. For in, out, sbi, cbi, sbic and sbis you therefore put #define __SFR_OFFSET 0 at the top or write _SFR_IO_ADDR(PORTB) in the instruction. Registers from address 0x60 on, on the Uno for example timers 1 and 2, the ADC and the USART, are only reached by lds and sts. The error message says which one fits.

What works

AreaSupported
InstructionsAll instructions of the chip in question. The ATtiny has no call, jmp and mul.
LabelsNames with a colon, plus local numeric labels: 1:, reached with 1b (backward) and 1f (forward).
Numbers and expressionsDecimal, 0x1F, 0b1010, 'A'; + - * / % << >> & | ^ ~, comparisons, parentheses; . for the current address; lo8(), hi8(), hh8(), pm_lo8(), pm_hi8(), pm(), _BV(). Precedence is that of GNU as, not that of C: use parentheses, as in (1 << CS12) | (1 << WGM12).
Data.byte, .word, .long, .ascii, .asciz, .string, .fill, .skip, .space, .zero, .align, .balign, .org. After data of odd length inside the program comes .balign 2.
Sections.text, .data, .section .bss, .lcomm, .comm.
Names and macros.equ, .set, name = value, #define without parameters (for registers too: #define temp r16), .macro with .endm, #if, #ifdef, #ifndef, #else, #endif.
Comments;, // and /* */.
No effect.global, .extern, .type, .size and similar information for the linker.

What does not work

The debugger works as with real AVR code: breakpoints sit on lines with an instruction, a step is one line, Step into follows rcall and call. The Debug tab shows the registers r0 to r31, SREG, the stack pointer and memory, and the call stack names the labels.

Programming in assembler

This chapter is a short reference to get started: the chip as the program sees it, the instructions and typical patterns. How programs run in the app is described under Assembler. The code blocks can be copied into an assembler project for the Uno and followed line by line in the debugger.

The chip as the program sees it

Registers r0 to r31The 32 working registers, 8 bits each. Instructions with a fixed value (ldi, cpi, subi, andi, ori) only work with r16 to r31. The app's startup code sets r1 to 0.
Pointers X, Y, ZThe pairs r27:r26, r29:r28 and r31:r30 as 16-bit addresses. The halves are called XL, XH and so on.
Status register SREGEight flags that almost every arithmetic instruction sets: Z result is 0, C carry, N negative, V signed overflow, S less than (signed), H carry out of bit 3, T a free marker bit, I interrupts enabled. The conditional jumps test them.
Stack and SPThe stack grows downwards from the end of RAM. rcall, push and interrupts put things on it, ret, pop and reti take them off.
Program memory (flash)The program and fixed data. Instructions are 2 bytes long, jmp, call, lds and sts 4.
RAMVariables and stack: 0x0100 to 0x08FF on the Uno, 0x0060 to 0x025F on the ATtiny85.
I/O registersPorts, timers, ADC and the other peripherals. in and out reach the first 64, sbi, cbi, sbis and sbic the first 32, lds and sts all the others. See Registers.

Instructions

In the tables Rd and Rr stand for r0 to r31, Rh for r16 to r31, K for a value, A for an I/O register, b for a bit 0 to 7 and k for a label. The result always ends up in the first register. Instructions may be written in upper or lower case.

Loading and copyingEffect
ldi Rh, KLoad a value 0 to 255 into a register, r16 to r31 only
mov Rd, RrCopy a register
movw Rd, RrCopy a register pair, for example movw r24, r26
clr Rd / ser RhSet a register to 0 / to 255
lds Rd, k / sts k, RrRead a byte from RAM or from a register at 0x60 and above / write it there
ld Rd, X / st X, RrRead / write through a pointer. Also Y, Z; X+ counts on afterwards, -X steps back first
ldd Rd, Y+q / std Y+q, RrThrough Y or Z with a fixed offset 0 to 63
lpm Rd, Z / lpm Rd, Z+Read a byte from program memory, Z points to it
in Rd, A / out A, RrRead / write an I/O register
push Rr / pop RdPut a register on the stack / take it back
ArithmeticEffect
add Rd, Rr / adc Rd, RrAdd / add with carry (for the upper byte)
sub Rd, Rr / sbc Rd, RrSubtract / subtract with carry
subi Rh, K / sbci Rh, KSubtract a value / with carry. There is no addi: subi r16, -5 adds 5
adiw Rd, K / sbiw Rd, KAdd / subtract 0 to 63 on a register pair, only r24, X, Y, Z
inc Rd / dec RdIncrease / decrease by 1. The carry flag stays
neg Rd / com RdChange the sign / invert all bits
mul Rd, RrMultiply, result in r1:r0. Also muls, mulsu, fmul. ATmega only; follow with clr r1
Logic and bitsEffect
and Rd, Rr / andi Rh, KBitwise AND: clears the bits that are 0 in the mask
or Rd, Rr / ori Rh, KBitwise OR: sets bits
eor Rd, RrExclusive OR: toggles bits
sbr Rh, K / cbr Rh, KSet / clear the bits of the mask
sbi A, b / cbi A, bSet / clear one bit in an I/O register, addresses 0 to 31 only
lsl Rd / lsr RdShift left / right, that is times 2 / divided by 2. The bit that falls out goes to carry
rol Rd / ror RdShift and take the carry in (for several bytes)
asr RdShift right, the sign stays
swap RdSwap the upper and lower four bits
bst Rr, b / bld Rd, bCopy one bit into the T flag / from there into a register
sec, clc, sei, cli, set, clt …Set (se…) or clear (cl…) a flag: C, Z, N, V, S, H, T, I
Comparing and jumpingEffect
cp Rd, Rr / cpi Rh, KCompare: computes Rd minus the value and only sets the flags
cpc Rd, RrCompare with carry, for the upper byte
tst RdTest for 0 or negative
breq k / brne k …Jump if the condition holds, at most 64 instructions away. See the table below
rjmp k / jmp kAlways jump. jmp only on the ATmega, rjmp reaches 2048 instructions
sbrs Rr, b / sbrc Rr, bSkip the next instruction if the bit in the register is 1 / 0
sbis A, b / sbic A, bThe same for a bit in an I/O register, for example an input
cpse Rd, RrSkip the next instruction if both are equal
ijmpJump to the address in Z
Subroutines and the restEffect
rcall k / call kCall a subroutine: the return address goes on the stack. call only on the ATmega
icallCall the subroutine Z points to
ret / retiReturn to the caller / return from an interrupt routine, interrupts allowed again
nopDo nothing for one clock cycle
sleep / wdr / breakSleep until the next interrupt / reset the watchdog / breakpoint for hardware debuggers

Conditional jumps

A conditional jump tests the flags of the last arithmetic or compare instruction. After cp r16, r17 or cpi r16, 10 they mean:

JumpJumps if
breq / brneequal / not equal (Z)
brlo / brshlower / same or higher, unsigned (C). The same as brcs / brcc
brlt / brgeless / greater or equal, signed (S)
brmi / brplresult negative / not negative (N)
brcs / brcccarry set / clear (C)
brvs / brvcsigned overflow / none (V)
brts / brtcT flag set / clear
brie / bridinterrupts enabled / disabled (I)

If the target is more than 64 instructions away, use the opposite condition and jump with rjmp: instead of breq far write brne 1f, rjmp far, 1:.

Patterns

Switching and reading pins. Each port has three registers: DDRx sets the direction per bit (1 is output), PORTx the level or, for an input, the pull-up, and PINx reads the pin. On the Uno D0 to D7 are port D, D8 to D13 port B bits 0 to 5, A0 to A5 port C.

#define __SFR_OFFSET 0
#include "avr/io.h"

start:
  sbi DDRB, 5          ; D13 as output
  cbi DDRD, 2          ; D2 as input
  sbi PORTD, 2         ; with pull-up
  ret

loop:
  sbis PIND, 2         ; skip the next instruction while D2 is HIGH
  sbi PORTB, 5         ; D2 is LOW: LED on
  sbic PIND, 2         ; skip the next instruction while D2 is LOW
  cbi PORTB, 5         ; D2 is HIGH: LED off
  ret

Counting and 16 bits. A loop counts a register down, and brne jumps back as long as it is not 0. Values above 255 need two registers: lo8() and hi8() split them, sbiw counts a pair in one instruction, otherwise the lower byte uses add or sub and the upper one adc or sbc.

main:
  ldi r16, 10          ; ten rounds
again:
  inc r20
  dec r16
  brne again           ; until r16 is 0

  ldi r24, lo8(1000)   ; 1000 does not fit in one register
  ldi r25, hi8(1000)
count:
  sbiw r24, 1          ; r25:r24 minus 1
  brne count

  ldi r18, lo8(300)    ; r19:r18 = 300 + 500
  ldi r19, hi8(300)
  ldi r16, lo8(500)
  ldi r17, hi8(500)
  add r18, r16         ; lower bytes
  adc r19, r17         ; upper bytes plus the carry
  ret

Waiting. Without delay() a counting loop burns the time. dec takes one clock cycle and brne two while it jumps: the innermost loop below needs three cycles per round, so 256 rounds take 48 µs at 16 MHz. Nested, that gives milliseconds up to seconds. A timer is more exact and does not block the processor, see the example Assembler: timer interrupt.

; Waits r24 milliseconds at 16 MHz (16000 clock cycles each).
wait_ms:
  ldi r25, 21          ; 21 x 256 x 3 cycles are about 1 ms
1:
  dec r18              ; r18 runs through all 256 values
  brne 1b
  dec r25
  brne 1b
  dec r24
  brne wait_ms
  ret

main:
  ldi r24, 250
  rcall wait_ms        ; a quarter of a second
  ret

Subroutines and the stack. rcall puts the return address on the stack and ret takes it back. Values are passed in registers; as in avr-gcc, r24 is common for the first value and the result. A subroutine that needs more registers saves them with push and restores them in reverse order with pop. Every push needs its pop, otherwise ret jumps to a wrong address.

main:
  ldi r24, 7
  rcall times10        ; r24 = 70
  ret

; r24 = r24 x 10, all other registers stay as they were
times10:
  push r16
  mov r16, r24
  lsl r24              ; x 2
  lsl r24              ; x 4
  add r24, r16         ; x 5
  lsl r24              ; x 10
  pop r16
  ret

Data in flash and in RAM. Fixed data such as texts and tables sit in flash behind the program and are read through Z with lpm. Variables live in RAM: .section .bss reserves space that is 0 at start, .data sets initial values. They are read and written with lds and sts or through a pointer.

.section .bss
total:  .skip 1          ; one byte, 0 at start
buffer: .skip 4

.data
step:   .byte 3          ; starts as 3

.text
main:
  ldi ZL, lo8(table)     ; Z points into flash
  ldi ZH, hi8(table)
  ldi XL, lo8(buffer)    ; X points into RAM
  ldi XH, hi8(buffer)
  ldi r16, 4
copy:
  lpm r0, Z+             ; read from the table
  st X+, r0              ; store in the buffer
  lds r17, total
  add r17, r0
  sts total, r17         ; total = 1 + 2 + 4 + 8
  dec r16
  brne copy
  ret

table:
  .byte 1, 2, 4, 8

Interrupts. A label with the name of the vector is the interrupt routine. It ends with reti and must leave everything as it found it, including the status register, because it interrupts the main program anywhere, for example between cpi and breq. Interrupts are enabled with sei, plus the enable bit of the source in question.

#define __SFR_OFFSET 0
#include "avr/io.h"

.section .bss
presses: .skip 1

.text
start:
  sbi PORTD, 2                 ; D2 is INT0, with pull-up
  ldi r16, 1 << ISC01          ; interrupt on the falling edge
  sts EICRA, r16
  sbi EIMSK, INT0              ; enable INT0
  sei                          ; enable interrupts in general
  ret

loop:
  ret

INT0_vect:
  push r16
  in r16, SREG                 ; save the flags
  push r16
  lds r16, presses
  inc r16
  sts presses, r16
  pop r16
  out SREG, r16                ; restore the flags
  pop r16
  reti

Limits

In the interpreter, timings are approximate and register access is not possible.