Instructables

TV Volume Loudness Guard using Arduino

Featured

Step 4: PREPARE THE ARDUINO PROGRAM

Picture of PREPARE THE ARDUINO PROGRAM
At the top of the Arduino program below there is a number of lines starting with #define LABEL NUMBER This is to make it easier to control how the program behaves.  The LABEL is the thing you want to control in the program behavior and the NUMBER is the value of the thing you want to control. Here's an explanation of the relevant #define lines. 

REMOTE BUTTON CODE & BIT

#define REMOTE_CODE  Your remote code as returned by the IRrecvDump decoder utility prefixed with "0x"
#define REMOTE_BIT   Your remote code data size as returned by the IRrecvDump decoder utility.

This Arduino program works for most remote controls but you need to tell it about your remote control protocol from the info you gathered in the previous step when you decoded your remote control buttons using IRrecvDump utility.  It's possible to make the remote selection dynamic during run time so you don't have to change and upload code. I might do this in a later version of this gadget.

VOLUME LEVEL THRESHOLD

#define NOISE_LEVEL A number from 0 to 1024. Start with 500 then fine-tune the number.

This is the number that decides at what point the Arduino will start transmitting Volume Down codes

NOTE: The sound sensor I am using as a built-in potentiometer which also controls the sensor's sensitivity. 

VOLUME CHANGE SPEED

#define REPEAT_TX (from 1 to as many as you want. Start with 3 then fine tune)

Change how many times you want  the remote code transmitted to the TV. If you want more drastic drop in TV volume increase this number. If you want a more gradual change in volume, lower this number.

FEATURE TODO LIST

It's very simple to program more functionality into this gadget. Some of the features that can be added:
  • Average audio level over a period of time to determine if increase in volume is persistent requiring volume control or momentary and should be ignored.
  • Read audio level after a period of time. If audio is too low, increase volume by a certain increment. 
  • Make program inclusive of supported remote protocols 
  • Add Panasonic & JVC support

THE ARDUINO CODE

Cut and paste the code below into your Arduino IDE



//=================================================

/*
PROJECT: TV Volume Guard
AUTHOR: Hazim Bitar (techbitar)
DATE: FEB 9, 2013
CONTACT: techbitar at gmail dot com
LICENSE: My code is in the public domain.          
IRremote library: copyright by Ken Shirriff http://arcfn.com

*/

#include <IRremote.h>


#define NOISE_LEVEL      350  // level of noise to detect from 0 to 1023
#define REPEAT_TX         3 // how many times to transmit the IR remote code
#define REMOTE_CODE     0x1CE3E817  // remote code to transmit. This is for my TV. Replace with yours. 
#define REMOTE_BIT   32

#define SOUND_SENSOR_PIN     A0 // sound sensor connected to this analog pin
#define LED        13      // LED used to blink when volume too high

IRsend irsend; // instantiate IR object

void setup()
{
  pinMode(LED, OUTPUT);
}

void loop()
{
  int soundLevel = analogRead(SOUND_SENSOR_PIN); // read the sound sensor
  if(soundLevel > NOISE_LEVEL) // compare to noise level threshold you decide
  {
    digitalWrite(LED,HIGH);  // LED on
    delay(200);
    for (int txCount = 0; txCount < REPEAT_TX; txCount++) { // how many times to transmit the IR remote  code
      irsend.sendNEC(REMOTE_CODE , REMOTE_BIT); // Change to match your remote protocol
      delay(200);

      // Uncomment the function that matches your remote control protocol as shown by IRrecvDump
      // irsend.sendNEC(REMOTE_CODE, REMOTE_BIT);
      // irsend.sendSony(REMOTE_CODE, REMOTE_BIT);
      // irsend.sendRC5(REMOTE_CODE, REMOTE_BIT);
      // irsend.sendRC6(REMOTE_CODE, REMOTE_BIT);

    }
  }
  digitalWrite(LED,LOW); // LED off
}

//=================================================
 
Remove these adsRemove these ads by Signing Up
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!