sarful
Published © Apache-2.0

How to build Arduino Rooster Alarm

If you complete this tutorial you can learn How to build Arduino Rooster Alarm step by step complete guide.

BeginnerFull instructions provided1 hour1
How to build Arduino Rooster Alarm

Things used in this project

Hardware components

Arduino uno
×1
light detector
×1
10-kΩ resistors
×2
piezo buzzer
×1
push button
×1
breadboard
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Arduino Rooster Alarm

Code

Arduino Rooster Alarm

Arduino
const int DirectSunlightCutOff = 1023;

const int BrightLightCutOff = 900;

const int MediumLightCutOff = 525;

const int LowLightCutOff = 310;

const int VeryLowLightCutOff = 200;

const int NightCutOff = 100;

int DetectorPin = A0;


int RawValue = 0;


int BuzzerPin = 9;


int BuzzerFreq = 300;

int BuzzerFreqRange = 400;


int NumberRoosterCalls = 5;


int RoosterCallsFinished = false;


int ButtonPin = 7;



boolean AlarmTripped = false;




void setup()
{
 Serial.begin(9600);
 Serial.println("Rooster Alarm ...");
}


void PrintBrightnessLevel(int value)
{
 Serial.print("BrightnessLevel: ");
 if (value <= NightCutOff)
 {
    Serial.print("Night");
 }
 else
 if (value <= VeryLowLightCutOff)
 {
    Serial.print("Very Low Light");
 }
 else
 if (value <= LowLightCutOff)
 {
    Serial.print("Low Light");
 }
 else
 if (value <= MediumLightCutOff)
 {
    Serial.print("Medium Light");
 }
 else
 if (value <= BrightLightCutOff)
 {
    Serial.print("Bright Light");
 }
 else
 {
    Serial.print("Direct Sun Light");
 }
}


void RoosterCall()
{
 for (int i = 0; i < NumberRoosterCalls; 
   i++)
 {
    for (int j = 0; j < BuzzerFreqRange; 
      j++)
    {
       tone(BuzzerPin, BuzzerFreq + j);
       delay(10);
    }
 }
 noTone(BuzzerPin);
 RoosterCallsFinished = true;
}

void ResetSoundConfirmation()
{
 for (int i = 0; i < 5; i++)
 {
    tone(BuzzerPin, BuzzerFreq);
    delay(100);

    noTone(BuzzerPin);
    delay(100);
 }
}

void loop()
{
 // Read Reset Button
 RawValue = digitalRead(ButtonPin);
 if (RawValue == 1)
 {
    ResetSoundConfirmation();
    AlarmTripped = false;
    RoosterCallsFinished = false;
 }

 RawValue = analogRead(DetectorPin);
 PrintBrightnessLevel(RawValue);
 Serial.print(" , RawValue: ");
 Serial.println(RawValue);

 if (RawValue >= VeryLowLightCutOff)
 {
    AlarmTripped = true;
 }

 if (AlarmTripped && !RoosterCallsFinished)
 {
    RoosterCall();
 }
}

Credits

sarful

sarful

56 projects • 30 followers
I am Sarful , I am a Mechatronics Engineer & also a teacher I am Interested in the evolution of technology in the automation industry .

Comments