Arduino Powered Gainclone (amplifier)

47,051

120

50

Introduction: Arduino Powered Gainclone (amplifier)

For those of you that do not know (and I didn't until recently), a Gainclone is an amp that is a 'clone' of the original design of an amp made by 47 Labs called a Gaincard and are based on single chip amplifiers made by National Semiconductor - Namely the LM3886 chip (The original Gaincard used LM3875).  These amps produce a superior sound to most anything that you can buy at your local audiophile store and are a fraction of the cost to build.  It sounds impossible but you will be wanting to turf your existing amp for one of these in no time!

I won't go too much into the build of the actual amp here but I will give details of my parts and where I acquired them from.  There are already a few instructables on building a gainclone and several websites almost dedicated to the subject and I could not even scrape the surface of the possibilities in building one.  There are so many different options for the same result.  Decide on the amp you want to build, learn how to build it and then come back here for the 'smarts' to put in it.

This is not a beginner project, especially the amp itself. It involves wiring of mains power and can be extremely dangerous to those that are not knowledgeable in this area - Do not take chances.  If you are not a competent solderer and don't have a reasonable knowledge of electronics and feel safe playing with mains power, this project might not be for you.

A big thanks goes to ASCAS for the initial inspiration to build one of these amps!

What this instructable is mostly about, is the 'front end' of the amp - In this case it is an Arduino powered sound processor and input switcher.

The main components that allow this to work are:
Arduino Nano
TDA7439 Sound processor chip
TEA5767 Radio module
DS1307 RTC clock module


The TDA7439 allows the switching of 4 sources to one output, Bass/Mid/Treb control, Input gain and volume control (among others). The functions of the chip are controlled via the i2c bus. It's commonly found in car audio applications but is perfectly suited to this use too.  The only downside to it is it's in a DIP30 package which means you cant breadboard it, even worse is that there seems to be no easily obtainable sockets for a DIP30 chip.  However, the pin spacing is still solderable by hand.  The chips cost a couple of dollars so if you fry one, its not the end of the world.

To make this even easier to use, I have authored an Arduino library so all you need are simple commands to use the functions of the chip.

The TEA5767 is an FM radio module, also controlled by the i2c bus and is extremely easy to use.  I would have preferred a DAB (digital) radio but the modules available are limited and somewhat awkward to use at the moment.  Maybe in V2....

The DS1307 RTC is included for the sake of it,  I just wanted to have a clock :)  It's also on the i2c bus.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Collecting the Parts

For my actual amp, the main components I used are:
2 X 25V, 100VA Toroids from Element14 - They were on special at the time for $15ea!  Sadly, they no longer are.
2 X Power supply boards from AliExpress
2
 X LM3886 Amplifier modules, also from AliExpress

However, a search for LM3886 on eBay or AliExpress will turn up a magnitude of results - Take your pick!

For the sound processor, you will need:
Aurduino Nano
TDA7439 IC ~$4
TEA5767 FM Module  <$3 ea
16X2 LCD module ~ $5
Ir Remote and reciever - These can be salvaged from old equipment or purchased from ebay
DS1307 RTC module
*A Rotary encoder (somewhat optional)

8 X 0.47uf MKT
4 X 100nf MKT
2 X 22nf MKT
2 X 18nf MKT
2 X 5.6nf MKT
2 X 2.2uf NP
2 X 2K7
2 X 5K5
1 X 10uf Mono
2 X 4K7
0.1" Header terminal strips (for connecting the inputs, LCD etc.
2mm spacing header (for the TEA5767 module, or just use some wire.

If you want Fan Control:
1 X BD681 Darlington Transistor
1 X 1k Resistor

A small power supply - The Datasheet for the TDA7439 states that it's minimum supply voltage is 9v, however, it seems to run ok on 5v when connected via USB.  I didn't test this further as I needed the power supply for the fan in my case anyway. You could possibly just use a decent 5v supply.

A way of fabricating the board

* The system is controllable by buttons and an IR remote.  The only functionality that is not in both is tuning the radio.  This is currently by IR only. So, if you wanted to leave out the Rotary encoder for the most minimalist look, you could just use the IR remote.

Also, the rotary encoder I am using was surplus stock from a massive manufacturing workshop shutdown, hence it is probably worth >$100 but cost me a couple of dollars. It does all the debouncing and signal processing itself, so there is nothing in the code to handle a 'raw' encoder signal. It is also a 1000ppr sensor so there is a divider in the interrupt service routine to reduce it's sensitivity.  In theory, there is no reason that a mechanical one would not work but it may require some debouncing on the inputs.

Step 2: Fabricating the Board and Assembly

These days I use a CNC machine to fab my boards but there is no reason this could not be made with toner transfer, positive resist etc.  Use what suits you.  I will mention however that the TDA7439 is fairly unforgiving for misaligned holes.  Take your time when drilling the holes if you are doing it by hand.

The attached file is in Sprint Layout format.  There is a free viewer available from Abacom - See the bottom of the page.

Most holes are 0.6mm with the arduino and other header pin holes being 1mm.

Once you have the PCB completed, check it over for any shorted/open tracks/pads and clean up as necessary.

Start assembling the board, starting with the links (in red) then all resistors and capacitors. If you were lucky enough to find a DIP30 socket, install that now too. Install the TEA5767 module, taking note of the orientation of the chip.  The silver cylinder part (crystal) is closest to the arduino.

Install the rest of the parts as per the layout.

You can install the RTC off some headers.  I used a female header from an arduino shield trimmed down to 4 pins to give it some height.  This works well.

From here, it is assumed that you have a functional Gainclone that is tested and verified to work with a simple signal source such as a MP3 player or PC.  Please ensure this is the case before adding the board to ensure you can easily isolate any problems encountered.

Step 3: LCD and IR Sensor


Once you know the distance and orientation of the LCD and IR sensor to the main board, you can use some standard IDC ribbon cable to connect the components.

Check the pinout of your LCD -  Most are the same but there are generally minor differences.  Match the pin identifications for the LCD to the PCB layout.  At this time, Identify the pins on the IR sensor. There will be Sig/O, Gnd and Vcc.  Gnd and Vcc can go to the corresponding pins on the LCD to simplify wiring, Sig will go to the pin marked IR on the PCB layout.

Step 4: Encoder and Buttons

If you are using a 'smart' rotary encoder like mine, connect your Rotary encoder to the corresponding pins marked A,B,Gnd, 5v.

However, if you are using a simple mechanical encoder, connect the common pin to 5v and A/B to the corresponding pins on the board. 

If your encoder also has a 'push' button, connect it's corresponding pins between ground and the pin marked enter.

**Remember, using a mechanical encoder will mean you need to change some settings in the code and likely 'fix' it to allow for debouncing of the contacts. Depending on the popularity of this instructable I may review the code to allow for this.

For those that do have an encoder but not with a push option, use a separate N/O SPST button connected between Gnd and Enter pins.

Connect a N/O SPST button between Gnd and Power pins for a power button.

Step 5: Power Relay

The relay output pin is for controlling power to the toroid(s) when the amp is 'off''.  This ensures low power use when 'off' (The arduino is still running on its own hard wired power supply)

This is an active high output that is to drive the Solid state relay natively or you could one of  the relay modules available on ebay if you wanted to keep costs down (pic 2)

 I had a spare SSR so that's what I used...  

Step 6: Power LED

Pins A1 and A2 (marked PWLED) are configured to be used for sinking current for the power LED.  This is a bi-state configuration but a single 'on' led can be used rather than have an on and an off led.  Connect your LED(S) to one of the 5v/Vcc lines via an apropriate (probably around 1k) resistor and then to these pins. I used a common Annode (+)  RGB led but just used red and green.

You could also use these pins in current sourcing mode with a common cathode LED and the corresponing gnd pin adjacent to the A1/2 header, The outputs on these pins are inverted with the power change so it will work fine with no code changes.

Step 7: Power Supply and Fan Connections

Connect your small power supply to the Vin and Gnd pins and connect your fan to the corresponding pins on the board (if using)

If you do not require a fan, you may be able to get away with a 5v power supply.  It worked ok in my initial tests but this is outside of spec for the operating voltage of the TDA749 chip and you may encounter problems.

Step 8: Final Connections

Connect the Ant. pin to a suitable antenna jack or just a piece of wire.

Finally, connect all of your inputs to the processor.  These are marked Lx and Rx.  Input 1 is hard wired to the TEA65767 Radio module but the other 3 inputs can be used as you wish.  In my amp I have a 3.5mm jack (AUX), standard component audio (CD) and USB (DAC).

The USB is simply a decased and rewired Sound blaster Play! that can be had for about $20 and the sound quality is quite impressive. It installs as "USB sound device" and needs no drivers, even on Windows XP (eeew).

Step 9: Loading the Code Into the Arduino and Testing.

With the mains power OFF!

All development has been done in the latest Arduino IDE.

You will need the following libraries
TEA5767 Library
TDA7439 Library
IRRemote Library

Install the libraries into the Arduino IDE as you would any other.

This project also use the EEPROMWriteAnything method 

Grab the zip file attached here too :)

Set the time...
Load up the default example sketch in the arduino IDE for the DS1307RTC called 'SetTime' and upload it to the arduino.  This will set the time on the RTC module to the current time of your PC. Hint: Open the serial monitor window. This also checks your connections to the RTC and ensures the i2c bus is working...  Provided you were successful in programming the time on the RTC, move on to the next step. If not, verify your soldering and ensure the RTC is orientated correctly with the pins labelled.

Now program the Arduino_Gainclone_1_3.ino file to the Arduino from the zip file.

Once loaded, the backlight should come on dimly and you should see a basic display of the time.  If at this point you see garble or nothing on the display, double check your wiring to the LCD module.

****Still with the mains power off*****

Power on the controller by pressing the power button, the LCD should light up to full brightness and Welcome you. It will then default to the radio and the power relay should come on.

The LCD may be slow to respond as it's all being powered off USB.  Don't fret, it will be fine once you're off USB power.

Learn your IR commands:
Open the arduino serial port monitor and it will print the codes when you push a button on your remote.  If it doesn't then you may have hooked up your IR receiver wrong - Check your wiring.

Find the line in the top section of the arduino code corresponding to the button you want to use and enter the code that it produces for that remote button.  Once you have all your IR codes entered, you can re-upload the code to the Arduino

 If you purchased a 'KEYES' remote off ebay - No need, that's what the code is configured for.

Left = Vol Down/Menu left
Right = Vol up/Menu Right
Ok = Enter
Up = Tune Up
Down = Tune down
* = Power

However, this remote has a slight annoyance in that it does not keep repeating the code when the button is held, it sends a 'repeat last code' type command.  This is annoying when changing the volume by a large amount.

Verify the functions of the remote, buttons and encoder to make sure they do what you expect.  The ok/enter button enters the menu and then you can use the volume to change the values, enter/ok to select etc.  Menus time out after 5 seconds.  If the volume is the wrong way round, swap the A/B wires on the encoder and it will go the right way.

If everything checks out, turn off the amp using one either of the power buttons and disconnect the usb cable from the Arduino.

Step 10: The Moment of Truth!

Connect and power on the amp from the mains.  Providing everything checks out, after about 2 seconds you should see the time on the display.  You can then hit the power button and the amp should turn on and you will be able to listen to some sweet tunes!

Arduino Contest

Participated in the
Arduino Contest

2 People Made This Project!

Recommendations

  • Magnets Challenge

    Magnets Challenge
  • Raspberry Pi Contest 2020

    Raspberry Pi Contest 2020
  • Wearables Contest

    Wearables Contest

50 Discussions

0
PVV001
PVV001

18 days ago

I have downloaded and added the required libraries like: EEPROMex, Encoder, DS1307RTC, Time, EEPROMAnything and the library has pinned at the article but i still got this error on arduino IDE
In file included from C:\Users\Admin\Documents\Arduino\libraries\EEPROMAnything-master/EEPROMAnything.h:6:0,
from C:\Users\Admin\Documents\Arduino\TDA7439\TDA7439.ino:10:
C:\Users\Admin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.2\libraries\EEPROM\src/EEPROM.h:145:20: error: conflicting declaration 'EEPROMClass EEPROM'
static EEPROMClass EEPROM;
^~~~~~
In file included from C:\Users\Admin\Documents\Arduino\TDA7439\TDA7439.ino:5:0:
C:\Users\Admin\Documents\Arduino\libraries\Arduino-EEPROMEx-master/EEPROMex.h:195:22: note: previous declaration as 'EEPROMClassEx EEPROM'
extern EEPROMClassEx EEPROM;
^~~~~~
Multiple libraries were found for "EEPROMex.h"
Used: C:\Users\Admin\Documents\Arduino\libraries\Arduino-EEPROMEx-master
Multiple libraries were found for "DS1307RTC.h"
Used: C:\Users\Admin\Documents\Arduino\libraries\DS1307RTC-master
Multiple libraries were found for "TimeLib.h"
Used: C:\Users\Admin\Documents\Arduino\libraries\Time-master
Multiple libraries were found for "EEPROM.h"
Used: C:\Users\Admin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.2\libraries\EEPROM
Multiple libraries were found for "EEPROMAnything.h"
Used: C:\Users\Admin\Documents\Arduino\libraries\EEPROMAnything-master
Multiple libraries were found for "IRremote.h"
Used: C:\Users\Admin\Documents\Arduino\libraries\Arduino-IRremote-master
Multiple libraries were found for "TEA5767.h"
Used: C:\Users\Admin\Documents\Arduino\libraries\TEA5767-master
Multiple libraries were found for "TDA7439.h"
Used: C:\Users\Admin\Documents\Arduino\libraries\TDA7439-master
Multiple libraries were found for "SPI.h"
Used: C:\Users\Admin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.2\libraries\SPI
Multiple libraries were found for "Wire.h"
Used: C:\Users\Admin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.2\libraries\Wire
Multiple libraries were found for "Encoder.h"
Used: C:\Users\Admin\Documents\Arduino\libraries\Encoder-master
Multiple libraries were found for "LiquidCrystal.h"
Used: C:\Program
exit status 1
Error compiling for board Arduino Uno.

Can you help me?

Untitled.png
0
andrew_h
andrew_h

Reply 17 days ago

Looks like you probably have the libraries in 2 locations - i.e in your user folder and ardduino\libraries folder.

0
PVV001
PVV001

Reply 17 days ago

Thanks very much. I have read the comments below and have been running,
and test time.
Thanks for sharing

Untitled.png
0
YudhiS4
YudhiS4

Question 7 weeks ago on Step 9

hello andrew_h, I have a few problems, the power button is not functioning, the input is not displaying, bass mid trebel is a strange character, I have been working on it for almost a week and still there is an error, maybe someone can help, thank you

IMG_20191202_110852.jpgIMG_20191202_110909.jpgIMG_20191202_110921.jpg
0
andrew_h
andrew_h

Answer 7 weeks ago

That's interesting - It seems there is an issue with the custom characters that build the double sized font. Does the time display correctly? These displays are somewhat temperamental and the custom characters in mine got scrambled over time. I actually modified the code and I now re-init the characters every time I power on or off the amp (I still use this amp as my main TV amp). I also swapped to a better RTC that keeps time better.

As for the power button, I'm not sure what to say - it's just a button, tripple check your wiring and the button itself.

0
YudhiS4
YudhiS4

Reply 7 weeks ago

thanks for the fast response, for now the time is right, who knows later. I slightly modified the sketch, now use i2c lcd, I haven't installed the relay including the audio processor, I just tested the sketch before proceeding further, does installing the relay and the audio processor affect the arduino sketch?
IMG_20191203_084545.jpgIMG_20191203_084556.jpg
0
andrew_h
andrew_h

Reply 7 weeks ago

Here is a theory - The Audio chip is i2c as well, perhaps the commands being sent to the (non-existent) audio chip are being interpreted by the LCD? Or some other crossover between the 2 libraries? Or better still - the values/variables are not being read from the audio chip so therefore it is returning invalid data so it ends up returning data from weird memory locations. The more I think about it, the more it makes sense. This could also be affecting the power as it initializes the chip on turn on but is not getting a response.

This is worsened by the 'hack' char to int conversion for the values as it relies on where the numbers are in the ASCII table to do the conversion (assuming it is getting char 0-9 but if it is something else, you will get unpredictable responses.

Try modifying the code to set the values manually in setup() and see what happens. i.e midLevel,bassLevel and trebLevel.

0
YudhiS4
YudhiS4

Reply 7 weeks ago

Yes, you are right. I will try, ty

0
YudhiS4
YudhiS4

Reply 7 weeks ago

maybe there is a problem in recording the settings in eeprom, later I try to modify the sketch to record all the settings in eeprom after 10 seconds of inactivity
0
andrew_h
andrew_h

Reply 7 weeks ago

I'd say its an issue of not having valid data, not the fact that it is not being stored. Ideally you need the audio chip connected.

0
YudhiS4
YudhiS4

Reply 7 weeks ago

ok, thanks, I'll try later if there is time I install all the components.

0
obulut2
obulut2

Question 2 months ago on Introduction

Mrhaba,
Arduino:1.8.9 (Windows 10), Kart:"Arduino Nano, ATmega328P (Old Bootloader)"
Arduino_Gainclone_1_3:7:23: error: DS1307RTC.h: No such file or directory
compilation terminated.
exit status 1
DS1307RTC.h: No such file or directory
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Derleme hatası çözümü nedir?

0
PatrikN4
PatrikN4

8 months ago

Hi, I have a problem with the code.
" tmElements_ť was not declared in this scope "
Can you advise?

0
andrew_h
andrew_h

Reply 8 months ago

try changing:
#include <Time.h>
to:
#include <TimeLib.h>

It looks like it has changed in more recent releases.

0
PatrikN4
PatrikN4

Reply 7 months ago

Thank you, I try. I don't know much English

0
PatrikN4
PatrikN4

Reply 7 months ago

It works well. I'll finish the project and I'll share it. Thank you

0
RafalR5
RafalR5

1 year ago

I have a problem. System composed correctly, the code works properly but not the sound at the output of the processor. Efficient processor. Where to find a mistake?

0
SergeyS92
SergeyS92

Reply 1 year ago

Hey. I'm also going to assemble this project, you can help me, because with programming I get an error associated with the clock

0
jokondom
jokondom

2 years ago

_212.ino: In function 'void displayMenu()':
_212.ino:478: warning: comparison between signed and unsigned integer expressions
_212.ino: In function 'void changeInput()':
_212.ino:566: warning: comparison between signed and unsigned integer expressions
_212.ino: In function 'void changeSnd(int)':
_212.ino:668: warning: comparison between signed and unsigned integer expressions
_212.ino: In function 'void changeGain()':
_212.ino:744: warning: comparison between signed and unsigned integer expressions
_212.ino: In function 'void changeSnd(int)':
_212.ino:631: warning: 'selected' may be used uninitialized in this function

0
jokondom
jokondom

2 years ago

Power is always on and off power can not be used