Pages Menu
Categories Menu

Posted by on Jun 18, 2011 in Atmel AVR, Electronics, Microcontrollers | 30 comments

Sensor Fundamentals

Sensor Fundamentals

AVR SeriesHuman-like Robots

Humans (or in general any living organism) has to have some senses to become totally autonomous. Humans have five senses – vision, smell, taste, hearing and touch. If so, then what do robots have?

Human-like RobotsLet me ask you a simple question. What does a robot needs to become totally autonomous? By totally autonomous, I mean that the robot should work on its own without any human interference. Most of you would agree with me that it needs intelligence. This intelligence is imparted by us (humans). But is it enough?  Well, of course the robot will work with that, but it will be totally isolated from the outside world. It won’t be interactive and cannot take decisions valid in the real world. In order for it to interact with the real world, we need to implant sensors!

In simple words, a sensor is any device capable of sensing physical parameters (like temperature, pressure, proximity, etc) and then convert into electrical signals so that it can be used for processing. So, what do robots have? Camera, piezoelectric sensors, acoustic sensors, accelerometer, etc.

Sensor Fundamentals

Now let’s move on to some of the fundamentals of sensors. Starting with the basic question, what can we measure using sensors?Practically anything! Light, motion, temperature, magnetic fields, gravity, humidity, vibration, pressure, electrical fields, sound, and other physical aspects of the external environment can be measured using them. Of course there are different sensors for each purpose like IR sensors, proximity sensors, temperature sensors, tilt sensors, accelerometers, ultrasonic sensors, RADAR, SONAR, etc.

Different Types of Sensors Available

Different Types of Sensors Available

Every sensor in this world has three terminals:

  • Vcc – to power up the sensor
  • GND – to provide a fixed negative reference
  • Output – analog output of the sensor (in some sensors, there may be more than one output terminals)

The following block diagram demonstrates it.

Sensor - Block Diagram

Sensor – Block Diagram

The sensor senses the physical parameters and gives a corresponding output. In most cases the output is analog. Some of the most common sensors used in the field of robotics and embedded systems are as follows:

  • IR Sensor

    IR Sensor

    IR Sensor– This is the most fundamental type of sensor available in the market. The basic concept is simple. There is an emitter which emits infrared (IR) rays. These IR rays are detected by a detector. This concept is used to make proximity sensor (to check if something obstructs the path or not, etc), contrast sensors (used to detect contrast difference between black and white, like in line follower robots), etc. The circuit diagram of a basic IR sensor is given below. So even you can make one by yourself.

    Basic Design of IR Sensor

    Basic Design of IR Sensor

    You can also put an op-amp (comparator) in the output terminal in order to amplify the signal and also to convert the analog sensor output to a digital one. We will discuss analog to digital conversion (using AVR) later. For more details on IR sensor design and construction, visit this page.

  • LM35


    LM35 Temperature SensorLM35 is a precision centigrade temperature sensor. It has three terminals – Vcc, Ground and Output – as shown in the adjoining diagram. It has a sensitivity of 10mV/°C. This means that for every degree rise in temperature, the output voltage increases by 10mV. In general, it gives a voltage of 0V at 0°C. Hence, say for an output of 450mV, the temperature is 45°C.

  • Apart from LM35, there are many other temperature sensors like thermistors, thermocouples, etc which are widely used.
  • MMA7260 Tri-Axis Accelerometer

    MMA7260 Tri-Axis Accelerometer

    Accelerometer – An accelerometer is a device which can measure acceleration in any direction (X, Y, Z). MMA7260 is one such tri-axis accelerometer. Even this has three major terminals – Vcc, ground and output (it has three outputs, one each for X, Y and Z). This is a very cool stuff. You can program graphical LCDs using this, you can implement this in humanoids (if you plan to make one) to measure the rate of fall, etc. Here is a short tutorial on using analog accelerometers.

  • Camera– To give your robot the power of vision, you can put cameras on them.
    Axis IP Camera

    Axis IP Camera

    The image processing is done using software like MATLAB, OpenCV, LabVIEW, etc and then the data is transferred to the MCU using serial communication. Even this is a cool stuff! In fact I am presently working on this and hope to bring you some exciting concepts regarding Digital Image Processing!

Well, these were just a few of the sensors. There are many other types of sensors used. Of course, the discussion of all of them is outside the scope of this post. So now, you have the fundamentals of the sensors. In the next post, we will discuss how to convert the analog output of sensors to digital signals using AVR.


  1. Oh my goodness! an amazing article dude. Thank you However I am experiencing issue with ur rss . Don’t know why Unable to subscribe to it. Is there anyone getting identical rss problem? Anyone who knows kindly respond. Thnkx

    • thanks a lot for your response! :)
      well, dunno why it isn’t working.. try once again.. or else you can subscribe via email too! :) or add it to ur google reader account..

  2. the blog is awsm…..hats off…but i want u to also include sm info on op-amp as an ADC……

    • Thanks Utsav! I will include them asap! :)

  3. does infrared output need to be converted into ADC???

    • The IR gives an analog output. The microcontroller is a digital device. Thus, you need to convert the analog signal into digital one. This can be done in two ways -:
      1. Use the internal ADC of the microcontroller
      2. Use external ADC (like using a comparator circuit)

      • thanks bro..

      • Please,kindly explain to me how a comparator can convert/be used to convert the analog output of an IR sensor to digital input of a microcontroller.

        • Hello Amos,
          Please read this tutorial. It explains the ins and outs of IR sensors – all that you’ll ever need to know.

        • Hi Cristina

          I think we need more information about your project to answer your questions.

  4. hey Rex Ryan……i’m also experiencing the same problem with rss feed……
    Anyway this blog is awesome……..

    • Thanks Yeasir… I will look into the matter of the RSS Feeds..

  5. Hi this s ragu
    currently im doing project on the topic bldc controller. for that i need to generate PWM signal for 6 switches and also i want to vary duty cycle through variable pot using ADC converter. i am posting my code pls help its not working

    Code can be found here.

    pls help me

  6. how to connect ir sensors to atmega 16?

    • First of all, I want to know how are you using IR sensor i.e. using op-amp as a comparator or without using op-amp. If you are using op-amp to amplify and convert analog signal to single bit digital signal, then you can directly just connect the output of your sensor to any of GPIO pins of ATMEGA 16 and use DDRx register to assign that pin as input pin.
      If your are not using any op-amp and directly taking the output from your photodiode, then you need to connect it ADC pins of ATMEGA 16. To learn about ADC, visit this.

  7. thanks a lot

  8. i am making linefollower robot with atmega16.But i am facing problem in giving input and taking output from ir sensors.can u pls send the code for taking signals from sensors using inbuilt ADC in atmega16

    • First, assign your input ports using DDRx. Now, if you want to give your port input. You can use following syntax for taking inputs from two IR sensors.

      the above mentioned syntax can be used and modified as per requirements of line follower.

  9. your site has been resourceful on many areas thanks.I have been trying to write code for hc-sro4 ultrasonicsensor(4 pin) but i cant get anywhere using the timer concepts of the using atmega8
    and there is lots of stuff about it(sensor) on the other sites which is more confusing, please help on this area.

    • Hello Issac,

      There are two types of ultrasonic sensors available – analog and digital. HC-SRO4 is a digital one. Usually analog ones are easy to use. Did you read its datasheet? It is clearly explained how to provide the trigger and get the echo. Simply provide 10us pulses to Trigger pin and monitor the Echo pin. You need to measure the time difference between two consecutive pulses of the Echo pin, then put in the formula to get the range. Here is a video as well. Though the video is for Arduino, you can at least get the concept.

  10. plz show me how to make a robot????

  11. mazing n useful info i got ..thnx buddy:-)

  12. can you please provide the temperature ranges of sensors

    • Read the datasheet Sweta. It should be mentioned in the first page itself. If not the temperature range, then the sensitivity range must be mentioned from which you can easily calculate the temperature range. Have fun! :)

  13. How to control a dc motor (how to connect this circuit to motor terminals) so as to run it as per in the control of presence of IR Rays. Basically meant is- like making a robot which runs/works on the IR detection. Reply Soon :)


  1. The ADC of the AVR « maxEmbedded - [...] the Real World, a sensor senses any physical parameter and converts into an equivalent analog electrical [...]
  2. Sensor Interfacing and ADC | roboVITics - [...] [...]
  3. Basic Parts of a Robot « maxEmbedded - [...] System – In order for the robot to interact with the physical world, we need to introduce sensors (which…
  4. ADC and Sensor Interfacing | roboVITics - [...] [...]
  5. Using an Analog Accelerometer | maxEmbedded - […] according to the dictionary, an accelerometer is a device (a sensor) that is typically used to measure the acceleration…
  6. How to build an IR Sensor | maxEmbedded - […] reading ahead, I would suggest you to go through this small post by Mayank on sensor fundamentals. It would…
  7. Different types of sensors - Studio Android BlogStudio Android Blog - […] interesting article the sensors fundamentals is available at maxembedded if you are […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: