Touch Sensitive Color Changing Plants using Arduino and RGB LEDs

Published  October 22, 2020   0
RAJESH
Author
Touch Sensitive Color Changing Plants using Arduino and RGB LEDs

In this article, we will learn how to build a touch-based color-changing plant using Arduino. When you touch the plant, the color of the plant vase will automatically change. This is a nice indoor decorative project and also a small hobby project for beginners to build and learn some interesting stuff. Previously we have also built a touch-based music player using Arduino, which works on a similar principle, you can also check them out.

Now when we say touch-based plants, a common question that might pop-up is, how can an electronic circuit detect the human touch through a plant. Nowadays, touch sensing devices are all around us. we can see touch displays in our smartphones and also in different types of appliances. The touch sensor is simply as a switch, when someone touches the touch sensor, the sensor closes an electronic circuit and allows the flow of current.

Type of Touch Sensors

From mobile phones to smart vending machines, nowadays, we can find touch sensors in all modern devices. Touch sensors are mainly of two types, namely, resistive touch type and capacitive touch type. The name of the type itself indicates the mode of operation and the working principle.

Resistive Touch Sensor: As the name indicates Resistive Touch Sensor works based on the resistance of the conductor. When a touch happens with the human body, the resistivity of the conductor changes and there is also a voltage change, this voltage change is detected by the circuit and things happen.

Capacitive Touch Sensor: This is the most commonly used type of touch sensor. Its simply because we can perform multiple touches at a time. The capacitive touch sensor works based on the change in capacitance, that is when we touch the sensor the capacitance of the circuit changes and this will be detected as a touch. Now let's discuss our circuit in detail.

How to Detect a Touch on the Plant?

Our plant circuit is also based on the capacitive touch sensor. That is we will connect a wire to our plant to make it act like an electrode, then when we touch the plant, due to the presence of our body, the capacitance changes and this will be detected by our circuit. And talking about the circuit, we need a microcontroller to detect the change in capacitance and also control the whole system. In our case, the microcontroller is Arduino.

Color Changing Plants using Arduino

Materials Needed to Build our Colour Changing Plant Vase

  • Arduino
  • Common cathode RGB LED
  • 1mega ohm resistor (brown, black, green)
  • Connecting wire
  • A plant with  its base
  • Common PCB

Materials Needed to Build Color Changing Plant Vase

Circuit Diagram for Touch-Based Colour Changing Arduino Plant

The complete circuit diagram used in this project is shown below. The circuit was created using Easy EDA and as you can see, it is a very simple circuit.

Touch-Based Colour Changing Arduino Plant Circuit Diagram

First, connect the one mega ohm resistor in between Arduino pin 2 and pin 4. Then connect a long wire (copper) to pin 4. This wire acts as an electrode or touch lead, then connect RGB led common ground to ground and red to D5 of Arduino and green to D6, blue to D7, finally attach the wire to the plant body and that's it. My hardware set-up after the connections has been made looks like this as shown below.

Touch-Based Colour Changing Arduino Plant

I have connected the RGB LEDs in a common perf board (like shown below) and finally placed the base (glass) above on the PCB. That's it.

RGB LEDs

Arduino Program to Detect Touch on Plant and Change LED Colour

The complete program used in this project can be found at the bottom of this page. To detect the capacitance of the plant, we need to use a capacitive sensor library. You can download the Arduino capacitive sensor library from the below link.

Download Arduino capacitive touch sensor library

After downloading and adding the library to your Arduino IDE, include that library to your code. This library helps to read the capacitance of Arduino pins.

#include <CapacitiveSensor.h>

We have already connected the resistor between pin 2 and 4, so we need to measure the capacitance in pin 4, for that, defined the pins.

CapacitiveSensor   cs_2_4 = CapacitiveSensor(2,4); 

capacitive sensor toggles a microcontroller pin, that is it sends the pin to a new state and then waits for the receive pin to change to the same state as the send pin. In the setup section, I defined different pins for led and sensor lead.

  pinMode(4, INPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);

In the loop section With the help of digital read, we can read the state of pin 4 and we store the value in variable ‘r’.

 r = digitalRead(4);
  if (r == HIGH && p == LOW && millis() - time > debounce) {
    cnt++;
  if (state == HIGH)
     state = LOW;
if(cnt == 1){
    digitalWrite(5, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
  }
  if(cnt == 2){
    digitalWrite(5, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(7, LOW);
  }
  if(cnt == 3){
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, HIGH);
  }
  if(cnt > 3){
      cnt = 1;
  }
  p = r;

Each time a touch is detected, it will increase the counts and I have given different conditions to light up in different colors based on the incremented number.

Once the code is ready, simply upload it to your Arduino board and place the LEDs under your vase. Here I am using a glass vase and my setup looks like this when everything is ready.

Arduino based Color Changing Plant

As you can see, the vase is already lit up in red color, and when I touch the plant, the color will change. Just make sure to use water-rich plants like lucky bamboo, money plant, etc. The complete working of this project can also be found in the video below.

Hope you enjoyed building this project and learned something useful, if you have any questions, leave them in the comment section below or use our forums for starting other technical discussions.

Code
#include <CapacitiveSensor.h>
CapacitiveSensor   cs_2_4 = CapacitiveSensor(2,4); // 1M resistor between pins 2 & 4, pin 4 is sensor pin, add a wire and 
int cnt=0;
int in = 2; 
int out = 4;  
int state = HIGH;  
int r;           
int p = LOW;    
long time = 0;       
long debounce = 200;
void setup()
{
  pinMode(4, INPUT);
  /*    LED Outputs   */
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT); 
}
void loop()                    
{
  r = digitalRead(4);
  if (r == HIGH && p == LOW && millis() - time > debounce) {
    cnt++;
  if (state == HIGH)
     state = LOW;
    else 
    time = millis();
  } 
  if(cnt == 1){
    digitalWrite(5, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
  }
  if(cnt == 2){
    digitalWrite(5, LOW);
    digitalWrite(6, HIGH);
    digitalWrite(7, LOW);
  }
  if(cnt == 3){
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, HIGH);
  }
  if(cnt > 3){
      cnt = 1;
  }
  p = r;
}
Video

Have any question realated to this Article?

Ask Our Community Members