[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 favourite brands.
STEP 1 Design & Material Required
Material Required:
RGB LED module 5050
DFRduino Nano 3.0
# LR44 cell battery(with a case) [for independent power supply]
USB Cable
Waterproof DS18B20 Sensor Kit
some PMMA, and some wire
We need two functions :
I. A timer(cos I used to stay in bathroom for too long)
II. A temperature sensor(cos I never wanna to do any move like this
Solution :
I. I made a timer by Arduino IDE and use LED to hint you about time.
II. I take Waterproof DS18B20 Sensor as a “cat tail” to show if the temperature is proper.
And we need a holder to hold all these stuff.And it should be as simple as possible.
Here is a draft of the holder :
STEP 2 circuit logic & code
Code: Select all#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; }
STEP 3 Structure
I wanted to make it as simple as possible, so I did some laser-cutting stuff.
And then screw on
STEP 4 assembling
Hint: adjust the screw to make sure the case can hold ‘the cat tail’
Check it yourself!!!