Microcontroller Programming

(Week 6)

This weeks task was to build and program a PCB that contained a microcontroller, led and switch. For this I decided to build a simple Polygraph lie detector before then playing around with the ATtiny 85 and it's sleep functionality.


The PCB was designed using Eagle and was based around the original design given in class. Thanks to Adam Setapen and his tutorial I was able to add a button, led and additional connectors for an analogue input to be attached.

Png images were made for both the tracks and exterior which were then converted to g code and machined using both the Roland Modela and the Mantis CNC built by David Carr.


After getting the board to working with the HelloWorld Interrupt C code I then modified this to create a simple program that turned on the LED when the button was pressed.

As I needed to read an analogue pin I implemented a simple program that read the voltage using an ADC pin and then sent this value via serial back to the computer. This program produced readings but I believe these were incorrect or possibly coming from the wrong pin. After spending hours reading, googling and debugging I moved away from the direct C implementation to the Arduino to debug it.

Using the Arduino I was able to successfully get readings from the ADC and so decided to use this for the final implementation. In this the computer sends a single character to the controller which then responds with a reading from the ADC pin.

Data received by the computer is then graphed using a Processing sketch listening for serial data.

ATtiny 85

I had one of these lying about and so I decided to wire it up with a single LED and switch to see how low I could get it's power consumption. Reading through the documentation there are many different power management settings that the microprocessor supports which would greatly improve the battery life of the device.

Following the data sheet I implemented a low level Pin Change interrupt attached to the reed switches pin. This means that when the device has not been interacted with for more then 10 seconds then the microcontroller will enter deep sleep and hibernate. This reduces the power consumption to 0.01 from 14.80 Milli Amps when in a wake cycle.

This improves the life span of the microcontroller from 7.59 to 839.37 days when used with an AA battery (3000 mAh).


Eagle Design Files - Schematic & Board
C Code - HelloWorld Blink & ADC Example
Arduino/Wiring Code - EDA

PCB Design - Eagle

Machining On The Mantis

Completed Board

Polygraph Setup

EDA Activity With Processing

Reading ADC Values

Basic ATtiny 85 With Switch & LED

Power Usage Running

Power Usage In Deep Sleep

Estimated Battery Life

ATtiny 85 EEPROM & Sleep