TinyOS is an operating system widely used in sensor network research in academia and industry. In this tutorial, we will explain the details of TinyOS 2.1 architecture and learn how to start using TinyOS 2.1 for research and sensor network application development. This tutorial presents: a) an overview of TinyOS 2.1 component-based architecture and design rationale, b) the details of nesC, the C-dialect used to write programs in TinyOS, c) mechanisms to trap memory access errors (null pointer dereferences, array bound violations, etc.) using Safe TinyOS, d) an overview of TinyOS threads which enables seamless interleaving of long running background computations with time critical event-based services, and e) a survey of the TinyOS network stack. The tutorial included a hands-on session during which the participants ran TinyOS programs on real motes.