Toilet tissue Alert with ultrasonic sensor

Well, it might sound odd that you need an alert to know when your toilet tissue is running out. This is just an idea and maybe helpful as well if someone can make it even precise and reliable. And it could be a luxury item for rich people, but anyway I made this as an example. Let's first see what you need to make it.

  • 1x RGB led.
  • 1x Ultrasonic Sensor.
  • 1x Arduino Board.
  • Few jumper cables.
  • And the sketch below.

The Sketch
int redPin = 4;
int greenPin = 5;
int bluePin = 6;

int trigPin2 = 8;
int echoPin2 = 9;

void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
  Serial.begin (9600);

  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);

void setColor(int red, int green, int blue)
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);

void loop() {

    int duration2, distance2;
    digitalWrite (trigPin2, HIGH);
    delayMicroseconds (10);
    digitalWrite (trigPin2, LOW);
    duration2 = pulseIn (echoPin2, HIGH);
    distance2 = (duration2/2) / 29.1;

      Serial.print("2nd Sensor: ");
      Serial.print("cm  ");
    if (distance2 >=9) {  // Change the number for long or short distances.
 setColor(255, 0, 0);
  setColor(0, 0, 0);
   else if (distance2 >=7 && distance2 <=9) {  // Change the number for long or short distances.
 setColor(255, 208, 0);
  setColor(0, 0, 0);
      else if (distance2 <=7) {  // Change the number for long or short distances.
 setColor(101, 255, 0);
  setColor(0, 0, 0);
 else {

delay(3000); // 3 seconds delay

Now let me explain what it does. Because it works by calculating the distance between the sensor and the tissue roll, so you might have change it according to your need. In this case it turns on the red led when the distance exceeds 9cm. And if the distance is 7cm to 9cm it turns on the amber led, and the if it's less than  7cm it turns on the green led. After take a rest for 3 seconds and then starts the sensor again to see how much tissue has been used. You can make it take the measurement after each 5 or 10 minutes if you want by changing the number to what ever amount you want.


No comments:

Post a Comment

Newly posted:
Reason why rich getting richer and poor getting poorer