Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 2 | ||||
Hand tools and fabrication machines | ||||||
| ||||||
|
I have an old zenith Radio.
I'm using an Amazon Echo device for audio but I'd like the radio to light up when there is sound emanating from the Echo. This circuit and code triggers an LED within the radio to light up the dial and stay lit until the audio stops. After 10 seconds of silence the dial light turns off. It also mimics a feature on the radio called a tuning eye however instead of indicating signal strength the light mimics the audio amplitude.
#define LED_ON_TIME 10000ul //10000mS == 10-seconds
#define LED_OFF 0
#define LED_ON 1
int pinOut = 4;
int led = 8;
int DogBark = 0;
const byte pinSensor = 2; //whatever pin you're using...
const byte pinLED = LED_BUILTIN;
unsigned long
timeLED,
timeNow,
timeIDOL,
totaltime;
byte
stateLED;
void setup()
{
Serial.begin( 9600 );
pinMode( pinSensor, INPUT ); //INPUT_PULLUP if device is OC
pinMode( 4, OUTPUT );
pinMode (8, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
stateLED = LED_OFF;
}//setup
void loop()
{
timeNow = millis();
if( digitalRead( pinSensor ) == HIGH )
{
digitalWrite(led, HIGH); // Eye Light on
}
switch( stateLED )
{
case LED_OFF:
if( digitalRead( pinSensor ) == HIGH )
{
DogBark++;
if( DogBark == 1 )
{
timeIDOL = timeNow;
}
Serial.println((int)DogBark); // Sharp instances of sound that may trigger the dial light are filered out, only a couple of "barks" per time IDOL seconds.
if( DogBark >= 100 ) // Adjust microphone sensativity when playing music, Suggest Setting Echo volume to 3 or 4 when tuning
//yes; turn on LED and set timer
{
DogBark = 0;
digitalWrite( pinLED, HIGH );
timeLED = timeNow;
//then move to ON state
stateLED = LED_ON;
digitalWrite(pinOut, HIGH);
}
}//if
break;
case LED_ON:
//whenever sensor shows high, reset LED on timer
if( digitalRead( pinSensor ) == HIGH )
{
timeLED = timeNow;
totaltime = timeNow - timeLED;
digitalWrite(pinOut, HIGH);
}
//when ontime has expired, turn off
if( timeNow - timeLED >= LED_ON_TIME )
{
digitalWrite( pinLED, LOW );
digitalWrite(pinOut, LOW);
stateLED = LED_OFF;
}//if
break;
}//switch
digitalWrite(led, LOW); // Eye Light off
if( timeNow - timeIDOL >= LED_ON_TIME )
{
DogBark = 0;
}
}//loop
Comments