[Waterproof DS18B20 Sensor Kit Tutorial_2] a BATHING CAT FOR YOUR BATHING
by Juncheng in Living > Life Hacks
436 Views, 0 Favorites, 0 Comments
[Waterproof DS18B20 Sensor Kit Tutorial_2] a BATHING CAT FOR YOUR BATHING
I have to admit that taking a bath can greatly help relax. And I prefer hot tubbing, no matter it’s summer or winter season. But that can be annoying when you can not estimate whether the temperature is proper. What's more, I bag most of us need a timer when you enjoy yourselves in the tub.So I decided to deal with such a BATHING COMPANION.The anime character is from RIPNDIP one of my favorite brands.
Material List
# LR44 cell battery(with a case) [for independent power supply]
some PMMA, and some wire
Circuit Logic & Code
#include <OneWire.h>
#include <RGBLED.h>
RGBLED myled = RGBLED(9,10,11);
int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2
//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 2
int ledPin = 9; // Connect LED on pin 9, or use the onboard one
int KEY = 3; // Connect Touch sensor on Digital Pin 3
void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // Set ledPin to output mode
pinMode(12, OUTPUT);
pinMode(KEY, INPUT); //Set touch sensor pin to input mode
}
void loop(){
float temperature = getTemp();
Serial.println(temperature);
delay(100); //just here to slow down the output so it is easier to read
if(temperature >= 40) { //Read Touch sensor signal
digitalWrite(12, LOW);
digitalWrite(ledPin, HIGH); // if Touch sensor is HIGH, then turn on
}
else if(digitalRead(KEY)==HIGH){ //start the timer
delay(1800000);
digitalWrite(12, LOW);
digitalWrite(10, HIGH);
delay(60000);
}
else{
digitalWrite(ledPin, LOW); // if Touch sensor is LOW, then turn off the led
}
}
float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
ds.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;
return TemperatureSum;
}
Structure
I wanted to make it as simple as possible, so I did some laser-cutting stuff.
And then screw on.