Week 8: Input Devices

Testing Temperature Sensor

I kept this week focused on testing the temperature sensor I'll be using in my final project. I used the BOJACK DS18B20 Temperature Sensor, which was $9 on Amazon and can measure temperatures in water - perfect for my Smart Aquarium.

About the DS18B20

After reading through the datasheet, I learned some key features about this sensor:

Testing Process

I tested this using the PCB that I made for electronics/my final project. The sensor requires a pull-up resistor and can be powered by a 5V battery, making it perfect for initial testing.

Temperature Readings

Temperature readings from the sensor in the Serial Monitor

Code

Here's the simple test code I used:


#include 
#include 

// Data wire is connected to pin 2
#define ONE_WIRE_BUS 2

// Setup a oneWire instance
OneWire oneWire(ONE_WIRE_BUS);

// Pass oneWire reference to Dallas Temperature
DallasTemperature sensors(&oneWire);

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

void loop(void)
{ 
  sensors.requestTemperatures(); 
  
  Serial.print("Temperature is: ");
  Serial.println(sensors.getTempCByIndex(0));
  
  delay(1000);
}
    

Applications

The DS18B20 is particularly well-suited for aquarium use because:

Reflection

This simple test was crucial for my final project development. Key learnings:

← Back to main page