In this project, we'll use RGB LEDs, an environment sensor, and an Arduino Nano to send a message or make an alarm with colored lights. At the end of this project, you can:
- Read environment temperature from the DS18B20 sensor by Arduino.
- Control RGB LEDs by PWM.
- Make a cool smart mug.
The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line(and ground) for communication with a central microprocessor.In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply.Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control several DS18B20s distributed over a large area. Applications that can benefit from this feature include HVAC environmental controls, temperature monitoring systems inside buildings, equipment, or machinery, and process monitoring and control systems.
Regarding combining technology to life, using colored light is amazing and attractive. Replacing RGB LEDs with displays to send a message or alarm can make projects more beautiful and also more simple.In this project, we want to make a mug smart, so that you can show you the temperature of the coffee or soft drinks and alarm when it’s ready to drink. As thermopile, we’ll use DS18B20 and stick that on the bottom of the mug. It can send temperature of the liquid in the mug to the controller in a digital data. Arduino Nano is our choice as the controller because of its small size and mini USB connector on board. Therefore it can be programmed and the battery can be charged by USB port. To show the temperature, we use 2 simple 4-pin RGB LEDs and connect them to separate PWM units in Arduino Nano. Now, We only need a battery, a mug, and a plastic shell to put the component in. Let’s do it.
Required MaterialsAll of the component used in this project can be purchased by the provided link.
The battery size depends on the LEDs and the mug size. A 500mAh battery is a good choice. You can use either polymer or ion batteries. The LEDs used here have common cathodes. If yours have common anodes, you must make small changes in the code. If your LEDs cannot work without a resistor, you have two ways. Adding a resistor or adding more LEDs. You should connect both voltage and data pin of DS18b20 to a 4.7K ohm resistor. Although it may not be necessary.
CodeYou should copy the following code in the Arduino IDE. But first You must add the library and then upload the code. Download the “One Wire” and “Dallas” library from the attachment. If it is the first time you run an Arduino board, don’t worry. Just follow these steps:
- Go to www.arduino.cc/en/Main/Software and download the software of your OS. Install the IDE software as instructed.
- Run the Arduino IDE and clear the text editor and copy the following code in the text editor.
- Navigate to sketch and include the libraries (Download libraries from the following links). Now click add ZIP library and add the libraries
- Choose the board in tools and boards, select Arduino Nano.
- Connect the Arduino to your PC and set the COM port in tools and port.
- Press the Upload (Arrow sign) button.
/********************************************************************/
// First we include the libraries
#include "OneWire.h"
#include "DallasTemperature.h"
/********************************************************************/
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
/********************************************************************/
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
/********************************************************************/
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/********************************************************************/
float temp;
void setup(void)
{
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
}
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
/********************************************************************/
Serial.print(" Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperature readings
Serial.println("DONE");
/********************************************************************/
Serial.print("Temperature is: ");
Serial.print(sensors.getTempCByIndex(0));temp= sensors.getTempCByIndex(0); Serial.print(" "); Serial.println(temp);// Why "byIndex"?
// You can have more than one DS18B20 on the same bus.
// 0 refers to the first IC on the wire
if (analogRead(A0)>100)
{ if (temp>50)
temp=100;
if (temp<30) temp=0; temp=(12.5)*(temp-30); Serial.println(temp); if (temp>255)
temp=255;
if (temp<0)
temp=0;
analogWrite(6,temp);
analogWrite(9,temp);
analogWrite(3,255-temp);
analogWrite(11,255-temp);}
else
{analogWrite(6,0);
analogWrite(9,0);
analogWrite(3,0);
analogWrite(11,0);}
delay(100);
}
The following lines of code belong to the color calculation and it depends on your mug. If your mug does not transfer heat fast enough, you should change it to achieve desired results.
if (temp>50)
temp=100;
if (temp<30)
temp=0;
temp=(12.5)*(temp-30);
AssemblingInitially, you must drill the bottom of the mug. The number of holes depends on the circuit and how you implement it. We have considered 3 holes for this project. One for the thermometer and two for connecting screws (electrodes) with liquid inside the mug. You can do this project without piercing the mug. Tick the thermometer to the bottom of the mug and connect the 2 wires of the electrodes to an on/off switch.After attaching the thermometer and the electrodes and sealing them, it is time to make a frame for the bottom of the mug. Use glues to seal the glass, which will not be solved by hot or cold water.To make the shell for the bottom of the mug. you must first measure the outer diameter of the mug. Then design a circle with exactly the same size of the bottom of the mug, and two rings with the outer diameter with a thickness of 3 mm (and of course with the diameter of the bottom of the mug).You can use plexiglass and a laser cut machine to make the prescribed shell. One of the rings must be transparent, you can choose the color of the rest of them as you wish.You should sand the transparent ring to achieve a matte finish. Glue them as shown in the images.Now glue the battery to the shell and connect its pins to Arduino. Slice the portion of the transparent ring as much as the Arduino micro USB port, and attach the Arduino to the battery so that the connector drops out of the ring. Now solder the LEDs to the Arduino and connected other wires to Arduino. Finally, glue the shell to the bottom of the mug and upload the code to Arduino.
Now, improve the smart mug by adding new functionalities to the code. For example, you can add some lines to alarm you when your coffee is in the desired temperature and it’s ready to drink. You can light up the green LEDs for alarming. In the next step, you can add a heater element to the bottom of your mug and write some code to stop decreasing the temperature of the drink.
Comments