Built-in project · ATtiny85

ATtiny85 dimmer

A knob on PB2 dims an LED on PB0, out of an eight-pin chip in the breadboard. No board, no USB, just the chip and its two rails. The whole build, an ATtiny85 and 3 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

IntermediateRuns in your browser. Free, and no account needed.

ATtiny85 dimmer · ATtiny85live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · ATtiny85
// Knob dimmer: a potentiometer on PB2 (A1, package pin 7) sets the
// brightness of an LED on PB0 (pin 5).
//
// The pot's two ends go to VCC and GND and its wiper to PB2, so turning it
// sweeps the pin from 0 V to the supply. analogRead gives 0..1023 against VCC
// and analogWrite takes 0..255, so the reading is shifted down by two.
//
// PB0 is OC0A: timer 0's compare output, the same timer that counts
// milliseconds, at 488 Hz. The LED is dimmed by the hardware, not by the
// sketch, so the loop is free to do nothing for 20 ms between readings.

void setup()
{
    pinMode(0, OUTPUT);
}

void loop()
{
    int reading = analogRead(A1);

    analogWrite(0, reading >> 2);
    delay(20);
}

Parts list

6 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

5 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • 5 V: Potentiometer pin 3; ATtiny85 pin RESET; ATtiny85 pin VCC
  • Ground: Potentiometer pin 1; ATtiny85 pin GND; LED, amber pin C
  • Potentiometer pin 2; ATtiny85 pin PB2
  • ATtiny85 pin PB0; Resistor, 220 Ω pin 1
  • Resistor, 220 Ω pin 2; LED, amber pin A

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.