Mission 16 - Change in Light Level Alarm
 DuinoKit Jr. - View Only. See new "Mission Manual" forum for manual and code   Started by Daniel Alich   2017-06-27 17:50:46 -04:00   Comments: 1    Viewed: 905

  1. Daniel Alich
    Daniel Alich Member Staff Member
    252_1498600209_Mission 16-1.jpg

    252_1498600196_Mission 16-2.jpg

    /*
    Wiring Guide - Based on DuinoKit

    NANO D13 -> Piezo Buzzer (+)
    Piezo Buzzer (-) -> NANO GND
    NANO A0 -> CDS Cell (Center Pin)
    CDS Cell (Resistor side) -> GND
    CDS CEll (CDS Cell Side) -> NANO 5V

    These constants describe the pins. They won't change:
    */
    int i; // Declare Variables
    int analog0;
    int CurrentValue;
    int Senstivity = 10; // Change in light level adjustment
    // Lower numbers make device more sensitive
    void setup()
    {
    Serial.begin(9600); // initialize the serial communications:
    pinMode(13, OUTPUT); // Buzzer alarm on Pin 13
    for(i=0; i < 5; i++) // Take i readings of A0 pin
    {
    delay (100); // Place a small delay between reading
    analog0=analog0+analogRead(A0);
    }

    analog0=analog0/i; // Divide by i to get average integer A0 value
    CurrentValue=analog0; // set initial reading and analog value the same

    }

    void loop()
    {
    analog0=0;
    for(i=0; i < 5; i++) // Take i readings of A0 pin
    {
    delay (10); // Small delay between readings
    analog0=analog0+analogRead(A0); // Add up total of i readings
    }

    analog0=analog0/i; // Divide by i to get average integer A0 value

    Serial.println(analog0); // Display current light levels in serial monitor
    delay(10);

    if(abs(analog0-CurrentValue)>Senstivity) { // If change in light level >5, sound alarm
    Serial.print(analog0); // Display readings in Serial monitor
    Serial.print("t");
    Serial.print(CurrentValue);
    Serial.print("t");
    Serial.println("ALARM");
    CurrentValue=analog0;
    digitalWrite(13, HIGH); // Turn on alarm buzzer on pin 13
    delay(100);
    }
    else{
    CurrentValue=analog0; // if change is <5, then take the new reading as current light level.
    digitalWrite(13, LOW); // Turn off buzzer on pin 13

    }
    }




    Daniel Alich, 2017-06-27 17:50:46 -04:00
  2. (You must log in or sign up to post here)

Report Post

Write your reason

Log in | Sign up
Terms & Conditions!
Help!