As our university offers several courses of studies with a wide range of subjects – like mathematics, information technology, natural science, electrical engineering and media design – it is always a big topic how to combine these different faculties. The aim is not to teach the subjects separate from each other, but to bring them together in interdisciplinary lectures, projects and applications. Two major components of our media technology lectures and laboratories are issues of optics and photonics.
Inspired by the educational program “Hands-On Optics” by SPIE, OSA and NOAO  two years ago a special idea was conceived at our laboratory: Programming microcontrollers in a hands-on seminar. This seminar contains theoretical contents alternating with practical tasks, whereat focus is on the practical issues (“learning by doing”).
Microcontrollers can be applied in various ways to teach content from the fields of optics and photonics. They can be used to control LEDs, displays, light detectors and infrared sensors, which makes it possible to build measuring instruments like e.g. a lux meter, a light barrier or an optical distance meter.
Our microcontrollers are programmed in the programming language C, which is a good choice, for all students have learned the basics of this language in their first semester. Equipped with this previous knowledge the students are able to start their own programming projects after only a short time. The student’s certificate of performance at the end of the semester is to gather in small groups and to develop a microcontroller program, which meets certain demands. Thereby they are encouraged to contribute their own ideas and interests.
The learning goals are to stimulate the student’s interest in the multiplicity of subjects related to this course and to support a deeper understanding of the close connections between them.
Structure and function of a microcontroller
Generally a microcontroller is a single chip that contains an entire small computer. Hence it is also called “computer on a chip”. Usually they are constructed for a particular purpose, e.g. for controlling a traffic light system, a digital clock etc.
The microcontroller’s centerpiece is the central processing unit (CPU), which is also called microprocessor and which primarily consists of the arithmetic and logic unit (ALU) and the control unit (CU). Its task is to perform all operations on data by means of a program:
The ALU loads its data from memory and also stores it there afterwards. The control unit decodes the given instructions of the program, which can be:
Subsequently the ALU executes these instructions and manages the data in- and output. To get in contact with the outside world you need several peripheral units in addition to the microprocessor, such as digital input/output registers (often called “ports”), data memory, program memory and timers. The in/out registers are there to control and read the peripheral devices. They are the ports to all external devices.
All these peripheral units are built in a microcontroller, for the aim is to integrate as much (programmable) functionality as possible into one single chassis. The microcontrollers we use are reprogrammable, which is absolutely essential for our educational purpose: With this condition our students can freely test their written programs or program fragments by trial and error.
Architecture of the microcontroller “ATmega2561”
For our development board we use the microcontroller ATmega2561 from the 8-bit AVR family of Atmel Corporation. Building our microcontroller systems based on this device provides us a reasonable and useful hardware development environment.
In Figure 3 you find the system architecture of the Atmega2561 in detail. The microcontroller is equipped with ten input/output ports, each with eight pins that are switched as digital I/O ports by default. To enable further functions the configuration can be changed with the help of controller-specific register entries.
The development board (hardware)
The development board is structured modularly. At the bottom right you find the microcontroller board with its LCD (1).
On-board in- and output devices
The development board has been designed to provide an easy entry into the field of microcontroller technology and programming. The devices are structured in a way which makes their functions easy to understand and allows a wide range of applications. With this approach it is possible to cover the demands of a good entry into the world of microcontrollers.
Our board contains three input devices:
… and three output devices:
Out of these boards we will take a closer look at the LED matrix, as this board is particularly interesting for optical and mathematical uses:
When designing the LED matrix board (Figure 5) we intentionally avoided the use of a multiplex control, to make it easier for the students to understand the close correlation between the 8 data lines for the columns of the matrix (port 1) and the eight data lines for the rows (port 2).
Example: A logical “1” at row 1 and a logical “0” at column 1 will enlighten the LED11.
On our 8x8 LED matrix we can display the complete ASCII character set, as well as simple graphics.
External devices: sensors
To support our students in their understanding of optics we are additionally using several sensors. For technical measurement reasons they are not part of the development board, but are connected as external input devices to a port of our microcontroller. We use the following sensors:
• A remote controlled temperature sensor: LM334
• A light sensor for the visible spectrum: BPW42 (silicon NPN epitaxial planar phototransistor)
• A light sensor for infrared light: TSOP 1730 (photo modules for PCM remote control systems)
…of which the last two sensors are particular interesting for uses in optics:
Function of the light sensor BPW42
The light sensor BPW42 shows a linear relationship between the irradiance and the phototransistor current. When using the displayed circuit (Figure 7) the sensor delivers an output voltage of UL = IC (RV+RP) which is proportional to the irradiance Ee (in W/m2).
If required, the irradiance has to be converted into the illuminance Ev (in lux), while having to pay attention to the correct wavelength. Afterwards the calculated voltage UL has to be adapted to the 10-bit A/D converter. 
Function of the infrared light sensor TSOP 1730
The light sensor TSOP 1730 is an infrared receiver with a digital output signal, whose spectral maximum sensitivity peaks at a wavelength of λ = 950 nm. It works with a carrier frequency of 30 kHz and a maximum data rate of 2400 bps.
An infrared transmitter sends a carrier-keyed signal, i.e. the infrared signal is being switched on and off with a frequency of 30 kHz. Such signal sequence (“burst”) has a transmission period of circa 600 μs. By sending this burst at specific times it becomes possible to transmit data. The receiver’s output signal SOUT can be passed directly to the microcontroller.
For the development of appropriate algorithms for measuring illuminance or temperature the students have to possess a basic knowledge of optics and electrical engineering.
When it comes to the software, an important part of our microcontroller project – along with electrical engineering, optics and mathematics – is the subject of information technology. This includes knowledge about the syntax of the programming language C, the ability to structure the own source code and the skill of operating the IDE.
The IDE (integrated development environment) is an application package for the PC combining editor, assembler, compiler, linker and simulator applications under one uniform surface, which can be operated more easily. For programming microcontrollers there is a variety of development environments for all different types of microcontroller hardware. All of them have in common that they are useful tools, which offer fast access to important functionalities, liberating the developer from recurring and formal tasks and helping him to manage his work results. This has the advantage for the developer that he can focus completely on his real task: the development of microcontroller applications .
To transfer the written source code to the microcontroller, the code first is being compiled into machine code in hex format, then the controller has to be connected to the computer via a programmer to load the code to the controller’s memory.
At this project we are using the development platform AVR Studio 4 by Atmel in combination with the compiler WinAVR. This IDE offers:
• Source code editor with syntax highlighting
• Proj ect administration for single projects
• Integrated project administration (automatic makefile generation or use of external makefiles)
• AVR-GCC (WinAVR) and AVR assembler support
• Debugger support for AVR simulator and emulator
• AVR programmer (flasher) support for several controllers. (However, to program the ATmega 2561 we do not use the integrated AVR programmer, but the tool USBasp by Thomas Fischl ).
The modular structure of the development board with arbitrary wiring possibilities between in- and output ports offers a big variety of thinkable applications.
To getting started after a short theoretical instruction at the beginning of the course the students are confronted with several small tasks, which are comparatively simple to solve. This can be for example:
Triggering an LED
Task: The LED connected to Pin 4 of Port A shall be switched on and off periodically every second. Source code (solution):
A short and clear code snippet like this has proven to be most suitable for getting used to the syntax of the programming language C and of the control commands for our microcontroller. After a couple of similar finger exercises with a constantly increasing level of difficulty the students are finally able to manage programs with more complex structures and functionalities.
We started the microcontroller project two years ago at our laboratory as an optional alternative to the media technology lab. In the following phase of consolidation it became more and more popular among the students of our faculty, notably also among many female students.
The results of the participant’s big programming tasks (which are their certificate of performance) at the end of each semester are very encouraging: Not only that they are able to get along with their tasks – in addition many of them are highly motivated to go further into the subject by coming up with their own ideas how to enhance their projects.
Considering the taxonomy of learning goals proposed by Bloom  this achievement of supporting the students in realizing their own ideas reaches level K5 to K6:
• Knowledge (K1): Precise (if not literal) reproduction of information;
• Understanding (K2): Ability of applying sense-preserving transformations to knowledge, ability of paraphrasing knowledge in own words and finding examples;
• Application (K3): Ability of applying abstractions, rules, methods, algorithms etc. in concrete situations;
• Analysis (K4): Ability of decomposing ideas and problem settings into its elements and comparing problems, spotting differences;
• Synthesis (K5): Composition of individual elements to a whole;
• Evaluation (K6). 
The feedback sheets our students returned were very positive and had one common tenor: “Finally a really ‘hands-on’ course”.