Saturday, October 26, 2019

0000 0000 0001 0010

Push on Push off latching transistor circuit

Wouldn't it be nice to not have to have two buttons to switch on and then switch off or reset a circuit? So then you could use just one momentary button and when you push it the circuit turns on, and then pushing it again turns the circuit off. It's like getting something for nothing!

I really do not know why I am fascinated by these types of circuit, the pragmatist in me says that using a latching button or a microcontroller with an interrupt and a few lines of code would be way more practical and way less time consuming (er, and cheaper).

Anyway, after literally hours of searching online I built a couple of circuits which DID NOT work as advertised. They looked dodgy on either youtube or some ad-filled nonsense website and there was little or no explanation for the theory behind the circuits. Finally I found exactly what I was looking for on this wonderful website.

Not only did they have a working circuit diagram, but also a great explanation of all the reasoning behind why it worked - educational!


© https://www.edn.com/





Saturday, October 19, 2019

0000 0000 0001 0001

Attiny13 microcontroller

A little divergence here because it is important to point out that a lot of the logic chips and other components used so far in this blog can easily be replaced by a simple microcontroller. Take for example the CD4017 featured in a previous blog as a clap switch circuit.

Here it the circuit repeated but with the Attiny13 doing the work.





The CD4017 comes in to Aus at around 11c each and the Attiny13 at around 40c each. However the Attiny13 has a great deal of flexibility and in fact programming it to "listen" to sound and then react accordingly is quite straight forward.


#define ledPin PB0
#define TINY_ADC_PB4 0x02
int sensorValue = 0;
int background = 0;
boolean lightup = false;
int sensitivity = 50;     // adjust up for less sensitivity

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(TINY_ADC_PB4, INPUT);
  delay(50);
  // take 5 readings and average for background noise
  for (byte i = 0; i < 5; i++) {
    digitalWrite(ledPin, HIGH);
    background = background + analogRead(TINY_ADC_PB4);
    delay(100);
    digitalWrite(ledPin, LOW);
    delay(100);
  }
  background = background / 5;
}

void loop() {

  sensorValue = analogRead(TINY_ADC_PB4);       // take initial reading
  sensorValue = abs(background - sensorValue);  // adjust for background noise

  if (sensorValue > sensitivity) {              // did I hear a clap?

    if (!lightup) {
      lightup = true;
      digitalWrite(ledPin, HIGH);
    }
    else {
      lightup = false;
      digitalWrite(ledPin, LOW);
    }
    delay(50);
  }
  delay(50);
}


Another great advantage of most of these types of microcontroller is that they can be put to sleep and have very little power requirements until required (e.g. woken up with a sensor). That makes them great for battery driven or solar powered projects where energy consumption is an important consideration for design.

One criticism of the Attiny13 microcontroller is lack of memory (only 1k flash!) for larger projects but if you can learn some assembler along with your c-style arduino code, then you can squeeze an awful lot of instructions into it's "tiny", but very capable, brain. Also, I have been known to scale up to the Attiny85 (four times the capacity) or the Atmega series if more features and/or GPIOs are required.

More often than not a combination of parts are required for a particular application, but in general I do reach for a microcontroller first.


Saturday, October 12, 2019

0000 0000 0001 0000

CD4017 counter

The CD4017 is a decade counter and there are a billion or so circuits based on a 555 timer feeding into the counter with the output being a lovely array of LEDs lighting up in response (think KnightRider). Halfway through breadboarding the circuit I came over all bored and went looking for something else to do with the IC. Scrolling down the list of possibilities on a search for alternatives I chanced on a "clap switch" which looked pretty cool.

After building the circuit it soon became evident that you had to be a champion clapper to make it work. I mean what's the point of a clapper circuit if you have to be right next to the microphone and clap like a demon to activate it - you might as well just lean over and flick a switch!

What followed was a few hours of happy transistor swapping. Firstly I tried four (!) SS8050 NPN transistors wired cascade style to increase the gain. It was (only slightly) better but I still got sore hands from clapping. Each SS8050 has a Hfe around 250-300 so I swapped out to a BC517 darlington which jumped up to a ridiculous Hfe around 25k - and it seemed no better as a clap switch.

It occurred to me based on a previous experience with electret microphones to swap out the 100k resistor recommended in the circuit diagram for a trimpot and fiddle with the resistance to affect the sensitivity or gain of the sensor.

At a resistance of around 20k the rig was working pretty well, but as a card carrying perfectionist I then changed out the standard electret microphone for a fancier model which includes it's own crude gain control and voilĂ , a stupid clap switch.









Saturday, October 5, 2019

0000 0000 0000 1111

LM386 Operational Amplifier

Audio amplifiers come in all shapes, sizes and specifications. We have quite a few different chips in the buckets of components which will see the light of day on this blog. But the very first audio amplifier I built from scratch on a breadboard featured the venerable LM386 opAmp which has been fueling hobbyist dreams since 1969.

I only half read the datasheet (??) so I fed it 27V and popped a few before I realised that I was way over voltage. Fortunately they come in for about AU11c each so it was no big deal to blow a few up in the interests of science?

After a bit more digging around I was able to obtain the LM386N-4 which according to the datasheet should make the most noise.



There are a billion examples of this circuit out there in cyber-world, but I returned a few times to this page and the circuit shown below (which is simple and works well).



This site has such a great tutorial and you can keep adding components to make the sound louder and sweeter. I recommend that if you're serious about these audio amp circuits you head over to the site rather than look at my efforts as I'm only trying to look at how these opAmps might be used. As the original IC was designed for use in an automobile as part of a fuel injection system there might be a few more blogs on this site with this component in other guises.

In the meantime, this is the circuit that I decided to build (with the swap out of 12V for 9V and the LM386N-4 for the standard LM386 opAmp).



If you're unhappy with the sound quality of the amplifier in the video below, remember it's coming through a cheap old speaker and then into a cheap phone microphone. It sounds better in the real world and in fact it has been chugging away on the kitchen bench providing background music for the last few days.