Milk Reminder

by danny20130311 in Circuits > Arduino

40 Views, 1 Favorites, 0 Comments

Milk Reminder

696E361D-DA9B-480F-A738-63D1492A6701.jpeg
提醒喝牛奶

I create a "milk reminder" using Arduino to help me remember to drink milk, preventing it from spoiling due to neglect. This device can be placed in my living room or milk room and uses a weight sensor to detect if the milk is on the board. If the milk is not present, a yellow LED will light up; if the milk is on the board but hasn't been drunk for a long time, a red LED will flash. This reminder is practical and helps prevent waste, ensuring you maintain the habit of regularly drinking milk.

Supplies

You can create an Arduino-based project using the Arduino LEONARDO board, connecting various sensors and components to monitor and manage a 290cc container of milk. Here's a brief overview of how this project could be structured:

  1. Cardboard sheets
  2. Ruler
  3. Pencil
  4. Scissors or box cutter
  5. Glue or tape
  6. Cutting mat (optional)



Components:

  1. Arduino LEONARDO Board:
  2. A microcontroller board that acts as the brain of your project, processing inputs from sensors and controlling outputs like LEDs or alarms.
  3. Electric Wires:
  4. Used to connect the Arduino board to various sensors and other electronic components, forming the necessary circuits.
  5. Sensors:
  6. VL53L0X Distance Sensor: This sensor can be used to detect the presence of the milk container on a specific surface or to measure the distance between the sensor and the milk container.
  7. Additional Sensors: You might use weight sensors to measure the amount of milk left in the container or temperature sensors to monitor the milk's temperature.
  8. 290cc Milk Container:
  9. This is the milk container that your project will monitor. The system could track the milk's presence, the amount of milk left, and alert you if it's been left out too long.

Project Description:

The project aims to monitor a 290cc milk container using an Arduino LEONARDO board and connected sensors. The VL53L0X sensor could be used to detect the presence of the milk container on a platform. If the milk is not detected, an LED or buzzer could be triggered to alert you. Additionally, the system can track how long the milk has been left out using the Arduino’s internal clock and flash a red LED if the milk has been left out too long, signaling that it may be going bad.

By integrating these components, you create a practical and automated solution to ensure that your milk is properly monitored, reducing waste and helping you maintain a regular milk-drinking habit.

Make Box

055D239E-C2F3-47C0-86E8-CA50C46048A1.jpeg
ED53B921-667D-4728-AB73-8B71BBB71442.jpeg
696E361D-DA9B-480F-A738-63D1492A6701.jpeg
F380C053-38E8-40E6-AA99-B668DBCBE900.jpeg

To make a simple box, you can use various materials like cardboard, wood, or plastic, depending on your needs. Here’s a basic guide for making a cardboard box:

Materials Needed:

  1. Cardboard sheets
  2. Ruler
  3. Pencil
  4. Scissors or box cutter
  5. Glue or tape
  6. Cutting mat (optional)

Steps to Make a Cardboard Box:

  1. Plan the Box Dimensions:
  2. Decide the dimensions of the box: length, width, and height.
  3. For example, if you want a box that is 10 cm long, 8 cm wide, and 6 cm high, keep these dimensions in mind as you draw the template.
  4. Draw the Template:
  5. Lay the cardboard flat on your cutting mat.
  6. Use the ruler and pencil to draw the outline of the box on the cardboard.
  7. Draw a central rectangle representing the base of the box (e.g., 10 cm x 8 cm).
  8. Draw four rectangles around this central rectangle for the sides, each with the height of the box (e.g., 6 cm). These rectangles should share a side with the central rectangle.
  9. Add tabs to the sides that will be used to glue the box together. The tabs should be about 1-2 cm wide.
  10. Cut Out the Template:
  11. Use scissors or a box cutter to carefully cut along the lines of the template.
  12. Be precise to ensure the box fits together well.
  13. Score the Fold Lines:
  14. Use the ruler and the back of the scissors (or a scoring tool) to lightly score the lines where the box will be folded. This will make it easier to fold the cardboard neatly.
  15. Fold the Box:
  16. Fold along the scored lines to create the shape of the box.
  17. Fold the sides up and fold the tabs inward.
  18. Assemble the Box:
  19. Apply glue to the tabs and attach them to the corresponding sides of the box.
  20. Hold the glued edges together until the glue sets or use tape to secure them.
  21. Finish the Box:
  22. Allow the glue to dry completely if using glue.
  23. If desired, you can reinforce the edges with additional tape or decorate the box as needed.

Now you have a simple cardboard box! You can scale this process up or down depending on the size and material you want to use.

Add Sensor

AFCF4BBB-8EC9-4646-84DC-B96A54C637C6.jpeg

The VL53L0X is a miniature laser distance sensor developed by STMicroelectronics, based on Time-of-Flight (ToF) technology. Here are its key features and functions:

Key Features:

  1. Distance Measurement:
  2. Measures the distance between the sensor and an object, typically ranging from a few millimeters up to 2 meters, depending on ambient lighting conditions.
  3. High Accuracy:
  4. Provides millimeter-level distance measurement accuracy at short ranges, making it ideal for applications requiring precise measurements.
  5. Fast Measurement:
  6. Capable of measuring distance at up to 50 times per second, suitable for detecting fast-moving objects.
  7. Interference Resistance:
  8. Uses a 940nm invisible laser to avoid interference from external light sources like sunlight.
  9. Low Power Consumption:
  10. Designed for battery-powered applications with low power modes, extending device lifespan.
  11. Simple I2C Communication:
  12. Communicates with microcontrollers via the I2C interface, making it easy to integrate into various embedded systems.

Typical Applications:

  1. Robot Obstacle Avoidance: Detects obstacles for robots to avoid collisions automatically.
  2. Distance Mapping: Used in tools like rangefinders for precise distance measurement.
  3. Gesture Recognition: Detects hand movements for gesture control systems.
  4. Presence Detection: Identifies if an object is within a specific range, used in automatic doors, liquid level sensing, etc.


Program

螢幕擷取畫面 2024-08-27 132630.png

Creating a Responsive LED System with VL53L0X Sensor and NeoPixel Ring

This project demonstrates how to use an Arduino to control a NeoPixel LED ring based on distance measurements taken by a VL53L0X sensor. The system is designed to change the color of the LEDs based on an object's distance and includes a feature to flash the LEDs red at specific intervals.

Components Used

  1. VL53L0X Distance Sensor: This sensor is used to measure the distance of an object from the sensor. It's an advanced sensor capable of measuring distances up to a few meters.
  2. NeoPixel LED Ring: A ring of addressable LEDs (in this case, 16 LEDs) controlled by a single data pin. NeoPixel LEDs can display a wide range of colors and are perfect for visual feedback in projects.

Key Features

  1. Red LED Flashing: The LEDs flash red every 30 seconds if a certain condition is met.
  2. State-Based LED Control: The LEDs only change color if the sensor detects that the object has remained at a certain distance for at least 0.3 seconds.
  3. Rainbow Animation: If no specific condition is met, the LEDs will display a continuous rainbow animation.

Code Explanation

The code is written in C++ for the Arduino environment and uses the Adafruit libraries for both the VL53L0X sensor and the NeoPixel ring. Below is a breakdown of the code:

1. Initial Setup

cpp
#include <Wire.h>
#include <Adafruit_VL53L0X.h>
#include <Adafruit_NeoPixel.h>

#define LED_PIN 8
#define LED_COUNT 16
#define RED_FLASH_INTERVAL 30000
#define STATE_CHANGE_DELAY 300

Here, the necessary libraries are included, and the pins and intervals are defined. The LED_PIN defines which Arduino pin is connected to the NeoPixel ring, and LED_COUNT is the number of LEDs in the ring.

2. Global Variables

cpp
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

bool milkIsOnBorad = true;
bool previousMilkIsOnBorad = true;
bool isFlashingRed = false;
unsigned long previousMillis = 0;
unsigned long rainbowMillis = 0;
unsigned long flashMillis = 0;
unsigned long stateChangeMillis = 0;
int rainbowDelay = 20;
int flashStep = 0;

These variables store the state of the system and control timing for the LED effects. milkIsOnBorad represents whether the measured distance is within the desired range.

3. Setup Function

cpp
void setup() {
Serial.begin(115200);
while (!Serial) { delay(10); }

strip.begin();
strip.show();
strip.setBrightness(50);

if (!lox.begin()) {
Serial.println("Sensor initialization failed");
while (1);
}
}

In setup(), the serial communication and NeoPixel strip are initialized, and the VL53L0X sensor is started. If the sensor fails to initialize, the program stops.

4. Main Loop

cpp
void loop() {
VL53L0X_RangingMeasurementData_t measure;
lox.rangingTest(&measure, false);

if (measure.RangeStatus != 4) {
Serial.print("Distance: ");
Serial.print(measure.RangeMilliMeter);
Serial.println(" mm");
} else {
Serial.println("Measurement failed");
}

unsigned long currentMillis = millis();

bool currentMilkIsOnBorad = (measure.RangeMilliMeter >= 75 && measure.RangeMilliMeter <= 90);

if (currentMilkIsOnBorad != previousMilkIsOnBorad) {
stateChangeMillis = currentMillis;
} else if (currentMillis - stateChangeMillis >= STATE_CHANGE_DELAY) {
milkIsOnBorad = currentMilkIsOnBorad;
}

previousMilkIsOnBorad = currentMilkIsOnBorad;

if (milkIsOnBorad) {
if (!isFlashingRed && (currentMillis - previousMillis >= RED_FLASH_INTERVAL)) {
previousMillis = currentMillis;
isFlashingRed = true;
flashStep = 0;
}

if (isFlashingRed) {
flashRedNonBlocking(currentMillis);
} else {
rainbowCycleStep();
}
} else {
isFlashingRed = false;
setRingColor(strip.Color(255, 255, 0));
}
}

The main loop continuously measures the distance and determines if the object is within the specified range. If the distance remains stable for 0.3 seconds, the system updates its state and changes the LED color accordingly.

5. LED Control Functions

cpp
void flashRedNonBlocking(unsigned long currentMillis) {
if (currentMillis - flashMillis >= 500) {
flashMillis = currentMillis;

if (flashStep % 2 == 0) {
setRingColor(strip.Color(255, 0, 0));
} else {
setRingColor(strip.Color(0, 0, 0));
}
flashStep++;
}
}

This function controls the flashing of red LEDs in a non-blocking way, allowing other code to run simultaneously.

cpp
void setRingColor(uint32_t color) {
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, color);
}
strip.show();
}

This helper function sets the entire LED ring to a specified color.

cpp
void rainbowCycleStep() {
static int j = 0;
unsigned long currentMillis = millis();

if (currentMillis - rainbowMillis >= rainbowDelay) {
rainbowMillis = currentMillis;

for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
j = (j + 1) % (256 * 5);
}
}

uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}

These functions create the rainbow effect by continuously cycling through different colors.

Conclusion

This project provides a great example of integrating sensors with visual output in an Arduino project. By combining the VL53L0X sensor and NeoPixel LEDs, you can create interactive and visually appealing electronics projects. The non-blocking approach used in this code ensures that the system remains responsive while controlling complex LED animations.vv