When the moment you open your refrigerator and all you saw is the rotten meat and ruined vegetables? We are suffering the same problem! That is why we build the refrigerator checker to help with the problem. The main components we use are Arduino Uno, DS18B20 temperature sensor and a LED Module to build the refrigerator saver.
Base on the component, you probably already guests it is a thermometer. How does it work? Put it into your refrigerator, it will display a thumbs up when the temperature is below 14 degree celsius which is the suitable temperature to store food. It will also display a snowflakes to show that it is below 0 degree celsius which is the temperature of freezer. Moreover, the LED module will also display a thumbs down when the temperature is above 14 degree celsius which cause most of the food to spoil.
At first, we need to prepare all the components and start arrange it with the schematics.
All the components that u need are already listed above and link is provided in order to buy them. In this project, we are using two sensors which is photoresistor and DS18B20 temperature sensor.
The main part is, we get the temperature using the DS18B20 temperature sensor, then we identify it as suitable temperature for storing food or not and finally display the outcome with LED Matrix 7219 8*8. The components part aren't the hardest, so you may done it within 2 hours.
After done prepared and assembly the components, coding part start. I divide the whole coding into three part and finally compile it together. First, i have to read the temperature. To use DS18B20 temperature sensor, you need to have 2 library which call 1 wire bus and Dallas Temperature. After installed both of the library, start the coding part with the reference.#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
int Temperature;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup(void)
{
Serial.begin(9600);
sensors.begin();
}
void loop(void)
{
sensors.requestTemperatures();
Temperature = sensors.getTempCByIndex(0);
Serial.print("Temperature is: ");
Serial.print(Temperature);
delay(1000);
}
After done coding, monitor the serial monitor and you will find the temperature reading in degree celcius.
After that, we need to work on the photoresistor part. Same, code with the reference.
int lightPin = 0;
int led = 4;
long previousMillis = 0;
long interval = 100;
void setup() {
pinMode(lightPin, OUTPUT);
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop() {
// using millis() instead of delay
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you checked the sensor
previousMillis = currentMillis;
// read value from sensor
int reading = analogRead(lightPin);
int ledvalue = reading / 1;
//log values to Serial Monitor
Serial.println("Light value / LED value");
Serial.print(reading);
Serial.print(" / ");
Serial.println(ledvalue);
//set the brigthness of LED
analogWrite(led, ledvalue);
}
}
Your photoresistor should work and the led will light up as soon as the it is dark enough.
Then, we need to start the 3rd part. Working on the LED Matrix 7219 Max. Here is the reference to where I learned how to use the module. To control the particular module, we need also the library which is LEDcontrol. With using the example in the reference website, modify the code as you want.
#include "LedControl.h"
LedControl lc=LedControl(12,11,10,1); // Pins: DIN,CLK,CS, # of Display connected
unsigned long delayTime=200; // Delay between Frames
// Put values in arrays
byte invader1a[] =
{
B10000001, // First frame of invader #1
B01000010,
B00100100,
B00011000,
B00011000,
B00100100,
B01000010,
B10000001
};
byte invader1b[] =
{
B00000000, // Second frame of invader #1
B00000001,
B00000010,
B00000100,
B10001000,
B01010000,
B00100000,
B00000000
};
void setup()
{
lc.shutdown(0,false); // Wake up displays
lc.shutdown(1,false);
lc.setIntensity(0,5); // Set intensity levels
lc.setIntensity(1,5);
lc.clearDisplay(0); // Clear Displays
lc.clearDisplay(1);
}
// Take values in Arrays and Display them
void sinvader1a()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0,i,invader1a[i]);
}
}
void sinvader1b()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0,i,invader1b[i]);
}
}
void loop()
{
// Put #1 frame on both Display
sinvader1a();
delay(delayTime);
// Put #2 frame on both Display
sinvader1b();
delay(delayTime);
}
After that, three of the code should be working as expected. Finally, combine the three part of code and change with your need.
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
#include "LedControl.h"
int Temperature;
int lightPin = 0;
int led = 4;
long previousMillis = 0;
long interval = 100;
unsigned long delayTime = 1000; // Delay between Frames
LedControl lc = LedControl(12, 11, 10, 1);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
byte invader1a[] =
{
B10000001, // First frame of invader #1
B01000010,
B00100100,
B00011000,
B00011000,
B00100100,
B01000010,
B10000001
};
byte invader1b[] =
{
B00000000, // Second frame of invader #1
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000
};
byte invader1c[] =
{
B00000000, // First frame of invader #1
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000
};
byte invader1d[] =
{
B00000000, // Second frame of invader #1
B00000001,
B00000010,
B00000100,
B10001000,
B01010000,
B00100000,
B00000000
};
byte invader1e[] =
{
B01100010, // First frame of invader #1
B10010101,
B10010101,
B10010010,
B10010000,
B10010000,
B10010000,
B01100000
};
byte invader1f[] =
{
B00000000, // Second frame of invader #1
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000
};
void setup() {
pinMode(lightPin, OUTPUT);
pinMode(led, OUTPUT);
Serial.begin(9600);
sensors.begin();
lc.shutdown(0, false); // Wake up displays
lc.shutdown(1, false);
lc.setIntensity(0, 5); // Set intensity levels
lc.setIntensity(1, 5);
lc.clearDisplay(0); // Clear Displays
lc.clearDisplay(1);
}
void sinvader1a()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0, i, invader1a[i]);
}
}
void sinvader1b()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0, i, invader1b[i]);
}
}
void sinvader1c()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0, i, invader1c[i]);
}
}
void sinvader1d()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0, i, invader1d[i]);
}
}
void sinvader1e()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0, i, invader1e[i]);
}
}
void sinvader1f()
{
for (int i = 0; i < 8; i++)
{
lc.setRow(0, i, invader1f[i]);
}
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
int reading = analogRead(lightPin);
int ledvalue = reading / 1;
analogWrite(led, ledvalue);
delay(0);
}
sensors.requestTemperatures();
Temperature = sensors.getTempCByIndex(0);
Serial.print("Temperature is: ");
Serial.print(Temperature);
if (Temperature >= 14)
{
sinvader1a();
delay(delayTime);
sinvader1b();
delay(delayTime);
} else if (Temperature < 14 && Temperature > 0 ) {
sinvader1c();
delay(delayTime);
sinvader1d();
delay(delayTime);
} else if (Temperature <= 0) {
sinvader1e();
delay(delayTime);
sinvader1f();
delay(delayTime);
}
}
Comments