Things used in this project

Hardware components:
Adafruit Analog RGB LED Strip
×1
09590 01
LED (generic)
1 red, 1 green
×2
Msp exp432p401r msp exp432p401r sidered eoamulng36
TI LaunchPad MSP-EXP432P401R SimpleLink MSP432 LaunchPad
Microprocessor
×1
Cc3100boost cc3100boost no bg resize
TI LaunchPad CC3100BOOST SimpleLink Wi-Fi BoosterPack
Enables IoT wifi communication
×1
HC-SR04 Ultrasonic Sensor
Rangefinder
×1
DRV8850 Motor Driver (Texas Instruments)
Drives water pump
×1
DC to DC Adjustable Step-up Boost Voltage Converter Module
MSP432 outputs 3.3V, we use this to step that up to 12V
×1
5V Wall Adapter
Provides power to MSP432
×1
5V USB Port
×1
Water Pump
×1
Software apps and online services:
Logo header
Temboo
Make an account
Energiabadgelogo2
TI LaunchPad Energia
IDE for writing/flashing code onto the MSP432
Hand tools and fabrication machines:
3drag
3D Printer (generic)
Used to print casing for system
09507 01
Soldering iron (generic)

Custom parts and enclosures

Schematics

Energy Harvesting BoosterPack
Pcb

Code

ColorsC/C++
#define greenPin 40
#define redPin 39
#define bluePin 38

byte red, green, blue; 
byte red_a = 0;
byte green_a = 0; 
byte blue_a = 0;
int ledDelay = 0;
byte colorCount = 1;                //Count the colors out
#define colorCount_max 7              //Set this to the max number of colors defined
#define colorDelay 4000             //Define the delay between changing colors in ms
#define timeAt_color 1000           //Time to stay on a color in ms

//Some Time values
unsigned long timeLed = 0;
unsigned long timeColor = 0;

//Define colors here.
//blue
#define C1_R 0
#define C1_G 0
#define C1_B 255
//Red
#define C2_R 255
#define C2_G 0
#define C2_B 0
//White
#define C3_R 255
#define C3_G 255
#define C3_B 255
//Orange
#define C4_R 255
#define C4_G 186
#define C4_B 0
//Light 
#define C5_R 0
#define C5_G 168
#define C5_B 255
//Purple
#define C6_R 255
#define C6_G 0
#define C6_B 255
//Yellow
#define C7_R 255
#define C7_G 250
#define C7_B 0

void setupRGB()
{

  //Assign initial values
  red= C1_R;
  green= C1_G;
  blue = C1_B;
  //Get the ledDelay speed
  ledDelay = (colorDelay - timeAt_color) / 255; 

  analogWrite(greenPin, 0);
  analogWrite(redPin, 0);
  analogWrite(bluePin, 0);
  delay(5000);
}

void loopRGB()
{

  //Rest of your program - Avoid using delay(); function!

  if(millis() - timeLed >= ledDelay){
    timeLed = millis();

    //Run the LED Function to check and adjust the values
    LED();
  }

  if(millis() - timeColor >= colorDelay){
    timeColor = millis();

    //Run the color Change function
    color();
  }

}

void LED()
{

  //Check Values and adjust "Active" Value
  if(red!= red_a){
    if(red_a > red) red_a = red_a - 1;
    if(red_a < red) red_a++;
  }
  if(green!= green_a){
    if(green_a > green) green_a = green_a - 1;
    if(green_a < green) green_a++;
  }
  if(blue != blue_a){
    if(blue_a > blue) blue_a = blue_a - 1;
    if(blue_a < blue) blue_a++;
  }

  //Assign modified values to the pwm outputs for each color led
  analogWrite(redPin, red_a);
  analogWrite(greenPin, green_a);
  analogWrite(bluePin, blue_a);

}

void color()
{

  //Increment the color by one or go back to 1 if maxed out
  if(colorCount < colorCount_max) colorCount++;
  else colorCount = 1;

  if(colorCount == 1){
    red= C1_R;
    green= C1_G;
    blue = C1_B;
  } else if(colorCount == 2){
    red= C2_R;
    green= C2_G;
    blue = C2_B;
  } else if(colorCount == 3){
    red= C3_R;
    green= C3_G;
    blue = C3_B;
  } else if(colorCount == 4){
    red= C4_R;
    green= C4_G;
    blue = C4_B;
  } else if(colorCount == 5){
    red= C5_R;
    green= C5_G;
    blue = C5_B;
  } else if(colorCount == 6){
    red= C6_R;
    green= C6_G;
    blue = C6_B;
  } else if(colorCount == 7){
    red= C7_R;
    green= C7_G;
    blue = C7_B;
  }
}
TembooAccountC/C++
/*
IMPORTANT NOTE about TembooAccount.h

TembooAccount.h contains your Temboo account information and must be included
alongside your sketch. To do so, make a new tab in Energia, call it TembooAccount.h,
and copy this content into it. 
*/

#define TEMBOO_ACCOUNT "comets"  // Your Temboo account name 
#define TEMBOO_APP_KEY_NAME "myFirstApp"  // Your Temboo app name
#define TEMBOO_APP_KEY "10fad3dea77045e78b2a06fc45f95196"  // Your Temboo app key

#define WIFI_SSID "iPhone (3)"
#define WPA_PASSWORD "ua87pe058ota"

/* 
The same TembooAccount.h file settings can be used for all Temboo sketches.

Keeping your account information in a separate file means you can share the 
main .ino file without worrying that you forgot to delete your credentials.
*/
Motor/PumpC/C++
//motor a and b
#define B_1L	63
#define B_1H	62
#define B_2H	64
#define B_2L	65

#define B_sleep	66

#define B_WHEEL	68
#define microC	67


void setupMotor()
{
   // microC low on, high board off
  pinMode(microC, OUTPUT);
  digitalWrite(microC, LOW);

  // Setup Pins for Motor Drivers

  pinMode(B_sleep, OUTPUT);

  digitalWrite(B_sleep, HIGH);


  pinMode(B_1L, OUTPUT);
  pinMode(B_1H, OUTPUT);
  pinMode(B_2H, OUTPUT);
  pinMode(B_2L, OUTPUT);

  digitalWrite(B_1L, LOW);
  digitalWrite(B_1H, LOW);
  digitalWrite(B_2H, LOW);
  digitalWrite(B_2L, LOW);

  // pinMode(A_WHEEL, INPUT_PULLDOWN);    // Pin 3 (PUSH1)  hardware prefers low
  pinMode(B_WHEEL, INPUT_PULLUP);      // Pin 4          hardware prefers high
  delay(5000);
}

void loopMotor()
{
    digitalWrite (B_2L, HIGH); //forward
    digitalWrite (B_2H, LOW);
    digitalWrite (B_1L, LOW);
    digitalWrite (B_1H, HIGH);
  
}
ultraSonicC/C++
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <Temboo.h>
#include "TembooAccount.h" // Contains Temboo account information

#define trigPin 41
#define echoPin 57
#define led 44
#define led2 59

WiFiClient client;

long previousMillis = 0;
long previousMillis2 = 0;
// int interval = 600000; // data gets logged every 10 minutes
int interval = 60000;
int interval2 = 2000;  // scan rate (in milliseconds)
long duration, distance;
static int daygreenCount = 0;
static int dayredCount = 0;
long time = millis();

void setupUltra(){
  Serial.begin (115200);
 
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  
  delay(5000);
}

int checkDistance(){
  digitalWrite(trigPin, LOW);  
  delayMicroseconds(2); 
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); 
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  return distance;
}

// inactive function
void greenLED(){
  static int greenCount = 0;

  if(greenCount == 0)
  {
      Serial.println("This greenLED function (detection) is called as a first time\n");
      greenCount++;
      daygreenCount++;
  }
  
  else
  {
     greenCount++;
     daygreenCount++;
     Serial.println("This greenLED function (detection) has been called");
     Serial.print(greenCount);
     Serial.println("times so far\n");
     
     // if (greenCount == 900) if inactive for 30 mins, sends txt to user
     if (greenCount == 5){ // demonstration
       connectInternet();
       sendText();
       greenCount = 0;
       
    
       unsigned long currentMillis = millis();
  
       if (currentMillis - previousMillis > interval) {    // demonstration..data gets logged every minute

         spreadSheet(daygreenCount,dayredCount);
         daygreenCount = 0;
         dayredCount = 0;
       
         }
      }
  }
  digitalWrite(led, HIGH); // When the Red condition is met, the Green LED should turn off
  digitalWrite(led2, LOW);
}

// active function
void redLED(){
  static int redCount = 0;
  
  if(redCount == 0)
  {
      Serial.println("This redLED function (no detection) is called as a first time\n");
      redCount++;
      dayredCount++;
  }

  else
  {
     redCount++;
     dayredCount++;
     Serial.println("The redLED function (no detection) has been called");
     Serial.print(redCount);
     Serial.println("times so far\n");
  }

  digitalWrite(led, HIGH); // When the Red condition is met, the Green LED should turn off
  digitalWrite(led2, LOW);
  
  digitalWrite(led, LOW);
  digitalWrite(led2, HIGH);
}

void connectInternet(){

 int wifiStatus = WL_IDLE_STATUS;

  // Determine if the WiFi Shield is present
  Serial.print("\n\nShield:");
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("FAIL");

    // If there's no WiFi shield, stop here
    while(true);
  }

  Serial.println("OK");

  // Try to connect to the local WiFi network
  while(wifiStatus != WL_CONNECTED) {
    Serial.print("WiFi:");
    wifiStatus = WiFi.begin(WIFI_SSID, WPA_PASSWORD);

    if (wifiStatus == WL_CONNECTED) {
      Serial.println("OK");
    } else {
      Serial.println("FAIL");
    }
    delay(5000);
  }

  Serial.println("Setup complete.\n");
  
}

void sendText(){

    TembooChoreo SendSMSChoreo(client);

    // Invoke the Temboo client
    SendSMSChoreo.begin();

    // Set Temboo account credentials
    SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT);
    SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
    SendSMSChoreo.setAppKey(TEMBOO_APP_KEY);

    // Set Choreo inputs
    String AuthTokenValue = "edd5b0235f6f679bcecbd83d3af35bee";
    SendSMSChoreo.addInput("AuthToken", AuthTokenValue);
    String BodyValue = "You've been inactive for x minutes. Get up and move around!";
    SendSMSChoreo.addInput("Body", BodyValue);
    String ToValue = "+19493949267";
    SendSMSChoreo.addInput("To", ToValue);
    String AccountSIDValue = "ACe5e5ed5a5a0e09d6a1327bc1add2dd9d";
    SendSMSChoreo.addInput("AccountSID", AccountSIDValue);
    String FromValue = "+15623726228";
    SendSMSChoreo.addInput("From", FromValue);

    // Identify the Choreo to run
    SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS");

    // Run the Choreo; when results are available, print them to serial
    SendSMSChoreo.run();

    while(SendSMSChoreo.available()) {
      char c = SendSMSChoreo.read();
      Serial.print(c);
    }
    SendSMSChoreo.close();

}

void spreadSheet(int x, int y){
    TembooChoreo AppendRowChoreo(client);

    // Invoke the Temboo client
    AppendRowChoreo.begin();
    
    //read the values coming off of the sensor
    unsigned long valueX = x;
    unsigned long valueY = y;
    
    valueX = (valueX/30);
    valueY = (valueX/30);

    //convert the time and sensor data into a comma separated string
    String rowData("=NOW()");
    rowData += ",";
    rowData += valueX;
    rowData += ",";
    rowData += valueY;

    // Set Temboo account credentials
    AppendRowChoreo.setAccountName(TEMBOO_ACCOUNT);
    AppendRowChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
    AppendRowChoreo.setAppKey(TEMBOO_APP_KEY);

    // Set Choreo inputs
    String ClientSecretValue = "du0corH8gH14G5mL76VV3xhd";
    AppendRowChoreo.addInput("ClientSecret", ClientSecretValue);
    String RefreshTokenValue = "1/AisA7ezWnrh4ciB1osRpvIcDG2FcP_EBMcye5FHFjnA";
    AppendRowChoreo.addInput("RefreshToken", RefreshTokenValue);
    String RowDataValue = rowData;
    AppendRowChoreo.addInput("RowData", RowDataValue);
    String SpreadsheetTitleValue = "zen garden";
    AppendRowChoreo.addInput("SpreadsheetTitle", SpreadsheetTitleValue);
    String ClientIDValue = "333682580605-6se8komegqnj3aiq3nqebkcs4suh35th.apps.googleusercontent.com";
    AppendRowChoreo.addInput("ClientID", ClientIDValue);

    // Identify the Choreo to run
    AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow");

    // Run the Choreo; when results are available, print them to serial
    AppendRowChoreo.run();

    while(AppendRowChoreo.available()) {
      char c = AppendRowChoreo.read();
      Serial.print(c);
    }
    AppendRowChoreo.close();
  }

void loopUltra() {
  
  unsigned long currentMillis2 = millis();
  
  if (currentMillis2 - previousMillis2 > interval2) {
    
  previousMillis2 = currentMillis2;
    
  int testDistance = checkDistance();
  
    if (testDistance < 20) {  
      greenLED();
  }
    else {
      redLED();
  }
  }
}

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Particle Photon Based Security System with Alerting
Intermediate
  • 1,167
  • 19

Full instructions

Be alerted to any door or window opening and closing in your house on your smart phone.

Raspberry Pi Google Assistant With Sleek Wood Box
Intermediate
  • 4,696
  • 25

Full instructions

l built a DIY Google AI Assistant using a Raspberry Pi, USB Speaker and USB microphone.

Smart and Safe Outdoor Plant Watering System
Intermediate
  • 2,338
  • 17

Monitors soil moisture and weather forecasts to give plants just the water they need. Safe garden hose hookup for season long watering.

DIY Alarm Control Panel for Home Assistant
Intermediate
  • 13,504
  • 26

Full instructions

A simple touchscreen interface, powered by a Raspberry Pi Zero, which controls the alarm in Home Assistant over MQTT.

Using Temperature Sensor
Intermediate
  • 250
  • 3

Protip

Using the Temperature Sensor from Adafruit

IR Home Automation on Arduino
Intermediate
  • 801
  • 9

Full instructions

Control all the appliances (up to 8) using just a single IR Remote.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog