## Introduction: Interactive Flower Pot - Arduino Motion Activated RGB Led

In this project I've made a flower pot with recycled plastic drink bottles. Then using Arduino, it turned in to a motion activated colorful lamp. This tutorial will show you how to wire and program your motion detector and RGB led with your Arduio. In this example, the RGB led goes on when there's motion detected and it changes color to red, green, blue, white and purple continually until there no motion detected and it then goes off.

## Step 1: The Parts

Here's the list of part needed:

1. Arduino Uno

3. Jumper wires

4. PIR motion detector

5. 3 x 220 ohm resistors

6. RGB led module

## Step 2: Wiring the Parts

This part explains how to wire all the parts. The PIR sensor has 3 pins, one to the ground, one to 5V and the OUT pin connects to a digital pin point on the Arduino (I chose pin number 4). Here is a good website explaining how this works.

Now we'll connect the RGB Led. The one I'm using has 4 pins. One for each of the colors (Red, Green, Blue) and one is the common anode which connects to the ground. The color pins have to connect to Arduino through resistors. So I've connected the red pin to pin number 7 via a 220 ohm resistor, green to number 6 via a 220 ohm resistor and blue to pin number 5 also via a 220 ohm resistor. And the forth pin connect to ground.

## Step 3: Writing the Code

Here is the code for this project. I have used the millis() function to keep the sensor active when it's already on HIGH. So basically the sensor keeps checking for any movement in interval defined in const long interval (I've used 800). You can see how this function works here

int redPin= 7;

int greenPin = 6;

int bluePin = 5;

int motion = 4;

int pirState = LOW;

unsigned long previousMillis = 0; // will store last time PIR was updated

const long interval = 800; // interval at which to check for motion (milliseconds)

boolean randomNum = false; // to check the random number generate once

void setup() {

pinMode(motion, INPUT);

pinMode(redPin, OUTPUT);

pinMode(greenPin, OUTPUT);

pinMode(bluePin, OUTPUT);

Serial.begin(9600);

}

void loop() {

unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= interval) {

// save the last time you checked the pir

previousMillis = currentMillis;

if(sensor == HIGH){

if (randomNum == false){

randomNum = true;

//int redColor = random (100,255); // these are to generate random colours when motion is detected

//int greenColor = random (50,100);

// int blueColor = random (50,100);

// setColor(redColor, greenColor, blueColor);

setColor(255, 0, 0); // Red Color

delay(1000);

setColor(0, 255, 0); // Green Color

delay(1000);

setColor(0, 0, 255); // Blue Color

delay(1000);

setColor(255, 255, 255); // White Color

delay(1000);

setColor(170, 0, 255); // Purple Color

delay(1000);

//Serial.println(redColor);

}

else {

randomNum = false;

}

}

else {

setColor(0, 0, 0);

}

// set the LED with the ledState of the variable:

digitalWrite(sensor, pirState);

}

}

void setColor(int redValue, int greenValue, int blueValue) {

analogWrite(redPin, redValue);

analogWrite(greenPin, greenValue);

analogWrite(bluePin, blueValue);

}

## Step 4: Assembling the Flower Pot

And all is done :) Participated in the
Arduino Contest 2017