ArduinoArduino UnoExact chip

555 timer blinker

A 555 blinks an LED by itself, about 7 times a second; the Uno counts its pulses and prints the frequency. Change R2 or C1 and watch it follow.

555 timer blinker in Argynix Lab

The code

sketch.inoC++
// A 555 timer blinking an LED by itself: no code drives it. R1 1 kΩ, R2 10 kΩ and C1
// 10 µF set it to about 6.9 times a second: f = 1.44 / ((R1 + 2 × R2) × C1).
// The Uno only listens: it counts the 555's pulses on pin 2 and prints the frequency.
// Click R2 or C1 and change its value: the LED and the count follow.

const byte PULSE_PIN = 2;
int last = LOW;
unsigned long rises = 0;
unsigned long since = 0;

void setup() {
  Serial.begin(115200);
  pinMode(PULSE_PIN, INPUT);
  since = millis();
}

void loop() {
  int now = digitalRead(PULSE_PIN);
  if (now == HIGH && last == LOW) rises++;
  last = now;
  if (millis() - since >= 1000) {
    Serial.print("The 555 runs at ");
    Serial.print(rises);
    Serial.println(" Hz");
    rises = 0;
    since += 1000;
  }
}