Things used in this project

Code

Main Code - EnergiaArduino
This is main code in Energia. Here are defined all variables that we want to use in other sketches.
/*
 * This tutorial shows how to multithread multiple sensors with Texas Instruments
 * and Energia software. Each Sketch (tab) gets it's
 * own task executing in parallel.
 * Note the names of the setup and loop in these tabs. Energia will look
 * for the keywords with the name setup and loop in it. Each set of matching    setup
 * and loop pairs will automatically create a task for that tab. The loop and setup 
 * names will need to be unigue. So for instance, the Color tab's setup/loop pair are
 * called setupColor() and loopColor(). 
 * Only variables declared in main sketch can be used in other sketches, eg. distance
 * variable can be used in Led sketch, because it's declared in main sketch.
 */

int trig = 38;
int echo = 36;
int elapsed_time, distance;
int frequency1;
int frequency2;
int frequency3;


void setup() {
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  Serial.begin(9600);
}

void loop() {
    digitalWrite(trig, HIGH); 
    delayMicroseconds(5); 
    digitalWrite(trig, LOW);
    delayMicroseconds(5); 

    elapsed_time = pulseIn(echo, HIGH);
    distance = abs(elapsed_time/2/29.1);
    Serial.println(distance);
    delay(100);
}
ColorArduino
This is sketch for color sensor.
int s0 = 35;
int s1 = 37;
int s2 = 39;
int s3 = 40; 
int out =34;

// Note names for setup() and loop()

void setupColor() {  
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);
  pinMode(out, INPUT);
  
  digitalWrite(s0,HIGH);
  digitalWrite(s1,LOW);
}
void loopColor() {
  digitalWrite(s2,LOW);
  digitalWrite(s3,LOW);

  frequency1 = pulseIn(out, LOW);  // This is value for RED
  Serial.println(frequency1);
  delay(100);

  digitalWrite(s2,HIGH);
  digitalWrite(s3,HIGH);

  frequency2 = pulseIn(out, LOW);  // This is value for GREEN
  delay(100);

  digitalWrite(s2,LOW);
  digitalWrite(s3,HIGH);

  frequency3 = pulseIn(out, LOW);  // This is value for BLUE
  delay(100);
}
LedArduino
int led = 33;

void setupLed() {
  pinMode(led, OUTPUT);
}

void loopLed() {
  // You can set any value here for frequency. 
  // Led will turn on if frequency1 (red) is lower than 60
  // and if distance from ultrasonic sensor is lower than 5cm
  
  if (frequency1 < 60 && 0 < distance && distance <= 5){
    digitalWrite(led, HIGH);
  }
  else{
    digitalWrite(led, LOW);
  }
}

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

Wi-Fi IoT Workshop for TI LaunchPad+Educational BoosterPack
Easy
  • 1,494
  • 122

Full instructions

Get started with some IoT projects. Learn how to use Wi-Fi wireless communication with the TI LaunchPad.

ASEE 2017: TI LaunchPad 4 Student Owned Freshman Experience
Easy
  • 373
  • 2

Protip

Learn how to use low cost student owned hardware for hands on intro courses.

MSP432 Fun with IoT Workshop 2016
Easy
  • 3,450
  • 69

Full instructions

Explore the Educational BoosterPack paired with the MSP432 LaunchPad and then take that to the cloud with the CC3100 Wi-Fi BoosterPack!

MIT IAP 2016 Lab
Easy
  • 1,983
  • 47

A collection of the 6 labs for the MIT IAP Texas Instruments LaunchPad Workshop

Control Your Bot From Anywhere
Easy
  • 64
  • 0

Full instructions

IoT with your robot at one place and your phone another, both connected via internet.

Mongoose Embedded Networking Library on mbed+CC3100
Easy
  • 611
  • 12

Protip

Mongoose, the most popular open source embedded web server and networking library now supports the mbed platform. See CC3100 example.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login