“You were born with wings, why prefer to crawl through life?”
— Rumi
“Popular culture is the test-bed of our futurity.”
— William Gibson - Idoru
“Self-education, I firmly believe, is the only kind of education there is.”
— Isaac Asimov
“When there are miles to go before we sleep, altered traits are more important than altered states.”
— Rumi

Portal’s Still Alive melody on Arduino UNO

I was browsing through the internet and found a tutorial on playing melody on Arduino which would incorporate PWM signals to generate sounds. Naturally, I enjoy video games and Portal being one of my favorite. I search for videos and found a video which featured Still Alive on Arduino. The author of the script did some painstaking work on writing a directory of sounds that would make up the music that we are familiar with. 

I will simply show you the step by step process of implementing the code on to the Arduino.

The first step is to get the hardware necessary for implementing the circuit. This is a simple and straight forward tutorial. You only require:

- An Arduino Board (I am using UNO)

- An audio jack or a speaker with 2 wires (one for power and other for ground)

- And a 1K resistor to protect the circuit

You can connect the circuit as shown here

The Arduino pin 8 is used to output the data which goes directly in to the speaker or audio jack.

Here is my setup:


Once the hardware is all setup. Open the Arduino Software>File>Examples>Digital>toneMelody. Once the sketch is opened. copy this code over the existing code. Do not touch the Pitches.h file. That is a library used to generate tones.

Still Alive

Plays a the song Still Alive

* 8-ohm speaker on digital pin 8

created 21 Jan 2010
modified 14 Oct 2010
by Tom Igoe

This example code is in the public domain.


#include “pitches.h”
#define REST 0

double song[] = {

// First line
REST, 2.0, NOTE_G3, 0.5, NOTE_FS3, 0.5, NOTE_E3, 0.5, NOTE_E3, 0.5,
NOTE_FS3, 2.0, REST, 2.0,

REST, 1.5, NOTE_A2, 0.5,
NOTE_G3, 0.5, NOTE_FS3, 0.5, NOTE_E3, 0.5, NOTE_E3, 1.0,

NOTE_FS3, 1.5,
NOTE_D3, 1.0, NOTE_E3, 0.5, NOTE_A2, 2.5,

REST, 1.5, NOTE_A2, 0.5,

// Second line
NOTE_E3, 1.0, NOTE_FS3, 0.5, NOTE_G3, 1.5, NOTE_E3, 0.5, NOTE_CS3, 1.0,
NOTE_D3, 1.5, NOTE_E3, 1.0, NOTE_A2, 0.5, NOTE_A2, 1.0,
NOTE_FS3, 1.5, REST, 2.0,

REST, 2.0, NOTE_G3, 0.5, NOTE_FS3, 0.5, NOTE_E3, 0.5, NOTE_E3, 0.5,
NOTE_FS3, 2.0, REST, 2.0,

// Third line
REST, 1.0, REST, 0.5, NOTE_A2, 0.5, NOTE_G3, 0.5, NOTE_FS3, 0.5, NOTE_E3, 0.5, NOTE_E3, 1.5,
NOTE_FS3, 0.5, NOTE_D3, 1.5, NOTE_E3, 0.5, NOTE_A2, 2.5,
REST, 2.0,

NOTE_E3, 1.0, NOTE_FS3, 0.5, NOTE_G3, 1.5, NOTE_E3, 0.5, NOTE_CS3, 1.5,
NOTE_D3, 0.5, NOTE_E3, 1.0, NOTE_A2, 0.5, NOTE_D3, 0.5, NOTE_E3, 0.5,

// Fourth line
NOTE_F3, 0.5, NOTE_E3, 0.5, NOTE_D3, 0.5, NOTE_C3, 0.5, REST, 1.0, NOTE_A2, 0.5, NOTE_AS2, 0.5,
NOTE_C3, 1.0, NOTE_F3, 1.0, NOTE_E3, 0.5, NOTE_D3, 0.5, NOTE_D3, 0.5, NOTE_C3, 0.5,
NOTE_D3, 0.5, NOTE_C3, 0.5, NOTE_C3, 1.0, NOTE_C3, 1.0, NOTE_A2, 0.5, NOTE_AS2, 0.5,
NOTE_C3, 1.0, NOTE_F3, 1.0, NOTE_G3, 0.5, NOTE_F3, 0.5, NOTE_E3, 0.5, NOTE_D3, 0.5,
NOTE_D3, 0.5, NOTE_E3, 0.5, NOTE_F3, 1.0, NOTE_F3, 1.0, NOTE_G3, 0.5, NOTE_A3, 0.5,

// Fifth line
NOTE_AS3, 0.5, NOTE_AS3, 0.5, NOTE_A3, 1.0, NOTE_G3, 1.0, NOTE_F3, 0.5, NOTE_G3, 0.5,
NOTE_A3, 0.5, NOTE_A3, 0.5, NOTE_G3, 1.0, NOTE_F3, 1.0, NOTE_D3, 0.5, NOTE_C3, 0.5,
NOTE_D3, 0.5, NOTE_F3, 0.5, NOTE_F3, 0.5, NOTE_E3, 1.0, NOTE_E3, 0.5, NOTE_FS3, 0.5, NOTE_FS3, 1.5,

// and belive me…
REST, 2.0, NOTE_A3, 0.5, NOTE_A3, 0.5,
NOTE_B3, 0.5, NOTE_A3, 0.5, NOTE_FS3, 0.5, NOTE_D3, 1.0, NOTE_E3, 0.5, NOTE_FS3, 0.5, NOTE_FS3, 1.5,
REST, 1.5, NOTE_A3, 0.5, NOTE_A3, 0.5, NOTE_A3, 0.5,

// science and im still…
NOTE_B3, 0.5, NOTE_A3, 0.5, NOTE_FS3, 0.5, NOTE_D3, 1.0, NOTE_E3, 0.5, NOTE_FS3, 0.5, NOTE_FS3, 1.5,

REST, 1.5, NOTE_A3, 0.5, NOTE_A3, 0.5, NOTE_A3, 0.5,
NOTE_B3, 0.5, NOTE_A3, 0.5, NOTE_FS3, 0.5, NOTE_D3, 1.0, NOTE_E3, 0.5, NOTE_FS3, 0.5, NOTE_FS3, 1.5,

REST, 2.0, NOTE_A3, 0.5, NOTE_A3, 0.5,
NOTE_B3, 0.5, NOTE_A3, 0.5, NOTE_FS3, 0.5, NOTE_D3, 1.0, NOTE_E3, 0.5, NOTE_FS3, 0.5, NOTE_FS3, 1.5,

REST, 1.5, NOTE_A3, 0.5, NOTE_A3, 0.5, NOTE_A3, 0.5,
NOTE_B3, 0.5, NOTE_A3, 0.5, NOTE_FS3, 0.5, NOTE_D3, 1.0, NOTE_E3, 0.5, NOTE_FS3, 0.5, NOTE_FS3, 1.5,

REST, 1.5, NOTE_A3, 0.5, NOTE_A3, 0.5, NOTE_A3, 0.5,
NOTE_B3, 0.5, NOTE_A3, 0.5, NOTE_FS3, 0.5, NOTE_D3, 1.0, NOTE_E3, 0.5, NOTE_FS3, 0.5, NOTE_FS3, 1.5,

// still alive… still alive…
REST, 1.5, NOTE_G3, 0.5, NOTE_A3, 0.5, NOTE_A3, 1.5,
REST, 1.5, NOTE_G3, 0.5, NOTE_FS3, 0.5, NOTE_FS3, 1.5,

// End of song
0.0, 0.0

void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);

double duration = 1;
for (int i = 0; duration > 0.0; i += 2)
int note = song[i];
duration = song[i + 1];

int noteDuration = (1600.0 * (duration / 4));
tone(8, note, noteDuration);

int pauseBetweenNotes = noteDuration * 1.3;

void loop() {
// no need to repeat the melody.

That’s all you need to do to play Portal’s Still Alive on your Arduino. Enjoy!

Avionic Sensor Measurement

While searching through my hard drive. I stumble upon an old project that I made while I was completing my bachelors. I thought I would put this here so that more people could see it and possibly replicate it.


Avionic Modules are used in airline industries mainly in aircrafts to measure changes in the physical parameter. These modules are used by air traffic controllers to measure the condition for the environment and based on the measured data, they could inform the pilots in order to provide pilots with accurate data and ensure that the plane is landing safely. They modules are also used inside the aircraft’s fuselage to provide pilots or operators with up to date data regarding the changing environment conditions that are important for the pilots to make decision for the safety of the passengers on board the plane. There are different types of modules available in the market. These modules vary depending on the type of the plane. In such modules are the temperature sensor, air velocity sensor, pressure sensor and most of all altitude sensor. Hence, avionic sensor modules are the very heart of the airline industries.


The objective of this project is to design an avionic sensor module that could measure, air velocity, temperature, pressure, altitude, 3D orientation and 3d position of the plane. This will be accomplished by using off the shelf sensors that are available in the university laboratories. The goal is to measure the environmental parameter and by using ADC, interface the sensor plus signal conditioning circuits with a microcontroller so that the reading could be obtained instantly on an LCD screen. The microcontroller used for this project is ATMEGA32. If time permits the module will be tested on a kite for measure physical parameter. The module will be lighter enough to be used on a kite to measure the physical parameters on a low altitude. 


The microcontroller used for this project is ATmega 32 from AVR. The ATmega32 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the ATmega32 achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed.


The temperature sensor used for this project is LM335. The LM335 are precision temperature sensors which can be easily calibrated. They operate as a 2-terminal Zener and the breakdown voltage is directly proportional to the absolute temperature at 10mV/°K. The circuit has a dynamic impedance of less than 1Ω and operates within a range of current from 450μA to 5mA without alteration of its characteristics. Calibrated at +25°C, the LM335 have a typical error of less than 1°C over a 100°C temperature range. Unlike other sensors, LM335 have a linear output.

To measure orientation Gyroscope was used, the gyro used for this project is a single axis evaluation board that can measure the yew movement. The gyro used is ADXRS150EB from Analog Device. The ADXRS150EB is a simple evaluation board that allows the user to quickly evaluate the performance of the ADXRS150ABG yaw rate gyro. No additional external components are required for operation. The ADXRS150EB has a 20-lead dual-in-line (0.3 inch width by 0.1 inch pin spacing) interface that allows the user to easily prototype products without having to deal with BGA soldering. The 0.4 square inch outline of the ADXRS150EB is still among the smallest gyros available today.


The Accelerometer used for this project is ADXL150EB.


 The first step in making this project is to test all the sensors and then make a signal conditioning circuit that would be used to interface with the microcontroller via Analog to digital converter. The analog to digital converter is accompanied inside the microcontroller with a reference voltage of 5V. The signal conditioning is done with 10-bit unipolar ADC. The set-up of the avionic module is first tested on a bread board and later it was transferred to a PCB. The microcontroller used for this project is AVR ATmega32. The code was written in C and can be found in the Appendix section. The testing of each sensor was done and the result was displayed on a multimeter.


After testing the circuit The PCB was made using ExpressPCB and the PCB was manufactured. The signal conditioning circuits, 5V power supply and the microcontroller was etched on the PCB. 



In order to implement the design and map the sensor output in to the microcontroller, we had to find the relationship between the environmental parameter measured by the sensor and the voltage that are generated by the sensor and inputted in to the ADC of the microcontroller. We tested all the sensors and based on the relationship, we entered the result in to the microcontroller.

For the temperature measurement, we used LM335 and connected it to the differential amplifier. By using the sensitivity of the LM335 and using the room temperature value (25.3), we found the voltage value of the temperature output which was around 2.93V. If we increase the temperature of the LM335, the voltage also increases and the change in voltage will be converted in to temperature value by using the following equation in the microcontroller.

Temperature  =  -30 + Voltage(18)

The voltage at the input of the Vadc = 5.5(V-2.4316)          

Similarly, to measure altitude, we also found the relationship between the Altitude and voltage and also with the pressure. As the altitude increases, the pressure decreases which also decreases the voltage of the LM335. By plotting this result on the graph we find that there is an inverse relationship as shown:


The formula used to convert the Voltage in to the Altitude:

Altitude =  (-Voltage+1.711)/(2.3423x10-3)

            To find the relationship of the Accelerometer we used the equation that was given in the accelerometer datasheet. It should be kept in mind that accelerator has a DC offset of 2.5V and when it is moved the voltage changes and usually increase more than 2.5V. In order to read from the sensor the relationship between voltage and acceleration is put in to the microcontroller for all 3-axis.


Acceleration = (-V0-2.5)/200m

Finally, for gyroscope we needed a range of 0 – 360o and the sensitivity is 12mV/degree/s


Degree  = (Voltage – 4.32)/0.005

After writing the code in C and adding the code in to the microcontroller, the sensors reading was displayed on to a computer screen. By using push-buttons, we could select between , altitude, temperature, orientation and position.


The results were displayed on the computer monitor and are as shown:


Conclusion & Discussion:

            Avionic sensor module making was a very interesting experience since we learned a lot about microcontrollers especially the programming aspect of the microcontroller which in itself is a very useful task. The use of different sensors made us appreciate the time and efforts engineers spend on designing and manufacturing efficient avionic module that provide accurate readings to the pilots and the flight controller.

            We were able to finish the design of the signals conditioning circuit and were also able to interface the system on the microcontroller. The outputs were seen on the computer in real time. However, some of the sensors like the pressure sensor and the gyro were not giving us large output cause their signal conditioning were not working properly and hence the output we were receive at the microcontroller terminal were very small and hence there was no noticeable output seen. We also couldn’t manufacture the PCB board because the lab was already been used for examination which prevent the manufacturing of the PCB. Therefore, as intended the system couldn’t be used on the kite for data logging.

            This project taught us a lot especially the calibration of the sensors and how to interface these sensors with the micro-controller.

“One of the saddest days of my life was when my mother told me ‘Superman’ did not exist, She thought I was crying because it’s like Santa Claus is not real. I was crying because no one was coming with enough power to save us.”
— Geoffrey Canada  - But this is exactly how I feel when I hear stories on ‪Palestine‬ 

Difference between a microcontroller and microprocessor?

A lot many of us get confuse between what defines a microprocessor and micro-controller. This is because they share common features and at the same time these devices are different from each other. It is really hard to tell the difference between them just by looking at them.


To begin with, let us discuss what a microprocessor is. A microprocessor is what we find at the heart of our Desktop PCs, Laptops, notepads etc. It is a single Integrated Circuit (IC) which has a Central Processing Unit (CPU) inside. A CPU is capable of performing Arithmetic and logical operation, it contains the program counter and instruction registers. In order to run a microprocessor, a system designer need to add external RAM, ROM and I/O peripheral devices to make it functional. Since memory and I/O need to be connected externally, therefore, it makes the circuit larger. Due to external components, the entire power consumption is high. Hence it is not suitable to be used with devices running on stored power like batteries. 

More importantly, microprocessors are base on Von Neumann model/architecture where program and data are stored in same memory module. Microprocessor find applications where tasks are unspecific like developing software, games, websites, photo editing, encoding etc. In such cases the relationship between input and output is not defined. They need high amount of resources like RAM, ROM, I/O ports etc. Hence, the clock speed of microprocessor is quite high usually in Gigahertz ranges as they are used to perform complex tasks.

Popular microprocessors are, Intel processors; I3, I5, I7, Core 2 Duo etc. AMD processors; Phenom, Athlon etc.


A Micro-controller on the other hand, are designed to perform specific tasks. This means that not much computation is required and the device need to detect an external event before executing an output. For instance, electronic door lock, electrical thermostat, motion sensor based night lamp etc are some of the specific task that microcontroller can perform as it does not require complex computation and hence can be embedded on a single chip.

Unlike microprocessor, micro-controller has built-in ROM, RAM, I/O pins etc. This makes the micro-controller compact in size and hence it is efficient technique to deploy embedded systems. The cost of the system is quite small compare to microprocessor. Micro-controller have power saving modes like idle mode and power saving mode. This helps to reduce power consumption even further.

Moreover, micro-controllers are based on Harvard architecture where program memory and Data memory are separate.Notable micro-controllers are PIC, AVR ATMEGA, Intel 8051 etc