Projects / Cricket thermometer

Cricket thermometer

Beginner1.7 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANO

    Wire the sensor

    DQ to D4 with 4.7 kilohm to 5V, power and ground.

  2. NANO

    Wire the button

    D2 to GND.

  3. NANO

    Wire the display

    SDA to A4, SCL to A5.

  4. NANO15.3 mASSD1306

    Install the libraries

    OneWire, DallasTemperature, SSD1306 and GFX.

  5. NANO

    Upload the sketch

    A prompt appears.

  6. NANO

    Tap once per chirp

    The first tap starts the 14 second window.

  7. NANO

    Read the result

    Dolbear, sensor and difference.

  8. NANO

    Try again

    Tap to start a new count.

In short

How do you build a cricket thermometer?

Count chirps for fourteen seconds, add forty, and Dolbear's law gives the temperature in Fahrenheit. The sketch checks it against a real sensor. You need Arduino Nano, DS18B20 waterproof probe, Resistor 4.7 kΩ, SSD1306 OLED Display, Tactile push button 6 mm, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points. It takes 8 steps and about 100 minutes.

Level
Beginner
Time
About 100 min
Parts
7

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
DS18B20 pin 1 (GND)Nano GNDFlat face toward you, legs down, pin 1 on the left
DS18B20 pin 2 (DQ)Nano D4One-wire data
DS18B20 pin 3 (VDD)Nano 5VSensor power
4.7 kilohm resistorBetween D4 and 5VPull-up for the one-wire line
Chirp tap buttonNano D2 and GNDTap once per chirp
OLED SDANano A4I2C data
OLED SCLNano A5I2C clock
OLED VCC and GNDNano 5V and GNDPower (check your OLED accepts 5 V)

Code

In 1897 the physicist Amos Dolbear noticed that the snowy tree cricket chirps faster as the air gets warmer, and he gave a rule of thumb: count the chirps in fourteen seconds, add forty, and the answer is the temperature in degrees Fahrenheit. It works best for that one species on warm evenings, so treat it as a fun test rather than a measurement. The sketch times the fourteen seconds for you: the first tap of the button starts the clock and counts as the first chirp, and each later tap adds one. When the time is up, it calculates the Dolbear temperature, converts it to Celsius, reads a DS18B20 temperature sensor, and shows both numbers with the difference. A 4.7 kilohm resistor holds the one-wire data line high between messages. Try it with real crickets outdoors on a quiet evening, or practise on a recording. Keep the electronics dry and away from the garden. Note how big the difference is at different temperatures, and decide how well the old rule holds up against modern sensors.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

OneWire oneWire(4);
DallasTemperature sensors(&oneWire);
Adafruit_SSD1306 oled(128, 64, &Wire, -1);

const int BTN = 2;
const unsigned long WINDOW_MS = 14000UL;         // count chirps for 14 seconds

enum State { WAITING, COUNTING, SHOWING };
State state = WAITING;
int chirps = 0;
unsigned long windowStart = 0, lastPress = 0;
bool wasPressed = false;
float dolbearC = 0, sensorC = 0;

void draw(const char *top, const char *l1, const char *l2, const char *l3) {
  oled.clearDisplay();
  oled.setTextColor(SSD1306_WHITE);
  oled.setTextSize(1);
  oled.setCursor(0, 0);  oled.print(top);
  oled.setCursor(0, 16); oled.print(l1);
  oled.setCursor(0, 30); oled.print(l2);
  oled.setCursor(0, 44); oled.print(l3);
  oled.display();
}

void setup() {
  pinMode(BTN, INPUT_PULLUP);
  sensors.begin();
  Serial.begin(9600);
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) {} }
  draw("Cricket thermometer", "Tap the button for", "each chirp. The first", "tap starts 14 seconds.");
}

void loop() {
  bool pressed = (digitalRead(BTN) == LOW);
  bool edge = pressed && !wasPressed && millis() - lastPress > 40;
  wasPressed = pressed;
  if (edge) lastPress = millis();

  char a[24], b[24], c[24];
  if (state == WAITING) {
    if (edge) { chirps = 1; windowStart = millis(); state = COUNTING; }
  } else if (state == COUNTING) {
    if (edge) chirps++;
    unsigned long left = WINDOW_MS - (millis() - windowStart);
    if (millis() - windowStart >= WINDOW_MS) {
      float dolbearF = 40.0 + chirps;                       // Dolbear's law with a 14 second count
      dolbearC = (dolbearF - 32.0) * 5.0 / 9.0;
      sensors.requestTemperatures();
      sensorC = sensors.getTempCByIndex(0);
      state = SHOWING;
      Serial.print("Chirps "); Serial.print(chirps);
      Serial.print("  Dolbear "); Serial.print(dolbearC, 1);
      Serial.print(" C  Sensor "); Serial.print(sensorC, 1); Serial.println(" C");
    } else {
      snprintf(a, sizeof(a), "Chirps: %d", chirps);
      snprintf(b, sizeof(b), "Time left: %lu s", left / 1000UL + 1);
      draw("Counting...", a, b, "");
    }
  } else {
    snprintf(a, sizeof(a), "Chirps in 14 s: %d", chirps);
    dtostrf(dolbearC, 4, 1, c);
    snprintf(b, sizeof(b), "Dolbear: %s C", c);
    char s[10], d[10];
    dtostrf(sensorC, 4, 1, s);
    dtostrf(dolbearC - sensorC, 4, 1, d);
    snprintf(c, sizeof(c), "Sensor %s  Diff %s", s, d);
    draw("Result (tap = again)", a, b, c);
    if (edge) { state = WAITING; draw("Cricket thermometer", "Tap the button for", "each chirp. The first", "tap starts 14 seconds."); }
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Power onPrompt to tap for each chirp
First tapCounting display with the time left
After 14 secondsChirp count, Dolbear temperature, sensor temperature
DifferenceUsually within a few degrees on a warm evening
Tap after the resultBack to the prompt

If it does not work

Sensor reads minus 127

Check the wiring and the 4.7 kilohm pull-up on D4.

Blank screen

Check A4 and A5 and the OLED address.

Result is far off

The rule works best for snowy tree crickets in warm weather.

Chirps counted twice

Increase the 40 millisecond lockout.

Display text cut off

Shorten the lines or use a smaller text size.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the cricket thermometer?

Arduino Nano, DS18B20 waterproof probe, Resistor 4.7 kΩ, SSD1306 OLED Display, Tactile push button 6 mm, Jumper wires male to male (40 pcs, 20 cm) and Breadboard 830 Tie Points.

How long does the cricket thermometer take to build?

About 100 minutes for a beginner maker, in 8 steps.

How do I know the cricket thermometer works?

Power on: Prompt to tap for each chirp. First tap: Counting display with the time left. After 14 seconds: Chirp count, Dolbear temperature, sensor temperature.

Sensor reads minus 127: what should I check?

Check the wiring and the 4.7 kilohm pull-up on D4.

Blank screen: what should I check?

Check A4 and A5 and the OLED address.

Result is far off: what should I check?

The rule works best for snowy tree crickets in warm weather.

Chirps counted twice: what should I check?

Increase the 40 millisecond lockout.