Thursday, 14 March 2013

Proteus Library For Arduino

Proteus is a very powerful tool in simulating microcontroller codes and Arduino is a very famous microcontroller platform but in Proteus there is no model for Arduino. In this post I am going to show how to add Proteus Library for Arduino and how to use it in simulation.

How to add the Arduino Proteus library

1- First of all you have to download the Proteus library from the following link: CLICK HERE (Note: The download link has been removed due to copyright materials. If you want to download Proteus library for Arduino you can search Google for it)
2- After downloading the file. Extract it and then copy the two files ARDUINO.IDX and ARDUINO.LIB and paste them in the following path:
Drive C >> Program Files >> Labcenter Electronics >> Proteus 7 Professional >> LIBRARY
3- Then open your Proteus and in the pick device wizard search for Arduino you will get the following results.

Now, I am going to show you how to add Arduino codes to Proteus.

How to add the Arduino codes to Proteus

Proteus use the .hex file to simulate microcontroller codes but since the Arduino IDE uses .pde or .ino files, you can't add the Arduino code directly to Proteus. To add Arduino code to Proteus, follow these easy steps:

1- Write your code using Arduino IDE and press verify icon to check the code for errors. Then save your code and name it.
2- Then, from the tools choose your board type (UNO, MEGA,....)
3- After that, press the upload icon and wait .... it will give you an error because the board is not connected to your PC. It's OK leave it.
4- The hex file will be located in the following path:
** NOTE ** you have to activate (Show hidden files,folders and drives) 
Drive C >> Users >> " the name of your PC " >> AppData >> Local >> Temp
5- Search for you code with the name you used in saving and you will find a file named "filename.cpp.hex" copy this file in any place (for example Desktop)
6- Return to Proteus and double click on your Arduino kit and then add the .hex file.

That's all. Now you can run your simulation. If you got any problems, please feel free to write to me in a comment and I will answer you as soon as possible.

You can download this tutorial in PDF format from the following link: CLICK HERE

Thursday, 10 January 2013

Line Follower Robot Prototype


A line Follower robot is a simple mobile robot that follows a line drawn on a floor. For example a black colored floor with a white line drawn as shown in the next figure. The idea behind the line follower robot is using light sensor. When light is incident on white line, the light is reflected and the light sensor detects the reflected light and this signal is used by microcontroller to know that the robot is following the line. When light is incident on black floor, all light is absorbed and nothing is reflected and the light sensor detects nothing and this means that the robot is away from the white line. However, in the last case, the robot may be on the right or left of the white line. So three light sensors are used and the three signals indicates the position of the robot from the line. It is always required to center the three light sensors at the white line as the robot moves.

The Proposed Prototype

A line follower robot is to be designed using ATmega16 microcontroller. Three InfraRed reflectance sensors is arranged in one line. They are composed of an IR LED and an IR phototransistor as shown in the next figure. The analog signal received of each of the phototransistors is proportional to its coverage of the line, and lies between 0 and 2V. The signals of the sensors are weighted by 1,2 and 3 for left, middle and right sensors respectively. The average of the weighted readings gives a value for deviation of the robot from the line. This average has the range between 1 and 3 when the line is at far left or far right of the robot respectively. This average is used to control the speed of the rear left and right wheels of the robot.

Timer-0 and timer-2 in phase correct PWM mode are used for the left and right wheels. It is such that if the average of the weighted readings is 2, the robot is on the line and the OCR0, and OCR2 values are half the top, and correspondingly by an average value of 1 the right speed is highest and the left is 0, and by an average value of 3 the right speed is 0 and the left is highest. In between the speed (i.e. the values of OCR0 and OCR2) change linearly. It is assumed that the microcontroller frequency is to be 1 MHz, and the A/D clock to be lowest and the timer clocks to be highest.

Code Sample

  • A/D initialization:
// ADC Clock frequency: 7.813 kHz
// ADC Voltage Reference: AREF pin
// ADC Auto Trigger Source: None
// Only the 8 most significant bits of
// the AD conversion result are used
  • Timer-0 initialization:
// Clock source: System Clock
// Clock value: 1000.000 kHz
// Mode: Phase correct PWM top=FFh
// OC0 output: Non-Inverted PWM
  • Timer-2 initialization:
// Clock source: System Clock
// Clock value: 1000.000 kHz
// Mode: Phase correct PWM top=FFh
// OC2 output: Non-Inverted PWM
  • The main code:
// asume that left sensor connected to PA0
// asume that Middle sensor connected to PA1
// asume that right sensor connected to PA2
// any analg value it's digital value is multiplied by 255/2

//    DIGITAL AVERAGE    ANALOG AVERAGE                OCR value
//       255/2                                    1                              0
//       255                                       2                           255/2
//       3*255/2                                3                             255

while (1)
      // Place your code here
      OCR2 = Dav-255/2;
      OCR0 = 255-(Dav-255/2);
  • Simulation using Proteus

You can download the project code and simulation from the following link: