Created
January 14, 2012 01:08
-
-
Save atamis/1609690 to your computer and use it in GitHub Desktop.
Arduino volume monitor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int analogPin = 0; // potentiometer wiper (middle terminal) connected to analog pin 3 | |
// outside leads to ground and +5V | |
int writePin1 = 2; | |
int writePin2 = 3; | |
int writePin3 = 4; | |
int writePin4 = 5; | |
int writePin5 = 6; | |
int writePin6 = 7; | |
int val = 0; // variable to store the value read | |
int threshold1 = 512; | |
int threshold2 = 500; | |
int threshold3 = 480; | |
int threshold4 = 460; | |
int threshold5 = 440; | |
int threshold6 = 420; | |
// 512 is the average for "silence" | |
// 511 is the average for "noise" | |
double thermister(int raw) { | |
double temp; | |
temp = log(((10240000/raw) - 10000)); | |
temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * temp * temp ))* temp ); | |
temp = temp - 273.15; // Convert Kelvin to Celcius | |
temp = (temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit | |
return temp; | |
} | |
void setup() { | |
Serial.begin(9600); // setup serial | |
} | |
void loop() { | |
val = analogRead(analogPin); // read the input pin | |
if (val < threshold1) { digitalWrite(writePin1, HIGH); } else { digitalWrite(writePin1, LOW); } | |
if (val < threshold2) { digitalWrite(writePin2, HIGH); } else { digitalWrite(writePin2, LOW); } | |
if (val < threshold3) { digitalWrite(writePin3, HIGH); } else { digitalWrite(writePin3, LOW); } | |
if (val < threshold4) { digitalWrite(writePin4, HIGH); } else { digitalWrite(writePin4, LOW); } | |
if (val < threshold5) { digitalWrite(writePin5, HIGH); } else { digitalWrite(writePin5, LOW); } | |
if (val < threshold6) { digitalWrite(writePin6, HIGH); } else { digitalWrite(writePin6, LOW); } | |
Serial.println(val); // debug value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment