Surface-Mount Electronics and Atmel ATtiny85 Microcontroller Robot Brain

(article continued from previous page)

This is a robot that follows a line. The electronics are enclosed in a metal candy tin that previously contained yellow mint candies.

Monkey Mints robot shell with motors and a motherboard.

Monkey Mints robot shell with motors and a motherboard.

The above photograph gives a nice view of the wheels dropping through the cutouts in the base of the candy tin. Tiny screw heads can be observed clamping down the white plastic motor mounts. (The flat lithium-polymer battery normally rests atop the motors, but was removed to provide a better view of the motors in this photo.)

The main printed circuit board is located in the front-center of the robot. The motor and battery wires attach with 0.1-inch spaced connectors. This allows the individual parts of the robot to be disconnected and removed without having to disassemble the entire robot.

There is still a little bit of open space behind the motors and to the left and right of the motherboard. Mode buttons and a power switch could be added. Presently, the battery must be unplugged to completely power off the robot.

Very Small Circuit Board

I’m proud of how much functionality I was able to cram onto this tiny circuit board. While it appears that there is leftover space behind the connectors, the lip of the battery fits there.

The front of the board has two shiny metal areas that block room lighting from affecting the sensors. Although external lighting is not a problem when the Monkey Mints cover is in place, the cap is usually removed during testing and debugging.

There is a lone screw hole at the front of the board. The remainder of the laminate is milled away to fit within the curved front of the candy tin.

About the size of a quarter. The top of the Monkey Mints robot’s main circuit board.

About the size of a quarter. The top of the Monkey Mints robot’s main circuit board.

IC1 is an Atmel AVR ATtiny85 microcontroller. It is the brain of this robot. The code takes up less than 25% of the memory, so an ATtiny25 or ATtiny45 would be an acceptable substitute.

Since the point of this robot is to fit into a small container, it seems counterintuitive to use the DIP (dual inline package) for IC1 rather than the smaller surface-mount package. However, it is likely that the microcontroller will need to be programmed many times as the robot’s software is developed and debugged. Instead of adding a 6-pin connector for in-circuit programming, the DIP chip can simply be removed from the socket for reprogramming.

Discrete Bipolar Junction Transistor (BJT) Motor Drivers

Unlike larger robots with hefty battery packs, the Monkey Mints robot has a fairly low-voltage power source (lithium polymer 3.7V nominal). To deliver the most electrical power to the motors, the motor driver circuit must use bipolar transistors (Q1 and Q2), not MOSFETs.

I selected Zetex ZXTN25012EFH NPN transistors in a SOT23 package (DigiKey #ZXTN25012EFHCT $0.96). These are similar to the transistors used in the Bipolar H-Bridge article, except these come in a smaller surface-mount package. Also, since this robot only needs to turn the motors off and on (rather than off, forward, brake, and reverse), only a single transistor is needed instead of a full four-transistor H-bridge.

The ZXTN25012EFH transistor is rated at a maximum 6A @ 12V. Sometimes this confuses beginners into thinking that the transistor needs to be used at these levels. No. That’s the peak rating. The manufacturer expects that the transistors will be used at lower current and voltage.

In fact, this transistor was chosen because 12V is a relatively low maximum voltage (compared to a classic 2N2222 that has a maximum of 40V). A low maximum usually implies that the transistor is optimized for lower voltage performance. For example, the datasheet shows that the ZXTN25012EFH can provide 1A of current to the motors while typically dropping only 0.045V for itself. The 2N2222 can’t provide such a low-voltage drop at any current level.

All of this means that the motors receive over 95% of the precious battery power. More electrical power means faster speed.

The other significant power usage factor in a bipolar transistor is how much current it takes at the base lead to turn on the transistor. In this case, R2 is 1000 ohms.

base current = supply voltage - base emitter drop / base resistor
base current = 3.7V - 0.7 (from datasheet) / 1000 ohms
base current = 0.003 A = 3 mA.

Battery life is extended because turning on the transistor requires so little base current.

Surface-Mount Devices Save Space

The underside of the main circuit board is packed with surface-mount components. We’ve already seen the reflective photosensors (IED1 and IED2). The sensors view the line-following course through slots in the container.

Underneath the Monkey Mints robot circuit board showing resistors, capacitors, diodes, and sensors.

Underneath the Monkey Mints robot circuit board showing resistors, capacitors, diodes, and sensors.

R1 is the same as R2 (on the top of the board). The 1000-ohm resistors limit the base current that turns on and off the corresponding transistor (Q1 or Q2 on the top of the board).

D1 and D2 are 15V 1A fast-recovery Schottky diodes (DigiKey #MA2YD2100LCT $0.50). Again, those values are maximum ratings, not the values that they need to operate. The diodes protect the bipolar transistors (Q1 and Q2) from higher voltages that occur when the motors are switched off. (See Intermediate Robot Building page 153.) Theoretically, the diodes also marginally improve the robot’s runtime by providing the energy a path back to the battery.

C1 (0.1 µF) and C2 (10 µF) are multilayer ceramic capacitors that smooth the power supply to the microcontroller and phototransistors. (See Intermediate Robot Building pages 126-131.) Without these capacitors, the microcontroller might reset, particularly because robots create a lot of electrical noise by turning on and off parts like motors.

R3 and R5 are the 24-kilohm resistors in series with the phototransistors, as described on the previous page. These create a voltage divider that the microcontroller uses to measure the amount of light reflecting off the floor.

Current-Limiting Resistors

R4 and R6 are the 330-ohm resistors described on the previous page that limit the amount of current supplied to the photoemitters. According to the GP2S40 datasheet, the infrared emitter shouldn’t exceed 50 mA. The typical voltage drop is 1.2V at 20 mA.

max emitter current = max supply voltage - emitter voltage drop / current limiting resistor
max emitter current = 4.2V - 1.2V / 330 ohms
max emitter current = 9 mA

In retrospect, that’s a little weak. Although using half the typical current saves battery power, it makes line detection more difficult. The current will drop even further as the battery voltage goes to 3.7V or lower. In hindsight, perhaps a 220-ohm or 150-ohm resistor would have been a better choice.

Taking a Break to Rescue a Field Mouse

In the middle of working of the robot, my wife told me there was a young mouse huddled by the front door. Our garden provides a wonderful place for small animals to live in the summer. However, as the temperature declines outside, it isn’t uncommon for mice to seek shelter indoors.

Rescued baby field mouse.

Rescued baby field mouse.

I warmed up the mouse by hand and provided it a safe home amongst the electronics. After a few hours, it ventured atop the plastic box, but decided it liked it better on the cloth towel.

It never showed any interest in my offerings of fruit strip, peanut butter, cottage cheese, and milk. I assume it was just being polite or had just eaten a large meal.

Regardless, I’m telling you this to suggest you take time out of robot building to enjoy the little things in life.

That’s all there is for the robots electronics. Let’s see how the Monkey Mints metal candy tin is machined to become the robot’s body.