Arduino LED Faucet

Introduction: Arduino LED Faucet

Hope you all are doing well! Today I will talk about how to make a cool Arduino project. I call this project LED Faucet. Surely, by now, everyone has see the LED faucets, if you haven't here: LED faucet. Well, we're going to create something like that. Sound good? If not, please, go away. :( Anyway, I am going to show you how to create something like the LED faucet, but, THIS DOES RUN OFF OF A WALL ADAPTER, SO BE CAREFUL WITH THIS PROJECT. PLEASE, FOR GOODNESS SAKES, DON'T PUT WATER ON THE WALL ADAPTER OR ANYTHING ELSE (INCLUDING THE ARDUINO) OR YOU WILL END UP HURTING SOMETHING (INCLUDING YOU). Phew, just thought I would get that off my chest. :) I mean, I understand if you accidentally get, SOME water on the Arduino, but FOR GOODNESS SAKEs, AGAIN, DON'T PUT ANY WATER ON ANYTHING ON PURPOSE!!!! Don't blame me when your house is on fire. >:( Anyway, without a further a do, let's get started...

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Materials

  • Arduino (Mega 2560 in my case)
  • USB cord (Type B - female)
  • Resistor (220 ohms work just fine or any < 220)
  • Wires (Male to male, female to male, and female to female)
  • Wall adapter (9V in my case)
  • Lab rules (optional)
  • No kids (optional)

Step 2: Schematic and Wiring Diagram

So, again, DON'T PURPOSEFULLY POUR WATER ON ANYTHING. Anyway:

  1. Get the Arduino
  2. Put the RGB LED into the breadboard.
  3. Attach a wire from GND (from the Arduino) to the breadboard, the negative rail
  4. Attach 2 wires (one to ground the other to pin 8), this will act as a switch
  5. Add the resistors to the digital pins of the RGB LED (more information can be found here: RGB LED link)
  6. Add the wires from the digital pins of the Arduino to the digital pins of the RGB LED
  7. Add a wire to the GND of the RGB LED to the negative rail of the breadboard

Step 3: Visual Aid

To explain the schematic/wiring diagram, I added a bunch of pictures, you know, for visual aid. Some things I should mention are that the wires for both the RGB LED and free wires/switch are not the same as the original color, the color that they are at the faucet/sink. In my case (in case you want to follow along), the wires at the sink for the RGB LED goes from left to right in this order; blue (LED blue pin), green (LED green pin), purple (LED GND), and grey(LED red pin). The wires in the middle to the RGB LED go in the following order; LED red pin from grey to red, LED GND pin from purple to black, LED green pin from green to brown, and LED blue pin from blue to white. 3rd section of the wires go in this order; LED red pin goes from red to red, LED GND pin goes from black to black, LED green pin goes from brown to brown, and LED blue pin goes from white to orange. The digital part of the LED is connect like so (MAKE SURE TO CONNECT THE RESISTORS LISTED IN THE PREVIOUS STEP TO THE DIGITAL AND LED PINS); orange wire goes to pin 6 of the Arduino (RGB LED red pin). The green wire goes to pin 5 (RGB LED green pin). Last, the yellow pin goes to pin 5 (RGB LED blue pin). The switch wire is your choice, but if you want to follow along and make the wiring the same because you are a perfectionist then here is the order; switch GND pin goes to blue (to the sink - 1st section), switch digital pin goes to purple. The middle section; switch GND from blue to black, and switch digital pin from purple to white. The third section just repeats the 1st section. Make sure to connect the blue (3rd section) wire to the GND of the Arduino, and connect the purple wire to pin 8.

Step 4: Code

Make sure to upload this code using the computer and usb. Also, don't forget: CONFIGURE YOUR BOARD AND COM PORT IN THE TOOLS SECTION OF THE ARDUINO FIRST!


//www.elegoo.com
//2016.12.8
// Define Pins
#define BLUE 3
#define GREEN 5
#define RED 6
const byte buttonPin = 8;
void setup()
{
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  digitalWrite(RED, HIGH);
  digitalWrite(GREEN, LOW);
  digitalWrite(BLUE, LOW);
}
// define variables
int redValue;
int greenValue;
int blueValue;
// main loop
void loop()
{
#define delayTime 10 // fading time between colors
  if (digitalRead(buttonPin) == LOW) {
    redValue = 255; // choose a value between 1 and 255 to change the color.
    greenValue = 0;
    blueValue = 0;
    // this is unnecessary as we've either turned on RED in SETUP
    // or in the previous loop ... regardless, this turns RED off
    // analogWrite(RED, 0);
    // delay(1000);
    for (int i = 0; i < 255; i += 1) // fades out red bring green full when i=255
    {
      redValue -= 1;
      greenValue += 1;
      // The following was reversed, counting in the wrong directions
      // analogWrite(RED, 255 - redValue);
      // analogWrite(GREEN, 255 - greenValue);
      analogWrite(RED, redValue);
      analogWrite(GREEN, greenValue);
      delay(delayTime);
    }
    redValue = 0;
    greenValue = 255;
    blueValue = 0;
    for (int i = 0; i < 255; i += 1) // fades out green bring blue full when i=255
    {
      greenValue -= 1;
      blueValue += 1;
      // The following was reversed, counting in the wrong directions
      // analogWrite(GREEN, 255 - greenValue);
      // analogWrite(BLUE, 255 - blueValue);
      analogWrite(GREEN, greenValue);
      analogWrite(BLUE, blueValue);
      delay(delayTime);
    }
    redValue = 0;
    greenValue = 0;
    blueValue = 255;
    for (int i = 0; i < 255; i += 1) // fades out blue bring red full when i=255
    {
      // The following code has been rearranged to match the other two similar sections
      blueValue -= 1;
      redValue += 1;
      // The following was reversed, counting in the wrong directions
      // analogWrite(BLUE, 255 - blueValue);
      // analogWrite(RED, 255 - redValue);
      analogWrite(BLUE, blueValue);
      analogWrite(RED, redValue);
      delay(delayTime);
    }
  }
}

Step 5: Code Explained

This section defines the pins for the RGB LED and switch. What does that mean? The variable for the RGB LED pins have a place holder of 3, 5, and 6. This will later be defined as the pin numbers and therefore, those pins will be initialized or set as pin 3, 5, and 6. Imagine the variable as a box and the value it contains as a item. If we set RGB LED blue pin to 3 the variable will act as a box and will have a certain number or item contained inside.

//www.elegoo.com
//2016.12.8
// Define Pins
#define BLUE 3    //RGB LED blue digital pin
#define GREEN 5  //RGB LED green digital pin
#define RED 6   //RGB LED red digital pin
const byte buttonPin = 8;   //free wires (AKA switch)

This part will set the pins as either input with a pullup resistor or output and turn on or off the LEDs. What does that mean? Well, all a pullup resistor is, basically a resistor with a certain voltage on it (i.e. 5V) and the device (i.e. the Arduino) in parallel to read the voltage rating. The output is simple, it literally outputs voltage (i.e. 5V) to the LEDs (NOTE YOU DO HAVE TO HAVE THE RESISTORS OR YOU WILL KILL YOUR LED).

void setup()
{ 
  pinMode(RED, OUTPUT); 
  pinMode(GREEN, OUTPUT); 
  pinMode(BLUE, OUTPUT);
  //MAKE SURE TO USE INPUT_PULLUP OR THE BUTTON MAY READ FALSE READINGS OR DATA
pinMode(buttonPin, INPUT_PULLUP); 
   digitalWrite(RED, HIGH);   //turn on red LED
digitalWrite(GREEN, LOW);  //turn off green LED 
digitalWrite(BLUE, LOW);  //turn off blue LED
}

This part is where the real action happens. If the water is detected (i.e. it short circuits the two leads by water being conductive) then fade the LED to different colors (i.e from red to blue to green). That's it, it's that simple!

// define variables int redValue;int greenValue; int blueValue;// main loop
void loop()
{ #define delayTime 10 // fading time between colors  

if (digitalRead(buttonPin) == LOW) {    

	redValue = 255; // choose a value between 1 and 255 to change the color.
        greenValue = 0;
        blueValue = 0;    

	// this is unnecessary as we've either turned on RED in SETUP
    // or in the previous loop ... regardless, this       turns RED off
     // analogWrite(RED, 0);
      // delay(1000);    

for (int i = 0; i < 255; i += 1) // fades out red bring green full when i=255
    {
      redValue -= 1;
      greenValue += 1;
      // The following was reversed, counting in the wrong directions
      // analogWrite(RED, 255 - redValue);
      // analogWrite(GREEN, 255 - greenValue);
      analogWrite(RED, redValue);
      analogWrite(GREEN, greenValue);
      delay(delayTime);
    }


    redValue = 0;
    greenValue = 255;
    blueValue = 0;
    for (int i = 0; i < 255; i += 1) // fades out green bring blue full when i=255


    {
      greenValue -= 1;
      blueValue += 1;
      // The following was reversed, counting in the wrong directions
      // analogWrite(GREEN, 255 - greenValue);
      // analogWrite(BLUE, 255 - blueValue);
      analogWrite(GREEN, greenValue);
      analogWrite(BLUE, blueValue);
      delay(delayTime);
    }


    redValue = 0;
    greenValue = 0;
    blueValue = 255;


    for (int i = 0; i < 255; i += 1) // fades out blue bring red full when i=255
    {
      // The following code has been rearranged to match the other two similar sections
      blueValue -= 1;
      redValue += 1;
      // The following was reversed, counting in the wrong directions
      // analogWrite(BLUE, 255 - blueValue);
      // analogWrite(RED, 255 - redValue);
      analogWrite(BLUE, blueValue);
      analogWrite(RED, redValue);
      delay(delayTime);
    }
  }
}

Step 6: Plug in the Power

JUST MAKE SURE YOUR VOLTAGE IS SET AT 7-9V ON YOUR WALL ADAPTER! Make sure all of your connections are working.

Step 7: Tape on All Electrical Components and Your All Set to Go!

AGAIN, MAKE SURE NOT TO SPILL WATER ON ANYTHING ON PURPOSE, JUST BE EXTRA CAREFUL!!

Be the First to Share

    Recommendations

    • Trash to Treasure Contest

      Trash to Treasure Contest
    • Raspberry Pi Contest 2020

      Raspberry Pi Contest 2020
    • Wearables Contest

      Wearables Contest

    Discussions