Tron-Club Advanced Kit 2

Introduction

In a previous article, I introduced the Tron-Club monthly circuit building kit. After going through the second kit, which centers around an ATTiny2313 MCU, I’ve found a few more changes that you may find useful.

Tips

Exercise 8

This circuit uses an electret microphone and attempts to turn on an LED when sound is detected. However in my experience with it, the LED seemed to flash randomly without any noticeable correlation to the sound. The example relies on the timing of an RC circuit to determine when a sound is loud enough to trigger the LED which isn’t very intuitive. I tried a different approach with a transistor amplifier.

Note: The schematic below just shows the new circuitry to connect to the analog comparator inputs, leave everything else the same.

Mic Circuit.PNG

Since the RC circuits are no longer being used, all of that code is removed. I also found that it worked better not to use the comparator’s interrupt and just check it each time through the main loop. The final code is below.

#include <avr/io.h>
  
#define LED PD0
  
int main(void)
{
 DDRD = (1<<LED);
  
 // Start with LED off.
 PORTD &= ~(1<<LED);
 while (1)
 {
  if(ACSR & (1<<ACO))
  {
   PORTD |= (1<<LED);
  }
  else
  {
   PORTD &= ~(1<<LED);
  }
 }
}

With these changes, the output of the mic is amplified from around a 40mV peak-to-peak signal to about a 1V peak-to-peak signal. C1 and C2 block any DC components from coming in or going out of the amplifier stage. R1 and R2 set the gain of the amplifier. R3 and R4 create a DC bias of 2.5V for the amplified audio to sit on top of. Since it is half of the supply voltage, it allows for the widest voltage swing.

The potentiometer acts as an adjustable voltage divider with the output going into PB1. This creates a reference for the amplified output to be compared to. When the voltage at PB0 is greater than the voltage at PB1, the comparator’s output will go high and the LED will turn on.

The potentiometer adjusts the sensitivity, allowing you to set the threshold where the LED turns on. You’ll need to keep it fairly close to the middle so that it stays near the 2.5V point or a little higher.

Exercise 17

This circuit involves the use of the ultrasonic transceiver module. You might find that non-numeric characters display on the LCD when trying to measure longer distances. A little testing shows that this occurs when the distance value becomes negative which doesn’t make sense in this scenario. The problem is caused by the three signed integer variables involved in the distance calculation. Positive signed variables wrap around to negative values when they become too large. Since this is undesirable here, we can change them to unsigned so they are always interpreted as positive values.

//Find the following variable declarations
//Replace ints with unsigned ints
volatile unsigned int Distance, rising
/*...*/
unsigned int old distance;
/*...*/
unsigned int falling = ICR1;
unsigned int counts = falling - rising;

Bill of Materials

Note : Part numbers in bold italics are functional equivalents and may not be exactly the same component. For example, the advanced kit’s LED Matrix module is not sold by Digi-Key, but they have the controller IC and various sizes of LED matrices.

Qty Description Digi-Key Part Number
1 ATTiny2313 ATTINY2313A-PU-ND
1 Speaker 102-3545-ND
1 2 Pos Terminal Block ED2609-ND
1 100 uF Aluminum Capacitor 493-1548-ND
1 MAX7219 MAX7219CNG±ND
1 LED Matrix 160-1555-5-ND
1 Ultrasonic Sensor Module 1568-1421-ND
1 Electret Microphone 668-1198-ND
1 1 uF Tantalum Capacitor 478-1834-ND
4 10k Ohm Resistors CF14JT10K0CT-ND
1 1k Ohm Resistor CF14JT1K00CT-ND
1 39 Ohm Resistor CF14JT39R0CT-ND
1 4x4 Keypad 27899PAR-ND
1 Mini breadboard 700-00012-ND
1 2N2222 Transistor PN2222AD26ZCT-ND
1 Red LED 160-1701-ND

Comments

Please use the Digi-Key’s TechForum: TechForum