Dear Friends,
I have made a complete stereo amplifier control with Arduino Mega with following features:
1. IR and manual input selector 4 INPUTS
2. IR and manual VOLUME control
3. IR and manual POWER ON/OFF
4. Soft start and Speaker protect circuit
5. Temperature sensed FAN ON/OFF with speaker off if too hot
6. Cool LCD display of Input mode, temperatures of both channels and status with warning
7. LED display of faulty conditions with flashing speed
8. Main PCB + 5 key input PCB with component layout in expressPCB
The components used are:
1. 4 channel Input selector from theaudiocrafts -
theaudiocrafts
2. Motorized Alps pot from the above dealer
3. Arduino Mega with LCD display from Sainsmart
4. Input keys micro switches with cap from Mx
5. IR - TSOP 48386.
6. 12V DC Fan
7. Remotes as mentioned in my previous post
The photos I have shown are of the prototype and not the final product. The Arduino Mega with LCD display to be attached to the front panel with keyboard. The soft start module and input selector are to be attached to the back panel.
If any needs the .pcb files on expressPCB, I would be happy to email them.
I will be posting one more IR related project i.e. control of the entire Music system including Home theatre and LCD Projector , fan and light control with the same Remote so you can completely relax with a set of remotes, a mug of cold beer or whatever, a packet of snacks. And enjoy the music!
#include <IRremote.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
#define ONE_WIRE_BUS 50
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress L_temp = { 0x22, 0xFB, 0x10, 0x2C, 0x00, 0x00, 0x00, 0x01 };
DeviceAddress R_temp = { 0x22, 0x74, 0x19, 0x2C, 0x00, 0x00, 0x00, 0x3C };
// Arduino Mega pins 21,23,25 motor up; 27,29,31 motor down
// Arduino Mega pins 36 to LED; pin 49 to IR sensor; +5v and GND pins to sensor and GND pin to LED
int RECV_PIN = 49;
long oldValue; // This value will save the last meaningful remote input and reuse it in the case of a repeat
int volDelay = 175; //this value can be changed to move volume for longer increments
const int CD_BUTTON = 37;
const int TUNER_BUTTON = 39;
const int TV_BUTTON = 41;
const int MP_BUTTON = 43;
const int CD_RLY = 38;
const int TUNER_RLY = 40;
const int TV_RLY = 42;
const int MP_RLY = 44;
const int SPK_IN_L = 22;
const int SPK_IN_R = 24;
const int PWR_BUTTON = 34;
const int LED = 36;
const int SPK_RLY_L = 26;
const int SPK_RLY_R = 28;
const int FAN_RLY = 30;
const int PWR_RLY = 32;
const int SUBPH_BUTTON = 46;
const int SUBPH_RLY = 48;
int tempC = 0;
int LTemp = 0;
int RTemp = 0;
int SPK_R_VAL = 0;
int SPK_L_VAL = 0;
int CD_VAL = 0;
int CD_OLDVAL = 0;
int CD_STATE = 0;
int TUNER_VAL = 0;
int TUNER_OLDVAL = 0;
int TUNER_STATE = 0;
int TV_VAL = 0;
int TV_OLDVAL = 0;
int TV_STATE = 0;
int MP_VAL = 0;
int MP_OLDVAL = 0;
int MP_STATE = 0;
int PWR_VAL = 0;
int PWR_OLDVAL = 0;
int PWR_STATE = 0;
int SUBPH_VAL = 0;
int SUBPH_OLDVAL = 0;
int SUBPH_STATE = 0;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup(void) {
lcd.clear();
lcd.begin(16,2);
lcd.setCursor(0,1);
lcd.print("Spkr:OFF");
lcd.setCursor(9,1);
lcd.print("Pwr:OFF");
sensors.begin(); // starts temp sensors
Serial.begin(9600); // starts serial port
irrecv.enableIRIn(); // Start the IR receiver
pinMode(21,OUTPUT);
pinMode(23,OUTPUT); //setting power to motor pins for 5v output
pinMode(25,OUTPUT);
pinMode(27,OUTPUT);
pinMode(29,OUTPUT); //setting power to motor pins for 5v output
pinMode(31,OUTPUT);
MotorOff();
pinMode(CD_RLY, OUTPUT);
pinMode(TUNER_RLY, OUTPUT);
pinMode(TV_RLY, OUTPUT);
pinMode(MP_RLY, OUTPUT);
pinMode(PWR_RLY, OUTPUT);
pinMode(SPK_RLY_L, OUTPUT);
pinMode(SPK_RLY_R, OUTPUT);
pinMode(SUBPH_RLY, OUTPUT);
pinMode(CD_BUTTON, INPUT);
pinMode(TUNER_BUTTON, INPUT);
pinMode(TV_BUTTON, INPUT);
pinMode(MP_BUTTON, INPUT);
pinMode(PWR_BUTTON, INPUT);
pinMode(SPK_IN_R, INPUT);
pinMode(SPK_IN_L, INPUT);
pinMode(SUBPH_BUTTON, INPUT);
//pinMode(AC_IN, INPUT);
digitalWrite(CD_RLY, LOW);
digitalWrite(TUNER_RLY, LOW);
digitalWrite(TV_RLY, LOW);
digitalWrite(MP_RLY, LOW);
digitalWrite(PWR_RLY, LOW);
digitalWrite(SPK_RLY_L, LOW);
digitalWrite(SPK_RLY_R, LOW);
digitalWrite(SUBPH_RLY, LOW);
}
void loop(void) {
// check for IR power ON
if (irrecv.decode(&results)) {
if (results.value == 4105841032) {
lcd.setCursor(13, 1);
lcd.print(" ");
PWR_STATE = 1- PWR_STATE; delay(100);
PWR_OLDVAL = PWR_STATE;
if (PWR_STATE == 1) {
PWR_Press();
} else {
PWR_OFF();
}
irrecv.resume(); // Receive the next value
}
} else {
// check for PWR press
PWR_VAL = digitalRead(PWR_BUTTON);
if (PWR_VAL == HIGH) {
lcd.setCursor(13, 1);
lcd.print(" ");
PWR_STATE = 1- PWR_STATE; delay(100);
PWR_OLDVAL = PWR_STATE;
if (PWR_STATE == 1) {
PWR_Press();
} else {
PWR_OFF();
}
}
}
//check spkr volt
SPK_R_VAL = digitalRead(SPK_IN_R);
if (SPK_R_VAL == LOW) {
digitalWrite(SPK_RLY_R, LOW);
lcd.setCursor(0, 1);
lcd.print("SpkR:OFF");
LED_FLASH_500();
} else {
digitalWrite(SPK_RLY_R, HIGH);
lcd.setCursor(0, 1);
lcd.print("SpkR:ON ");
LED_ON();
}
SPK_L_VAL = digitalRead(SPK_IN_L);
if (SPK_L_VAL == LOW) {
digitalWrite(SPK_RLY_L, LOW);
lcd.setCursor(0, 1);
lcd.print("SpkL:OFF");
LED_FLASH_500();
} else {
digitalWrite(SPK_RLY_L, HIGH);
lcd.setCursor(0, 1);
lcd.print("SpkL:ON ");
LED_ON();
}
if (PWR_STATE == HIGH) {
if (irrecv.decode(&results)) {
Serial.println(results.value, DEC);
/////////////////////
if (results.value==1752382022) //if up button pushed move motor forward with a 250ms shot of 5V
{
oldValue=results.value; //setting the placeholders value
MotorUp();
delay(volDelay); //this value can be changed to move volume in bigger increments
MotorOff();
}
else if (results.value==2209452902) // down button pushed
{
oldValue =results.value;
MotorDown();
delay(volDelay);
MotorOff();
}
else if (results.value==0xFFFFFFFF) // button is held down, do the last thing done, again
{
if (oldValue==1752382022)
{
MotorUp();
delay(volDelay);
MotorOff();
}
else if (oldValue==2209452902)
{
MotorDown();
delay(volDelay);
MotorOff();
}
//}
///////////////////////////////////
switch (results.value) {
case 3778927144:
//Serial.println("CD");
CD_Press(); // selects CD
break;
case 2908251746:
//Serial.println("TUNER");
TUNER_Press(); // selects TUNER
break;
case 657459652:
//Serial.println("TV");
TV_Press(); // selects TV
break;
case 4120482440:
//Serial.println("MP");
MP_Press(); // selects MP
break;
case :
SUBPH_Press();
break;
//case 4105841032: // -1734753073:
//Serial.println("ON/OFF");
//PWR_Press(); // sets the PWR on
break;
default:
delay(100);
//Serial.println("Waiting ...");
}
irrecv.resume(); // Receive the next value
} else {
////////////////////////////
// check for MP button press
MP_VAL = digitalRead(MP_BUTTON);
if (MP_VAL == HIGH) {
MP_Press();
}
// check for TUNER button press
TUNER_VAL = digitalRead(TUNER_BUTTON);
if (TUNER_VAL == HIGH) {
TUNER_Press();
}
// check for TV button press
TV_VAL = digitalRead(TV_BUTTON);
if (TV_VAL == HIGH) {
TV_Press();
}
// check for CD button press
CD_VAL = digitalRead(CD_BUTTON);
if (CD_VAL == HIGH) {
CD_Press();
}
// check for Sub Ph button press
SUBPH_VAL = digitalRead(SUBPH_BUTTON);
if (SUBPH_VAL == HIGH) {
SUBPH_Press();
}
}
}
sensors.requestTemperatures();
printTemperature(L_temp);
printTemperature(R_temp);
}
void MotorOff() {
digitalWrite(21,LOW); // The core code for motor control came from
http://www.hifivision.com/diy/44275-...g-arduino.html
digitalWrite(23,LOW); // this sets the functions for each mode of motor movement
digitalWrite(25,LOW);
digitalWrite(27,LOW);
digitalWrite(29,LOW);
digitalWrite(31,LOW);
}
void MotorUp(){
digitalWrite(21,HIGH); // The core code for motor control came from
http://www.hifivision.com/diy/44275-...g-arduino.html
digitalWrite(23,HIGH); // this sets the functions for each mode of motor movement
digitalWrite(25,HIGH);
digitalWrite(27,LOW);
digitalWrite(29,LOW);
digitalWrite(31,LOW);
}
void MotorDown()
{
digitalWrite(21,LOW); // The core code for motor control came from
http://www.hifivision.com/diy/44275-...g-arduino.html
digitalWrite(23,LOW); // this sets the functions for each mode of motor movement
digitalWrite(25,LOW);
digitalWrite(27,HIGH);
digitalWrite(29,HIGH);
digitalWrite(31,HIGH);
}
void printTemperature(DeviceAddress deviceAddress)
{
int tempL = sensors.getTempC(L_temp);
int tempR = sensors.getTempC(R_temp);
if (tempC == -127.00) {
lcd.setCursor(10,0);
lcd.print(" Err");
} else {
lcd.setCursor(10,0);
lcd.print(tempL);
lcd.setCursor(13,0);
lcd.print(tempR);
lcd.print("C");
if (tempL > 50 | tempR > 50) {
digitalWrite(FAN_RLY, HIGH);
LED_FLASH_1000();
lcd.setCursor(6,0);
lcd.print("FAN");
} else {
lcd.setCursor(6,0);
lcd.print(" ");
digitalWrite(FAN_RLY, LOW);
LED_ON();
}
if (tempL > 60 | tempR > 60) {
digitalWrite(SPK_RLY, LOW);
lcd.setCursor(6,0);
lcd.print("HOT");
lcd.setCursor(0,1);
lcd.print("Spkr:OFF");
}
}
}
void SUBPH_Press() {
SUBPH_STATE = 1 - SUBPH_STATE; delay(150);
SUBPH_OLDVAL = SUBPH_VAL;
if (SUBPH_STATE == 1) {
digitalWrite(SUBPH_RLY, HIGH);
} else {
digitalWrite(SUBPH_RLY, LOW);
}
}
void CD_Press() {
CD_STATE = 1- CD_STATE; delay(500);
CD_OLDVAL = CD_VAL;
if (CD_STATE == 1) {
TUNER_VAL = 0; TUNER_OLDVAL = 0; TUNER_STATE = 0; digitalWrite(TUNER_RLY,LOW);
TV_VAL = 0; TV_OLDVAL = 0; TV_STATE = 0; digitalWrite(TV_RLY,LOW);
MP_VAL = 0; MP_OLDVAL = 0; MP_STATE = 0; digitalWrite(MP_RLY,LOW);
delay(500);
digitalWrite(CD_RLY, HIGH);
lcd.setCursor(0, 0);
lcd.print("DVD ");
} else {
lcd.setCursor(0, 0);
lcd.print(" ");
digitalWrite(CD_RLY, LOW);
}
}
void MP_Press() {
lcd.setCursor(0, 0);
lcd.print(" ");
MP_STATE = 1- MP_STATE; delay(10);
MP_OLDVAL = MP_VAL;
if (MP_STATE == 1) {
CD_VAL = 0; CD_OLDVAL = 0; CD_STATE = 0; digitalWrite(CD_RLY,LOW);
TV_VAL = 0; TV_OLDVAL = 0; TV_STATE = 0; digitalWrite(TV_RLY,LOW);
TUNER_VAL = 0; TUNER_OLDVAL = 0; TUNER_STATE = 0; digitalWrite(TUNER_RLY,LOW);
delay(500);
lcd.setCursor(0, 0);
lcd.print("MP ");
digitalWrite(MP_RLY, HIGH);
} else {
lcd.setCursor(0, 0);
lcd.print(" ");
digitalWrite(MP_RLY, LOW);
}
}
void TUNER_Press() {
TUNER_STATE = 1- TUNER_STATE; delay(100);
TUNER_OLDVAL = TUNER_VAL;
if (TUNER_STATE == 1) {
CD_VAL = 0; CD_OLDVAL = 0; CD_STATE = 0; digitalWrite(CD_RLY,LOW);
TV_VAL = 0; TV_OLDVAL = 0; TV_STATE = 0; digitalWrite(TV_RLY,LOW);
MP_VAL = 0; MP_OLDVAL = 0; MP_STATE = 0; digitalWrite(MP_RLY,LOW);
delay(500);
digitalWrite(TUNER_RLY, HIGH);
lcd.setCursor(0, 0);
lcd.print("TUNER");
} else {
lcd.setCursor(0, 0);
lcd.print(" ");
digitalWrite(TUNER_RLY, LOW);
}
}
void TV_Press() {
TV_STATE = 1- TV_STATE; delay(100);
TV_OLDVAL = TV_VAL;
if (TV_STATE == 1) {
CD_VAL = 0; CD_OLDVAL = 0; CD_STATE = 0; digitalWrite(CD_RLY,LOW);
TUNER_VAL = 0; TUNER_OLDVAL = 0; TUNER_STATE = 0; digitalWrite(TUNER_RLY,LOW);
MP_VAL = 0; MP_OLDVAL = 0; MP_STATE = 0; digitalWrite(MP_RLY,LOW);
delay(500);
lcd.setCursor(0, 0);
lcd.print("TV ");
digitalWrite(TV_RLY, HIGH);
} else {
lcd.setCursor(0, 0);
lcd.print(" ");
digitalWrite(TV_RLY, LOW);
}
}
void PWR_Press() {
digitalWrite(PWR_RLY, HIGH);
lcd.setCursor(13, 1);
lcd.print(" ON");
SPK_VAL == digitalRead(SPK_IN);
if (SPK_VAL == HIGH) {
lcd.setCursor(0, 0);
lcd.print("Wait..");
delay(5000);
digitalWrite(SPK_RLY, HIGH);
lcd.setCursor(0, 1);
lcd.print("Spkr: ON");
lcd.setCursor(0, 0);
lcd.print(" ");
} else {
digitalWrite(SPK_RLY, LOW);
lcd.setCursor(0, 1);
lcd.print("Spkr:OFF");
}
}
void PWR_OFF() {
CD_VAL = 0; CD_OLDVAL = 0; CD_STATE = 0; digitalWrite(CD_RLY,LOW);
TV_VAL = 0; TV_OLDVAL = 0; TV_STATE = 0; digitalWrite(TV_RLY,LOW);
TUNER_VAL = 0; TUNER_OLDVAL = 0; TUNER_STATE = 0; digitalWrite(TUNER_RLY,LOW);
MP_VAL = 0; MP_OLDVAL = 0; MP_STATE = 0; digitalWrite(MP_RLY,LOW);
digitalWrite(PWR_RLY, LOW);
lcd.clear();
lcd.setCursor(9, 1); lcd.print("Pwr:OFF");
lcd.setCursor(0, 1); lcd.print("Spkr:OFF");
}
void LED_FLASH_1000(){
digitalWrite(LED,HIGH);
delay(1000);
digitalWrite(LED,LOW);
delay(1000);
}
void LED_FLASH_500(){
digitalWrite(LED,HIGH);
delay(500);
digitalWrite(LED,LOW);
delay(500);
}
void LED_ON(){
digitalWrite(LED,HIGH);
}