Tahani Almanie
Published

Lighted Hat

A hat that lightens in the darkness based on the reading value from a light sensor.

BeginnerFull instructions provided618
Lighted Hat

Things used in this project

Hardware components

Lilypad Arduino Development Kit
SparkFun Lilypad Arduino Development Kit
×1
hat
×1

Hand tools and fabrication machines

SparkFun Alligator Test Leads
30AWG Wire Wrapping
SparkFun Wire Strippers
Felt
Hot glue gun (generic)
Hot glue gun (generic)
Needle-Threads-Scissors

Story

Read more

Schematics

circuit diagram

Code

Lighted Hat

Arduino
/*
Lighted Hat

This code makes a light pattern using 4 LEDs. The light is only turned on in the darkness 
which is detected by the reading value from a light sensor.

Tahani Almanie

*/

int lightSensorPin = A3;  // The light sensor is connected to the analog pin A3
int lightValue;           // This variable holds the light sensor readings
const int darkValue = 30; // This variable determins when we turn on the light pattern

int led1Pin = 5;          // First LED is connected to the digital pin 5
int led2Pin = 6;          // Second LED is connected to the digital pin 6 
int led3Pin = 9;          // Third LED is connected to the digital pin 9 
int led4Pin = 10;         // Fourth LED is connected to the digital pin 10 

void setup()
{
  // Set sensorPin as an INPUT
  pinMode(lightSensorPin, INPUT);
  
  // Set LEDs as outputs
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(led3Pin, OUTPUT);
  pinMode(led4Pin, OUTPUT);
  
  //Start the serial connection to view the sensor readings
  Serial.begin(9600);
}

void loop()
{
  //get the reading from the light sensor
  lightValue = analogRead(lightSensorPin);
  
  // print out the reading value 
  Serial.println(lightValue);
  
  // check the darkness value
  if (lightValue <= darkValue) 
  { 
    // turn on the light pattern
    digitalWrite(led1Pin, HIGH); 
    delay(150);
    digitalWrite(led1Pin, LOW); 
    delay(150);
    
    digitalWrite(led2Pin, HIGH); 
    delay(150);
    digitalWrite(led2Pin, LOW); 
    delay(150);
    
    digitalWrite(led3Pin, HIGH); 
    delay(150);
    digitalWrite(led3Pin, LOW); 
    delay(150);

    digitalWrite(led4Pin, HIGH); 
    delay(150);
    digitalWrite(led4Pin, LOW); 
    delay(150);  
  }
   
}

Credits

Tahani Almanie
3 projects • 4 followers
Contact
Thanks to Sparkfun Tutorial.

Comments

Please log in or sign up to comment.