Skip to content

Instantly share code, notes, and snippets.

@chayanforyou
Created September 11, 2025 18:03
Show Gist options
  • Select an option

  • Save chayanforyou/11d2d5b7274636762b0023f71184246d to your computer and use it in GitHub Desktop.

Select an option

Save chayanforyou/11d2d5b7274636762b0023f71184246d to your computer and use it in GitHub Desktop.
DS18B20 Proteus Simulation Fix

DS18B20 Proteus Simulation Fix

Overview

This project provides a solution to fix the DS18B20 temperature sensor simulation issue in Proteus, where incorrect readings (e.g., -127.00°C) were observed despite the code and circuit working on real hardware.

Problem

The DS18B20 sensor in Proteus simulation returned alternating readings of -127.00°C (indicating a communication failure) and 27.00°C (likely the default simulated temperature). This issue is simulation-specific and does not occur on real hardware due to timing mismatches in the OneWire protocol.

Solution

The fix involves adjusting the DS18B20 component properties in Proteus to align with the OneWire timing requirements. Follow these steps:

  1. Edit DS18B20 Properties:

    • Right-click the DS18B20 sensor in the Proteus schematic.
    • Select "Edit Properties."
    • Update the following timing parameters:
      • Data Pulse Delay High: 40µs
      • Data Pulse Delay Low: 140µs
      • Time Reset Low: 400µs
      • Time Slot: 120µs
      • Conversion Time: 10ms
      • Data Write Time: 1ms
    • Save the changes.
  2. Verify Pull-Up Resistor:

    • Ensure the 4.7kΩ pull-up resistor is set to "Analog" mode (right-click, edit properties).
  3. Check Arduino Settings:

    • Confirm the Arduino clock is set to 16MHz (internal oscillator) in Proteus.
  4. Test the Simulation:

    • Rerun the simulation to verify stable temperature readings.

Customizing Simulated Temperature

  • To test different temperatures:
    1. In the DS18B20 properties, locate the "Temperature" field.
    2. Set the desired value (e.g., 25.0 for 25°C).
    3. Rerun the simulation to see the updated reading.

Code

The Arduino sketch used is a simple temperature reading implementation:

#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup(void) {
  Serial.begin(9600);
  Serial.println();
  sensors.begin();
}

void loop(void) {
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);
  Serial.print("Temperature : ");
  Serial.println(temp);
}

Additional Notes

  • If issues persist, consider testing in alternative simulators (e.g., Tinkercad or Wokwi) where DS18B20 support is more robust.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment