Because I'm a very music-oriented person, it was important for me to be able to listen to music throughout the day; however, as the youngest person in a household of 4, it was important for me to have my speakers at certain volumes throughout the day. Thus, this creation was born.This project was part of Lane Tech HS's Physical Computing Lab course. I created it as part of the Home Automation project.
CircuitryThe circuitry of this project is fairly simple. Because the knob on my speakers uses rotational energy to move, I simply needed a continuous servo. The servo is connected to digital pin D8. The power is connected to the VUSB pin on the Argon and the ground is connected to the ground rail on the breadboard.
A schematic of the circuitry can be found below.
To house the continuous servo, I utilized an old cardboard box, which used to contain a refurbished mouse that I bought a year or two ago. I simply cut a servo-sized hole into the box so that it nests comfortably in the box's side.
In order to turn the physical knob of my speaker, I attached a rubber band to the servo that stretched to the knob. The tension of the rubber band is enough grip to turn the knob when the servo turns, transferring its mechanical energy.
Before any programming, add the SparkTime library to your program.
The following line should now be in your code:
#include <SparkTime.h>
After adding the library, you can begin setup. Create your Servo object and set the pin your servo is connected to as a constant integer. In addition, create a integer variable to default your speaker's volume to. I chose to default it to an off position.
// set up servo object and pin
Servo myServo;
const int servoPin = D8;
// speaker volume setting variable
int isAudible = 0;
In the setup function, start your serial monitor, attach the servo to the pin you specified prior, and set your timezone. Since I am in Chicago, I set the timezone to CDT. To tailor to your timezone, switch out -5 with the number after UTC that designates your timezone.
void setup() {
// start up serial monitor
Serial.begin(9600);
// attach servo to D8 pin
myServo.attach(servoPin);
// set timezone
Time.zone(-5);
}
In the loop function, make an if statement that makes the loop function activate only once every 2 minutes. Inside the if statement, return the current hour and print it to the serial monitor. Two nested if statements will now be created: one for the hours which I want my speaker off and one for the hours I want my speaker volume on. In both, simply program the continuous servo to turn and change the boolean variable that holds the state of the volume knob. I included a line to print the boolean variable to my serial monitor; this may be omitted.
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);
}
ResultWhen you are finished, the volume knob on your speakers should turn based on your own parameters.
Your serial monitor will look like so:
Comments
Please log in or sign up to comment.