edge lab LIVE! starts Tuesday in Munich. Grab a workshop seat and take home the board you build on. Code FRIEND-HACKSTER saves 20%. () Learn more!

LEDefense

Fear no more! With our inescapable and blinding LEDefense Alarm System, burglars won't ever trespass again.

BeginnerFull instructions provided509
LEDefense

Things used in this project

Hardware components

EK-TM4C123GXL TM4C Tiva LaunchPad
Texas Instruments EK-TM4C123GXL TM4C Tiva LaunchPad
×1
Breadboard (generic)
Breadboard (generic)
×1
Photo resistor
Photo resistor
×1
LED, RGB
LED, RGB
×1
Tilt Switch, SPST
Tilt Switch, SPST
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×8

Software apps and online services

Energia
Texas Instruments Energia
Arduino IDE
Arduino IDE

Story

Read more

Schematics

LEDefense Schematics

Code

LEDefense

Arduino
// maps analogPin to PE3
int analogPin = 29;

// mapping Red to PD6, Green to PD7, blue to PF4
int RED = 33, GREEN = 32, BLUE = 31;

// initializing values for LED
int redVal;
int greenVal;
int blueVal;
int delayTime = 5;

void setup()
{
  // sets up pin mode for photoresistor.
  Serial.begin(9600); // initialize serial communication for photoresistor
  pinMode(analogPin, OUTPUT);

  // sets up pinMode for LED
   pinMode(RED, OUTPUT);
   pinMode(GREEN, OUTPUT);
   pinMode(BLUE, OUTPUT);
}


void loop()
{
  int lightLevel = analogRead(analogPin); // Read the light level
  int MAX_RES = 255; // this variable will hold our resolution.
  Serial.println(lightLevel); // Print the analog value to Serial (used to test sensor)

  // default mode is off, unless triggered by moving person
   int greenVal = MAX_RES; // max voltage will give us no color
   int blueVal = MAX_RES;
   int redVal = MAX_RES;
   analogWrite( RED, redVal );
   analogWrite( GREEN, greenVal );
   analogWrite( BLUE, blueVal ); 

     // the darker the environment, the greater the reading
    if (lightLevel > 570) {


      // Turns on the rainbow LED
      for (int i; i < 2; i += 1){
    
         // begins as full red
         int redVal = 0; 
         int greenVal = MAX_RES;
         int blueVal = MAX_RES; 
         analogWrite( RED, redVal );
         analogWrite( GREEN, greenVal );
         analogWrite( BLUE, blueVal );
        
         // Changes from red to green
         for( int i = 0 ; i < MAX_RES ; i += 1 ){
           greenVal -= 1;
           redVal += 1;
           analogWrite( RED, redVal ); // sets to redVal
           analogWrite( GREEN, greenVal ); // sets to greenVal
          
           delay( delayTime ); // wait for how long delay time is
         }
        
         // changes to full green
         redVal = MAX_RES; 
         greenVal = 0; 
         blueVal = MAX_RES; 
         analogWrite( RED, redVal );
         analogWrite( GREEN, greenVal );
         analogWrite( BLUE, blueVal );
      
         // Change from green to blue 
         for( int i = 0 ; i < MAX_RES ; i += 1 ){
           blueVal -= 1;
           greenVal += 1;
           analogWrite( BLUE, blueVal ); // sets blueVal
           analogWrite( GREEN, greenVal ); // sets greenVal
          
           delay( delayTime ); // wait for how long delay time is
         }
        
         // changes to full blue.
         redVal = MAX_RES; 
         greenVal = MAX_RES; 
         blueVal = 0; 
         analogWrite( RED, redVal );
         analogWrite( GREEN, greenVal );
         analogWrite( BLUE, blueVal );
      
         // fade from blue to red 
         for( int i = 0 ; i < MAX_RES ; i += 1 ){
           redVal -= 1;
           blueVal += 1;
           analogWrite( RED, redVal ); // sets redVal
           analogWrite( BLUE, blueVal ); // sets blueVal
          
           delay( delayTime ); // wait for how long delay time is
      }
    }
  }
  delay(100); // delay for 0.1 seconds
 }

LEDetector

Credits

Anna Bai
3 projects • 0 followers
Charles Lussier
1 project • 0 followers
Vivian Ellis
1 project • 0 followers
Jaime Samojedny
1 project • 0 followers
Alex Prucka
3 projects • 1 follower
Gavin Zhang
1 project • 0 followers
Thomas Yeum
1 project • 0 followers
Rambod Azarbad
0 projects • 0 followers

Comments