Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!

Photosynthesis Detection System

Save the Earth with this light detector which measures and displays the light intensity in an environment.

IntermediateFull instructions provided997
Photosynthesis Detection System

Things used in this project

Hardware components

EK-TM4C123GXL TM4C Tiva LaunchPad
Texas Instruments EK-TM4C123GXL TM4C Tiva LaunchPad
×1
Grove Starter Kit for LaunchPad
Seeed Studio Grove Starter Kit for LaunchPad
×1
Grove - Light Sensor
Seeed Studio Grove - Light Sensor
×1
Seeed Studio Grove - 4-Digit Display
×1
SparkFun 4 Pin RGB LED
×1

Software apps and online services

Energia
Texas Instruments Energia

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Schematics

Light Detector System Diagram

Code

Light Detector System

C/C++
Use a TM4C Tiva Launchpad to create a light detector system that detects the amount of light in an area, displays the value of light as numbers on a 4-Digit Display and as colors on an RGB LED.
/*
 Light Detection System

 A simple program that displays the value of light from the Grove Light Sensor on the Grove 4-Digit Display and turns the RGB LED a specific color depending on the value of light
 
 The circuit:
 * 4-Digit Display attached to Pin 38 and 39 (J14 plug on Grove Base BoosterPack)
 * Light Sensor attached to Pin 24 (J6 plug on Grove Base BoosterPack)
 * RGB LED connected to pins defined below
*/

//4-Digit Display library
#include "TM1637.h" 

/* Macro Define */
#define CLK               39                  /* 4-Digit Display clock pin */
#define DIO               38                 /* 4-Digit Display data pin */
#define LIGHT_SENSOR      24                 /* pin connected to the Light Sensor */

/* Global Variables */
TM1637 tm1637(CLK, DIO);                  /* 4-Digit Display object */
int analog_value = 0;      
int new_value = 0;
/* variable to store the value coming from Light Sensor */
int8_t bits[4] = {0};                     /* array to store the single digits of the value */



 /*

 Hardware Required for RGB LED Section
 * TI LaunchPad
 * Breadboard BoosterPack
 * Breadboard
 * RGB LED
 * 4x Jumper Wires

*/

// Connect Anode pin to VCC
// Connect Red to pin 19 which should be PWM capable
// Connect Green to pin with PWM
// Connect Blue to pin with PWM

#define RED 19 // pin 19 is always PWM capable according to LaunchPad standard
#define GREEN 18 // may need to change this for your LaunchPad
#define BLUE 11 // may need to change this for your LaunchPad
#define delayTime 10 // delay between color changes, 10ms by default

int redVal;
int greenVal;
int blueVal;


void setup() 
{
  /* Initialize 4-Digit Display */
  tm1637.init();
  tm1637.set(BRIGHT_TYPICAL);

  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);

}


void loop() 
{
  analog_value = analogRead(LIGHT_SENSOR);        /* read the value from the sensor */
  int PWM_RESOLUTION = 255; // this variable will hold our resolution.
  memset(bits, 0, 4);                             /* reset array before we use it */
  for(int i = 3; i >= 0; i--) 
  {
    /* Convert the value to individual decimal digits for display */
    bits[i] = analog_value % 10;
    analog_value = analog_value / 10;  
    tm1637.display(i, bits[i]);    
  }
      //analog_value = analog_value*10;
    
  if(bits[0]>=2) // bright - red
  {
    int redVal = 0; // zero voltage will give us full color
    int blueVal = PWM_RESOLUTION; // max voltage will give us no color
    analogWrite( RED, redVal );
    analogWrite( BLUE, blueVal );
  }

  else if(bits[0]>=1) // middle - purple
  {
    int redVal = PWM_RESOLUTION/2; // half voltage gives us half color
    int blueVal = PWM_RESOLUTION/2; // half voltage gives us half color
    analogWrite( RED, redVal );
    analogWrite( BLUE, blueVal );
  }


  else // dark - blue
  {
    int redVal = PWM_RESOLUTION; // max voltage will give us no color
    int blueVal = 0; // zero voltage will give us full color
    analogWrite( RED, redVal );
    analogWrite( BLUE, blueVal );
  }

 
  delay(100);  //small delay so that the number doesn't change too quickly to read
 
}

Credits

Julia Coyner

Julia Coyner

1 project • 0 followers
Kelly Park

Kelly Park

1 project • 0 followers
Nikhita Gangla

Nikhita Gangla

1 project • 0 followers
Fernanda Lago

Fernanda Lago

2 projects • 0 followers
Nikhita Gangla

Nikhita Gangla

2 projects • 1 follower

Comments