wojosarah
Published © GPL3+

Light Sensor Activated Alarm Pillow

Phone alarm not quite right and need a better way to waken? Use an alarm pillow for a personalized, wake-up-to-the-sun experience!

BeginnerShowcase (no instructions)963
Light Sensor Activated Alarm Pillow

Things used in this project

Hardware components

LilyPad ProtoSnap Plus
SparkFun LilyPad ProtoSnap Plus
×1
LilyPad Vibe Board
SparkFun LilyPad Vibe Board
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Conductive Thread
Needle
Pillowcase or Pillow

Story

Read more

Schematics

Close Enough Schematic

Code

Alarm Pillow Code

Arduino
// Create variables for the pins we'll be using

int lightSensor = A9;
int buzzer = A5;
int motor = A7;
int RGB_red = 12;
int RGB_green = 13;
int RGB_blue = 14;

// Set the frequency and threshold

int mainFrequency = 740; //F#4
int tempo = 200;
int threshold = 5;

void setup()
{
  int x;

  // Initialize the pins we'll be using
  
  pinMode(lightSensor, INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(motor, OUTPUT);
  pinMode(RGB_red, OUTPUT);
  pinMode(RGB_green, OUTPUT);
  pinMode(RGB_blue, OUTPUT);

  // Initialize the serial monitor

  Serial.begin(9600);
}

void loop()
{
  int sensorValue;
  int frequency;


  int x,lightLevel,brightness;

  // Read the sensor value (will be 0 to 255):

  lightLevel = analogRead(lightSensor);

  // Print out the sensor reading:

  Serial.print("light level: ");
  Serial.print(lightLevel);
  Serial.print(" threshold: ");
  Serial.print(threshold);
  Serial.print(" sensor value: ");
  Serial.println(sensorValue);


 if (lightLevel > threshold) // If it is lighter than the threshold:
  {
     digitalWrite(RGB_red, HIGH);
     digitalWrite(RGB_green, HIGH);
     digitalWrite(RGB_blue, HIGH);
     digitalWrite(motor, HIGH);
     tone(buzzer,mainFrequency);
     delay(tempo);

     digitalWrite(RGB_red, LOW);
     digitalWrite(RGB_green, LOW);
     digitalWrite(RGB_blue, LOW);
     digitalWrite(motor, LOW);
     noTone(buzzer);
      delay(tempo*2);

     digitalWrite(RGB_red, HIGH);
     digitalWrite(RGB_green, HIGH);
     digitalWrite(RGB_blue, HIGH);
     digitalWrite(motor, HIGH);
     tone(buzzer,mainFrequency);
     delay(tempo);

     digitalWrite(RGB_red, LOW);
     digitalWrite(RGB_green, LOW);
     digitalWrite(RGB_blue, LOW);
     digitalWrite(motor, LOW);
     noTone(buzzer);
     delay(tempo*2);


    
  }
  else
  {
    noTone(buzzer);
     
  }
}

Credits

wojosarah

wojosarah

0 projects • 0 followers

Comments