Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Ethan Pizarro
Published © GPL3+

Lane Tech HS - PCL - Automatic Speaker Volume

Adjusts the volume of my speakers automatically depending on the time of day.

BeginnerFull instructions provided1 hour115
Lane Tech HS - PCL - Automatic Speaker Volume

Things used in this project

Hardware components

Jumper wires (generic)
Jumper wires (generic)
×1
Argon
Particle Argon
×1
Breadboard (generic)
Breadboard (generic)
×1
DS04-NFC 360 Degree Continuous Rotation Servo
×1

Story

Read more

Schematics

Automatic Speaker Volume Adjustment Schematic

Code

Automatic Speaker Volume Adjustment Code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <SparkTime.h>

// set up servo object and pin
Servo myServo;
const int servoPin = D8;

// speaker volume setting variable
int isAudible = 0;

void setup() {
    // start up serial monitor
    Serial.begin(9600);
    
    // attach servo to D8 pin
    myServo.attach(servoPin);
    
    // set timezone
    Time.zone(-5);
}

void loop() {
    // grab current hour
    int currentHour = Time.hour();
    // grab current minute
    int currentMinute = Time.minute();
    
    // print current hour and minute
    Serial.print("Current hour: ");
    Serial.println(currentHour);
    Serial.print("Current minute: ");
    Serial.println(currentMinute);
    
    if (currentMinute % 2 == 0)
    {
        if (currentHour > 21 && currentHour < 8 && isAudible == 1)
        {
            // rotate counterclockwise full speed
            myServo.write(135);
            delay(1000);
            // stop
            myServo.write(90);
            delay(500);
            
            // record state of speaker volume
            isAudible = 0;
        }
        if (currentHour >= 8 && currentHour <= 21 && isAudible == 0)
        {
            // rotate clockwise full speed
            myServo.write(45);
            delay(1000);
            // stop
            myServo.write(90);
            delay(500);
            
            // record state of speaker volume
            isAudible = 1;
        }
    }
    
    // print current logged state of speaker volume
    Serial.print("Is the speaker audible? ");
    Serial.println(isAudible);
    
    // wait 5 seconds for separate serial monitor prints
    delay(5000);
}

Credits

Ethan Pizarro
3 projects • 3 followers
Contact

Comments

Please log in or sign up to comment.