Saturday, May 12, 2012

Controlling a led using temperature sensor (lm35) and arduino

The lm35 is a simple temperature sensor whose signal can be used to find you the temperature of what ever the lm35 chip is contact with .

Steps to convert the lm35 signal to temperature

  • lm35 outputs 10mv/degree Celsius.
  • When this analog signal is connected to the arduino, it converts the signal to a value between 0-1023.
  • The voltage range of the arduino analog pin is 0-5V.
  • Thus if the arduino board reads 0 at the sensor pin it means there is 0V as input and if it reads 1023 it means the input is 5V.
  • A value in between 0-1023 indicates a value in between 0-5V, which can be calculated by the formula

For eg if the value read is 58 then the input voltage would be

Once we have the input voltage it can be converted to temperature using the information that for every degree celsius lm35 output is 10mV.
Thus for an input voltage V volts temperature would be (to convert volts to mV multiply it by 1000)

Thus for the above example the temprature would be

In this post we will see how lm35 can be used to light up leds when a certain limit of temperature is reached.
We will need

  • Two leds
  • Two resistors (220ohm) (Value chosen randomly)
  • lm35
  • arduino uno

Light up led1 when the temperature is below 30 degrees and led2 when the temperature is above 30 degrees.


The bread board and schema of connections are shown in the figures below.


Analog I/O A0 acts as input
Digital I/O 2 and 4 act outputs.
we read the analog signal at A0, convert it to temperature using the steps shown above. compare the temperature with 30
Set the pins 2 and 4 based on the result of the comparison.

Program :

Load the program into the arduino uno board and depending on the surrounding temperature one of the two leds should glow , we can modify the temperature by holding it between our fingers or placing it near something warm etc.

Friday, May 4, 2012

Controlling a robot just by thoughts

The scientists at the Federal Institute of Technology in Lausanne, Switzerland demonstrated how a robot can be controlled jut by thoughts and than too over a distance of 100KM.

In the experiment a partially quadriplegic person wearing a head gear, which reads his brain's signals, was able to control a robot just by thinking. That is, if he thought about lifting a finger the robot would lift its finger and so on.

Such experiments have been going on for a while in various countries but this was the first occasion where a paralyzed person could control a robot by his thoughts, with out having to have any thing implanted into his body.

One of the major problems in thought controlled robots has been to be able to pick the right signals from the brain, and for the user to remain completely focused on the task as even small distractions can send wrong signals to the robots.

According to Duc, who was the person who controlled the robot found it easy to control it when he was not in pain. Indicating that the system would still struggle if the user's mind is not completely focused on controlling the robot.

The age old proverb says "Think before you leap", but if are the one controlling this robot you will have to "Think before you Think"


Thursday, May 3, 2012

Cache memory animation

The cache memory is defined as the first level of memory after an address encounters after it leaves the processor. In the memory hierarchy, it is placed right below the processor registers as shown in the figure below.

The following animation shows the traversal of address along the memory hierarchy.

The higher the data is found in the hierarchy the faster it can be fetched by the processor.

The cache is generally made up of SRAM because of the high speed of operation of SRAMs and the faster a cache operates, faster data can be made available to the processor for processing.

The cache stores in it the data of memory locations that the processor uses repeatably or is expected to use very soon in future. When the processor wants to access data of a certain memory location, the data might be present in cache or not, this is defined by the terms cache hit and cache miss respectively.

Note: In the examples below we assume the cache to be made of 8 blocks and main memory to be made of 32 blocks.
A block is the minimum amount of memory that is accessed in on operation, it could be one byte or one word etc depending on the design of the cache.

Cache miss: When the processor does not find, the memory location which it wants to access, stored in the cache it has to fetch the data from the main memory. As the data is missing in the cache this is termed as a cache miss. The following animation depicts a cache hit

Cache hit: On the other hand if the memory location is present in the cache, processor can fetch the data from cache itself and need not go to the main memory to fetch it. This is termed as a cache hit. The following animation depicts a cache miss.

The design of applications as well as the cache should always aim to achieve as high a cache hit ratio as possible.

To able to store the data in the cache in such way as to maximize the cache hit two principles are made use of, temporal locality and spatial locality.

Temporal locality : A memory location accessed once will be accessed again soon and hence need to be stored close to the processor.
The following animation depicts the working of temporal locality

Spatial locality : The memory locations around the memory that the processor accesses might also be accessed by the processor soon and hence need to stored close the processor in the cache.
The following animation depicts the working of spatial locality.

Tuesday, May 1, 2012

Reaction timer using arduino

A reaction timer is the one that measures the time we take to react in response to an external event.

In this post we will design a basic reaction timer using arduino board.

The external event is the glowing of an led, upon which the user has to press the pushbutton. The time difference between the lighting of the led and the user pressing the button is the reaction time of the user.

We will need

  • An led 
  • A push button or switch 
  • 2 Resistors 220 ohm or higher ( value taken randomly) 
  • An Arduino uno board


  • Connect the anode of led to digital I/O pin2 and cathode to the ground through the resistor
  • Connect one end of the pushbutton to 5V of the arudino and the other end to digital I/O pin 7 and to ground through the resistor.
  • The bread board as well as the schematic connections are shown in the figures below.

Working :

  • Digital I/O pin2 acts as output and digital I/O pin7 acts as input.
  • The led connected to digital I/O pin2 should be turned on after some random interval .
  • As soon as the led is turned on the user should press the push button, which is connected to digital i/o pin 7
  • The Push button sends a high to pin 7.
  • While waiting for the press of the push button the program calculates the delay in miliseconds.
  • Once the high on pin 7 is recieved it the delay value is printed to the serial window.

Program :

The random function returns a random number between 0 and the number passed as argument to it, using this we can make sure that the on each iteration the led lights up at random intervals.

The while loop keeps waits for 10 milliseconds before checking the state of the pushbutton, a variable,timer, is incremented on each iteration.

After recieving the high on pin 7,the delay value in milliseconds is written to the serial window.

Follow by Email