Tien HerdCharles Daniels
Published

Light Activated Alarm

An alarm clock that goes off when the sun rises

IntermediateFull instructions provided25
Light Activated Alarm

Things used in this project

Hardware components

Argon
Particle Argon
×2
Photo resistor
Photo resistor
×1
Buzzer
Buzzer
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×2
5 mm LED: Red
5 mm LED: Red
×1

Software apps and online services

ThingSpeak API
ThingSpeak API
Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Photoresistor Board

Buzzer Board

Code

Buzzer Code

C/C++
int BuzzerPin = D7;                // Buzzer


void setup() {
    pinMode(BuzzerPin, OUTPUT);
    Particle.subscribe("Group20LightLevels", myHandler);
}

 void myHandler(const char *event, const char *data) {
if (strcmp(data,"Bright")) {
  digitalWrite(BuzzerPin,HIGH);
      delay(1000);
  digitalWrite(BuzzerPin,LOW);
  digitalWrite(BuzzerPin,HIGH);
      delay(1100);
      digitalWrite(BuzzerPin,LOW);
 String Buzzer = String("1");     
 Particle.publish("Group20LightLevels","buzzON", PUBLIC); 
}
else if (strcmp(data,"Medium")) {
  digitalWrite(BuzzerPin,HIGH);
      delay(1000);
  digitalWrite(BuzzerPin,LOW);
  digitalWrite(BuzzerPin,HIGH);
      delay(1100);
      digitalWrite(BuzzerPin,LOW);
 String Buzzer = String("1");     
 Particle.publish("Group20LightLevels","buzzON", PUBLIC); 
}
    else {
        digitalWrite(BuzzerPin, LOW);
        digitalWrite(BuzzerPin, LOW);
        String Group20LightLevels = String("0");
        Particle.publish("Group20LightLevels","buzzOFF", PUBLIC);
    }
}    

Photo-Sensor Code

C/C++
int led = D0;
int photoresistor = A0;
int power = A5;
int analogvalue; 

    

unsigned long myChannelNumber = 1247607;		/*Thingspeak channel id*/
const char * myWriteAPIKey = "TSHI95ZO5S0GKRHO";/*Channel's write API key*/

    
void loop() {
    analogvalue = analogRead(photoresistor);
    delay(500);

    if(analogvalue > 601) { // If it is bright... 
       Particle.publish("Group20LightLevels","Bright", PUBLIC);
       
        digitalWrite(led,HIGH);
        delay(4000);
        //delay(900000);
	}
  else if(analogvalue > 451 && analogvalue < 600) { // If it is average light... 
       Particle.publish("Group20LightLevels","Medium", PUBLIC);
        digitalWrite(led,HIGH);
        delay(4000);
        //delay(900000);
  }
       else { // If it's dark... 
        Particle.publish("Group20LightLevels","Dark", PUBLIC);
        digitalWrite(led,LOW);
        delay(4000);
        //delay(900000);
       }}
     
    
    

Credits

Tien Herd

Tien Herd

1 project • 1 follower
Mechanical Engineering Student UNCC
Charles Daniels

Charles Daniels

1 project • 1 follower
Mechanical Engineering Student at UNCC

Comments

Add projectSign up / Login