Showing posts with label microcontroler. Show all posts
Showing posts with label microcontroler. Show all posts

How To Make An IR Object Detection Module

Saturday, 13 July 2013
“The IR object detection module is quiet easy to make. This circuit below is a low cost / low range object detection module that you can easily make at home using IR sensors. We will use a photodiode and IR LED to make a simple circuit. IR led looks like a regular LED that you usually see in Television Remote controls.”

How to make an IR Object Detection module using  IR LED and Photodiode , Rakesh Mondal


The IR object detection module is quiet easy to make. This circuit below is a low cost / low range infrared object detection module that you can easily make at home using IR sensors.
We will use a photodiode and IR LED to make a simple circuit. IR led looks like a regular LED that you usually see in Television Remote controls.
I found a small kit for infrared IR sensor circuit and sharing this here.
For now I have added a regular LED to glow when something is detected , you can replace it with a buzzer or something else the way you wish.
The Main concept is simple , the IR led keeps transmitting IR infrared rays up to some range (there is a potentiometer also in the design with the help of which you can alter the range). When some object comes in the IR infrared range, the IR waves hits the object and comes back at some angle, Photo diode detects that IR  rays and hence works as a sensor.

Requirements
 
1  -IR  LED
1 - PR (photodiode)
1 - 1k resistance
1 - 220E resistance
1- 6k8 resistance
1 - 10k potentiometer

Circuit diagram
IR object detection circuit diagram , Object detection ,   infra red  , ir circuit diagram  ,  photo diode



IR LED and photo diode , IR object detection circuit diagram, Object detection , infra red , ir circuit diagram , photo diode

For now in this circuit a LED is glowing as an example , You can use it the way you wish, You can use it to run some DC motors and make a simple robot. Or the logic 1 can be used to do complex operation with interface to some microcontroller for some complex projects.
Use the way you want it.
Thanks for reading
Read more ...

IR Proximity Motor Control

Tuesday, 25 June 2013

IR Proximity Motor Control 

      Infrared proximity sensors are very fun to play with. In the past we have used them to make Digital Theremins and Control Robots, always using its proximity sensing (how far away an object is from the sensor) as the main feature. Today, we're going on a quest to use an infrared proximity sensor, to control the speed of a DC motor.
          In this article, we will go step-by-step through the process of understanding, designing and building a system that uses an infrared proximity sensor for input, correlates that input to how far away an object is from the sensor and then drives a motor and some LEDs at distinct speeds depending upon the proximity of the object.

IR Proximity Motor Control - Demonstration

click to see the vedio

IR Proximity Motor Control - Project Setup

Purpose & Overview Of This Project
          The goal of this project and article is to explain how to use an infrared proximity sensor to drive a motor. The system should be able to drive the motor at 8 different speeds (1 = slowest, 8 = fastest), likewise a representative LED bar will be added to give a second visual speed indicator. Up to 8 LEDs will be controlled to represent the 8 different levels of speed.
          To make this system we will use a sharp ir distance sensor (10cm-80cm) for detecting how far away the object is, a PIC 18F4520 microcontroller to interpret the input and drive the output, a 10 LED Bar for giving a visual indication of what speed we're at, and a TIP42 + DC motor for the actual motor and power transistor to drive the motor.

Parts
7805 +5v Regulator
PIC 18F4520
TIP42 Power BJT
IR Proximity Sensor
LED Bar
 +3v Motor
20 MHz Crystal
3x 10uF Capacitors
Green LED
2x 100Ω Resistor
330Ω Resistor Network
10kΩ Resistor
Breadboard
Jumper Wire
+9v Battery Connector



Parts List Details
           Luckily this project is half hardware intensive and half software intensive, so there aren't too-too many parts. Below I'll describe the most important parts in more detail.
PIC 18F4520
           This microcontroller will be used for understanding the input (an analog voltage) using its built-in Analog to Digital converter and it will also be used to drive the motor output and the LED bar output.
20 MHz
           A 20 MHz crystal will be used to run the microcontroller at a 20 MHz clock rate (5 MHz instruction rate).

Sharp IR Distance Sensor
           This sensor is the center-piece of this article. It outputs a specific analog voltage depending upon how far away an object is from the sensor.

TIP42 Power BJT
           To provide enough current to the motor we need to use a power transistor. A PWM signal from the PIC will tell the power transistor when to turn the motor on and when to turn the motor off. The PWM's duty cycle will determine the speed the motor turns.

Breadboard and Jumper Wire
           We'll use a breadboard for building the circuit since everything is low frequency. Standard jumper wire will be used to connect the circuit together.

The Sharp IR Distance Sensor
           There's two parts to the theory of this project that we need to cover before looking at the schematic. The first part is how the IR distance sensor works and the second part of the theory section will be looking at how the motor is controlled.



           The video above demonstrates in a crude manner what the output of the IR distance sensor does when connected directly to a red LED. The LED gets brighter when the piece of paper nears the sensor because the voltage output increases. The opposite happens when the piece of paper is moved backward away from the sensor.

The Sensor's Output
           Let's take a look at the datasheet's theoretical output vs. distance. The graph below shows what voltage output from the sensor you should expect when a white piece of paper is placed in front of the sensor.


           As you can see right away, the output voltage is not linear which makes things a little annoying as we won't be able to have a straight-forward correlation between voltage and distance. Sharp has made a few attempts at building an algebraic equation that you can use, check the app notes on their website for more info on those.
           We won't be dynamically evaluating the sensor output in this project and converting it to distance, instead we'll use set voltages hard-coded in the software with some if statements. That means we'll need to pick 9 voltage levels at certain distances. Below you can see the 9 we chose and the 'windows' that those points form.


          The specific distances are chosen as follows:
  • Window #1 6cm-8cm
  • Window #2 8cm-10cm
  • Window #3 10cm-12cm
  • Window #4 12cm-14cm
  • Window #5 14cm-16cm
  • Window #6 16cm-18cm
  • Window #7 18cm-20cm
  • Window #8 20cm-22cm
We call them 'windows' because each window has two sides defined by the distance. For example if the sensor's output voltage is +2.4v, then take a look at the graph above and you will see that we are inbetween 6cm and 8cm, thus we're inside of Window #1's range. Our software will create these 'windows' using IF statements.

TIP42 Motor Control
           Now, we'll take a look at how the motor will be controlled through the power transistor; the tip42. This power transistor will receive an input pulse from the microcontroller called PWM, pulse with modulation. Since the TIP42 is a PNP type transistor, any time the base pin is +0v, the transistor will be turned on and thus the motor will be turned on. To see what PWM looks like, take a look below:


PWM Explained - Pulse With Modulation

           The two images above show you two different PWM signals. The first signal is "on" 80% of the time. That means it is at +5v for 80% of the period of the signal. This is a weak signal and it would make the motor for this project run very slowly, if at all.
           The second image shows you a signal similar to the first, but it is only on 30% of the time. It is at +0v for 70% of the period of the signal. Since this PWM signal is in an 'off' state for the majority of the time, it would make the motor for this project run much fast than the first PWM.
           This might seem backwards with all the 'on' and 'off' being switched, but that is due to the fact that we're using a PNP transistor. If you want you could use an NPN transistor and everything would be opposite and therefore a little more normal.

Schematic Overview
           The schematic for this project has 4 main parts, the 18F4520 microcontroller, the sharp IR distance sensor, the power transistor and the LED bar. You can see how these parts are connected together to build the system we want in the schematic below:



View Full Schematic

Schematic Specifics

Power Supply
           To make things simple, we'll use a 7805 +5v regulator to supply the power for this entire project.

IR Distance Sensor Input
           The IR Proximity Sensor has a 3 pin connector that is super simple, Vsupply, Gnd, Vout. Vsupply is connected to +5v power and Gnd to Ground. Vout will be connecting to pin RA0 of the microcontroller, this is an analog-to-digital converter pin.

Motor Control Circuit
           The TIP42 power transistor allows the motor to be turn off or on. The base pin of the TIP42 is connected to the PIC microcontroller's CCP1 pin, which is a PWM output pin from the PIC. PWM will be used to drive the motor at different speeds as we discussed in the theory section.

LED Bar Output
           To give a visual read-out of the current status and speed level (level 0 to 8, 0 motor is off, 8 motor is full speed!) we'll use an LED Bar connected to the PIC microcontroller's PORTD. This port has 8 digital I/O pins which will each drive a single LED, on the LED Bar.


Hardware Design
           Lucky for us the hardware design and construction process is only 5 steps. Scroll down to see how it starts out!

Putting Everything Together
          Double check you have all the parts seen in the schematic and get ready to start building! The first step is always gathering the parts together so you can start building. Below you can see all the parts. I chose to use some alligator clips to connect the motor to the circuit instead of plain wire.



           The first connections are all the power supply connections, capacitors and power LED.


           Next, the basic PIC circuit is added to the breadboard, with power, ground, crystal and 10kΩ connected to the PIC.


           Now, the LED Bar and resistor network are connected to the PIC's PORTD.


           For the final step, connect the motor control circuit and IR distance sensor to the PIC.


           That's it! Now let's take a look at the PIC's firmware/software to see how we'll capture input and turn it into nifty motor controlling output!



The Software
           There are two main portions of code that we are concerned with:

    -The Initializations
    -Forever While Loop



The compiler used for this project is the C18 Compiler Provided Free From Micropchip. The first part of this software initailizes the A/D converter and the PWM module in the PIC.

PIC Initializations For Motor Control


------------« Begin Code »------------
..
...
    /*
    Timer2 Prescalary Details:
    0b00 = Prescalar x 1
    0b01 = Prescalar x 4
    0b10 = Prescalar x 16
    */
    T2CONbits.T2CKPS0 = 0;
    T2CONbits.T2CKPS1 = 0;

    // PWM Frequency = [(period ) + 1] x 4 x TOSC x TMR2 prescaler
    // Tosc = 20 MHz
    // TMR2 Prescalar = 1
    // Period = 128
    // PWM Frequency = (256) x 4 x (1/20,000,000) x 1 = 19.5 KHz
    OpenPWM1( period );

    //Motor Initially Off
    SetDCPWM1( speed_0 );

    // configure A/D convertor
    OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_20_TAD,
    ADC_CH0 & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS 
    & ADC_INT_OFF, 0 );
...
..
------------« End Code »------------

           This next chunk of code is the forever while loop which controls the motor and LED bar. This loop, takes the sensor input data, evaluates it and then outputs to the LED Bar and Motor depending upon the distance detected.

Forever Control/While Loop

------------« Begin Code »------------
    while(1){
        
        Delay10TCYx( 5 ); // Delay for 50TCY
        ConvertADC(); // Start conversion
        while( BusyADC() ); // Wait for completion
            result = ReadADC(); // Read result

        //Update Motor Speed Setting & LED Bar
        if(result < dist_6cm && result > dist_8cm){
            SetDCPWM1( speed_8 );
            PORTD = 0xFF;
        }
        else if(result < dist_8cm && result > dist_10cm){
            SetDCPWM1( speed_7 );
            PORTD = 0xFE;
        }
        else if(result < dist_10cm && result > dist_12cm){
            SetDCPWM1( speed_6 );
            PORTD = 0xFC;
        }
        else if(result < dist_12cm && result > dist_14cm){
            SetDCPWM1( speed_5 );
            PORTD = 0xF8;
        }
        else if(result < dist_14cm && result > dist_16cm){
            SetDCPWM1( speed_4 );
            PORTD = 0xF0;
        }
        else if(result < dist_16cm && result > dist_18cm){
            SetDCPWM1( speed_3 );
            PORTD = 0xE0;
        }
        else if(result < dist_18cm && result > dist_20cm){
            SetDCPWM1( speed_2 );
            PORTD = 0xC0;
        }
        else if(result < dist_20cm && result > dist_22cm){
            SetDCPWM1( speed_1 );
            PORTD = 0xFE;
        }
        else if(result < dist_22cm){
            SetDCPWM1( speed_0 );
            PORTD = 0x00;
        }

        Delay10KTCYx( 5 ); // Delay for 50TCY
    }
------------« End Code »------------

           These are the two main portions of the program. Download the full .c file at the top of the page to see the small things I left out. Give it a compile with the C18 libraries in MPLAB, load the hex file onto the PIC and the system is ready to go!

Data & Observations
           After all of that work, hopefully you're as eager as I am to test the system out and see how well (or poorly =P) it works. Below is a demonstration video of the project.



           As you can see, the system works flawlessly! The distances we chose, 6cm through 22cm in 2 cm increments were all borders of the different speeds that the motor could be controlled at. The motor responded quickly and accurately, as did the LED bar letting us know what speed the motor was currently at.


An Overview Of The IR Proximity Motor Control
           In this project, we learned about LED Bars, motor control with a single power transistor and about the sharp IR distance sensor. All of those items were combined together to make a system that could control a motor without pressing any buttons, moving a hand back and forth in front of the sensor was all you needed. The system seemed to operate fairly well in the demonstration video and the PIC did a great job as the microcontroller work-horse.



What To Do Now
           Although I've used these IR distance sensors in a variety of test, robotic and musical articles already, there's always other areas to explore. You could consider building an automated door opener for your pets, or perhaps a simple logging system that keeps track of how often a door is opened. Simple ideas, but you now have the tools to make them real!


Conclusion
           The purpose of this article was to build a motor control system that used an IR distance sensor as its controller. In that purpose and goal we were successful. We even added a simple LED Bar that gave a spedometer read out of the current motor speed. All these things combined together made for a simple yet elegant motor control system.
           If you have any further questions, I implore you...don't be shy, take a look at the forums or ask a question there. I check them out regularly and love getting comments & questions.



Read more ...

Part 1 of 3 USING AVR MICROCONTROLLERS FOR PROJECTS

Tuesday, 25 June 2013
Part 1 of 3
USING AVR MICROCONTROLLERS FOR PROJECTS
The AVR 8535 microcontroller and its new version ATmega8535 are versatile, high-performance but low-cost chips. This article series covers typical applications of this processor illustrating its power and cost-effectiveness in an embedded system.

The AVR family comprises several chips, all with almost the same instruction set. Of them, the 90S8515, 90S8535 and ATmega8535 chips are low-cost and readily available with the complete set of port pins. The ATmega8535-16 is more powerful and available for around Rs 250. Capable of running at 16 MHz and achieving almost 16 million instructions per second (MIPS), it is one of the fastest devices available in the market today.

Fig. 1: Pin configuration of ATmega8535


Fig. 2: A simple LED display circuit using ATmega8535

Using ATmega8535, you can build a microcontroller-based project with following features:
1. Four ports, of which one of them has eight analogue-to-digital converter (ADC) channels
2. ADC conversion time is as little as 60 microseconds. Imagine adding an external ADC to 8051 or any other microcontroller chip—that would have taken the cost to over four digits. And mind you, it is a 10-bit ADC, not just 8-bit.
3. If an 8MHz crystal is connected, each instruction executes in 1/8th of a microsecond. The 89C51 at 12MHz clock had its internal division by twelve, so it ran at just one microsecond. Thus, ATmega8535 chip is eight times faster with an 8MHz crystal. However, you can also use a higher-frequency crystal. The chip is basically a RISC processor that executes most instructions in one clock cycle itself.
4. The chip has RS-232 transmit and receive terminals much like the 8051 family, but it can support even higher baud rates.
5. It has quite a few internal registers, RAM, EEPROM and CODE memory (flash memory in excess of 4kB).
6. The instruction set is versatile, complete with several arithmetic, logic and transfer instructions and related jump instructions, etc.
7. An analogue comparator pin, which can compare an external analogue voltage and take control action.
8. Reset is possible through the software, and a watchdog is provided. Power-down or sleep modes are available.
9. An additional serial interface, known as the SPI bus, with three wires: data (2) and clock (1). These pins can be used for programming or loading the code from a PC through the printer port or serial port. For programming the internal flash memory locations, just 5V supply is enough.
10. Two PWM output pins, which are useful for power control applications.
11. Several timers as in other members of the 8051 family, but with much better time resolution.
12. Additional features like input capture and output compare.

Here, we shall delve into the chip’s operations with typical programs and circuits. All the development tools including ‘C’ compiler are available for free from the Internet.

The features of ATmega8535 make it the right candidate for various embedded control applications. Even a digital filter can be implemented on the device, provided you are fully conversant with its hardware and software features. You can download the databook of ATmega8535 from the ‘ATMEL.com’ Website to understand its features and work out simple applications.

The sample programs given here can be used to yield a powerful controller for many applications like a filter or motor controller.

Programming the chip

The AVR source code file with ‘.asm’ extension can be written using either the EDIT, Wordpad or notebook programs.

As with all microprocessor or microcontroller programs, for the source code, one has to enter the program by mnemonics and assembler directives and then convert the same into a code list for the program. (Directives are assembler commands used to control the input, output and data allocation of the assembler. These are, however, not translated into op-codes directly.) This is done using the cross-assembler software ‘avrasm.exe.’


Fig. 3: Circuit diagram of AVR programmer (Pod)
To describe the modus of writing of an Assembly language program, a simple program (LED.ASM) for AVR processors is given below:


This program helps you understand:
1. Access to the output port (here port B, where LEDs are connected)
2. The different parts of a typical assembler program
3. Different conventions like use of semicolon, upper-/lower-case letters, etc

Explanatory notes for LED.ASM
1. In Assembly language, all the text on a line after a semicolon (;) is treated by the cross-assembler as comments and it does not use it for code formation.

2. Including the m8535def.inc processor-specific file in Assembly program means all the I/O register names, I/O register bit names, etc appearing in the datasheet can be used. Failure to include this file may result in a number of error messages. Ensure that this file is placed in the same directory as your source code file (LED.asm in this case). Else, give complete path for the m8535def.inc file.

3. Following conventions havebeen used in the program:
(a) Words in upper-case letters are used for command directive words of the Assembly language or predefined ports of the processor.
(b) Mnemonic words are written in lower case.

4. LIST directive turns on the listing output if it had been previously turned off. Similarly, NOLIST directive, if used, will turn off the listing output.

5. DEF directive is used to define a text-substitution label for a string. A label/name is easy to remember. Here, register R16 is replaced with ‘mp’ name. Thus whenever ‘mp’ is encountered in the source code, it will be automatically replaced with ‘R16.’

Fig. 4: Screenshot of AVR-Programmer


Fig. 5: Screenshot of AVR-Programmer showing activity window
6. ‘.org $0000’ defines the reset address. When power is switched on, the program starts from this location. A restart from the reset address can be activated by resetting the respective hardware pin of the chip (pin 9) or upon watchdog timer reaching its zero count. A relative jump command (rjump) at this reset location directs the program execution to label (main)—as long as the label is within 2k locations from the reset address (0000). Incidentally, ‘rjmp main’ is the first code-generating instruction.

7. It is essential to set up the stack pointer before being able to call any subroutine, since stack is required for saving the return address, where the next program execution is to start from. The program lines starting with ‘ldi R16,low(RAMEND)’ and ending with ‘out SPH, R16’ do just that.

8. The ‘ldi mp, 0b11111111’ and ‘out DDRB, mp’ lines set port-B pins as the output. The first line, interpreted as ‘load immediate (ldi) into register ‘mp’’, loads binary value ‘11111111’ into the ‘mp’ register. The second line transfers the contents of ‘mp’ (11111111) to the data direction register of port B (DDRB). DDRB is already defined in the m8535def.inc file. (If you want to set port-B pins as input, load binary ‘00000000’ into ‘mp’ and output it to DDRB.) Incidentally, ‘0b’ precedes a binary number. Similarly ‘0x’ precedes a hex number. Numbers without these prefixes denote decimal numbers by default. Hence you may replace ‘0b11111111’ with either ‘0xFF’ or simply ‘255’ to achieve the same results.

Fig. 6: Circuit for message display on the LCD

9. The rest of the program starting at label ‘loop:’ and ending with ‘rjmp loop’ achieves switching on and off of the LEDs with a delay. The delay subroutine starting at label ‘delay:’ and ending with return instruction ‘ret’ is called from within the loop.

Initially, ‘mp’ is loaded with hex value ‘00’ and output through port-B pins, making them low. Since the cathodes of all the eight LEDs are connected to these port pins via current-limiting resistors, the LEDs light up. Thereafter, the delay subroutine (Rcall delay) is called and ‘mp’ is loaded with hex value ‘FF’ and transferred to the port-B output to turn off the LEDs. The loop is repeated as long as the power is switched on.

10. The internal R-C clock of ATmega8535 is 1 MHz by default. In the absence of ‘Rcall delay’ instruction, each of ‘ldi’ and ‘out’ instructions requires 1000 ns, while ‘rjmp’ instruction requires 2000 ns. Thus loop execution would take 4000 ns. This amounts to LED switching rate of 250 kHz.

Introduction of delay between switching on and off reduces this frequency to around 0.5 Hz by decrementing registers ‘r19’ and ‘r17’ from ‘255’ to ‘0,’ thereby making the elapsed time slower by 256×256 (which works out to around 0.5Hz rate).

After assembling the LED.asm source file, the program will have eight words. The LED.LST file stores the result of the assembly process in the form of a listing.

Once a program has been written using any editor, wordpad or notepad, it is assembled using the avrasm.exe AVR assembler, which is included in this month’s EFY-CD. Of course, the AVRSTUDIO 4.0 integrated development environment (IDE) is more versatile and user-friendly software for development, but the avrasm.exe assembler is simpler and direct.

Simply typing ‘avrasm -i LED.asm LED.lst LED.hex’ under the DOS prompt makes the cross-assembler generate code for the LED.hex file and also provide a text file giving both the code and the program together in LED.lst. Thus, you get the LED.lst listing file and the LED.hex Intel hex code file.

Fig. 7: Actual-size, single-side PCB layout for AVR
programmer (Pod

Fig. 8: Component layout for the PCB in Fig. 7

Fig. 9: Actual-size, single-side PCB layout for
message display on LCD

Fig. 10: Component layout for the PCB in Fig. 9
http://adf.ly/R66qb
Alternatively, you can prepare a batch file as follows:
Upon DOS prompt, enter ‘copy con avr.bat.’ In the following line, type ‘Avrasm -i %1.asm %1.lst %1.hex.’ Pressing ‘F6’ key in the following line displays ‘Control-Z.’ Now pressing the ‘Enter’ key displays “1 file copied.”

Now the avr.bat file has been prepared. This simple batch file is invoked to assemble this (or any) program by typing ‘Avr LED’ upon the DOS prompt and pressing the ‘Enter’ key.

This assembles the program, and forms both the list file (that contains the code-cum-Assembly listing) and the hex file (the actual Intel-format hex file for use by the programmer).

Likewise, any other assembly program ‘xxx.asm’ can be coded into the hex file by simply typing ‘avr xxx’ on DOS prompt. ‘xxx’ denotes the name of the program. The ‘.asm’ is not to be typed.

In our LED.asm program, we have included the m8535def.inc file. This file is required along with the avrasm.exe cross-assembler. For other AVR processors like 90S8515, 90S8535 and at-Tiny 26, the files to be included are 8515def.inc, 8535def.inc and tn26def.inc, respectively.

The next task is to burn the code into the chip. Note that a chip previously programmed or erased is automatically erased when a new program is burnt into it using the device programmer as described below.

The AVR device programmer
The AT-PROG programmer software is used for programming ATmega8535. This menu-drive programming software is simple to use and invoked from command prompt.

The software uses a simple pod connected to the printer port of a computer. The circuit of the pod (shown in Fig. 3) is very simple. It just connects the IC to be programmed to the pins of the PC’s printer port.

This circuit is assembled on a small PCB with a D25 male-female plug at one end. The IC base is a 40-pin zero-insertion-force socket (ZIF). This enables easy insertion and removal of the IC to be programmed.

The AT_PROG.exe is a simple programming software that can be run under DOS prompt by typing AT-PROG. The files At-prog-hlp.htm, At-prog.exe, At-prog.cfg and At-prog.ini should be placed in one directory before running the AT-PROG. These files have been included in this month’s EFY-CD as part of this article.

The menu-driven window of the AT-PROG programmer has the following menu items:
1. File menu. This menu is used to select or open the LED.hex file, or whatever, which is to be programmed into the device.

Pull down the menu by clicking it. Under ‘Open’ option, enter the file name as ‘LED.hex’ and press ‘Enter.’ The IC to be programmed is selected from the AVR-Programmer window by clicking the edge of the small rectangular window and choosing the IC as shown in Fig. 4. Now connect the printer-port connector to the programming pod, whose circuit is shown in Fig. 3.
2. Write menu. On clicking the ‘Write’ menu, the ‘Activity’ window at the bottom whitens and shows ‘Connecting’  (refer Fig. 5). Then, the data is transferred to the IC and verified after programming, showing ‘ok’ in the same window.
3. Check menu. This menu is used to find out whether the IC is inserted in the socket and whether the connector connections are okay. It will indicate an error if the IC is not there or not responding.

In this mode of programming, the serial-peripheral interface (SPI) of the AVR chip is used. This interface has three wire connections:
(i) Master output and slave input (MOSI)
(ii) Master input and slave output (MISO)
(iii) Serial clock (SCLK)

Using these wires, the SPI interface does the serial transfer of data (i.e., our program codes) into the chip, which is configured as a slave. The data and clock are connected via MOSI and SCLK pins of the chip, respectively. Upon reception of each byte, the chip acknowledges it by sending a byte (53hex).

In ‘Check’ mode, the IC is enquired about its name by the computer (Master), which it replies with its signature code embedded in the chip memory by the manufacturer. Each IC has its specific signature code. Thus, by noting the code itself, what IC is being programmed will be known to the computer. So the small window under the device-select rectangular window can be clicked to show ‘autodetect’ the IC.
4. Options menu. In this menu, the speed of the clock used for transferring data from the computer can be selected as ‘slow,’ ‘normal’ or ‘fast.’ With present high-speed PCs, choose ‘normal’ or ‘slow.’ In the same menu, the ‘read signature bytes’ option is to be enabled and it is so by default.
5. Port menu. The port menu, which is next to the file menu, is useful if a different printer port is available. The program automatically selects the available printer port.

When the ‘Activity’ window shows ‘ok’ after clicking the ‘Write’ menu, remove the programmed chip from the programmer circuit board and fix it onto the target circuit for the LED.asm program (shown in Fig. 2). Now apply 5V and press the switch connected to Reset pin, if needed. (The circuit resets at power-on.) The LEDs start blinking fast and the waveform can be observed on the CRO for any of the pins at the output to the LEDs. It will be around 600 Hz.

Message display on the LCD module
Method I. Given below is the source code for message display on the LCD module along with suitable comments wherever needed.


This program displays ‘Electronics ForU’ on the LCD module (Fig. 6). The message may be displayed on the LCD in a single or two rows depending on the LCD module. In some LCD modules, the first eight characters are written consecutively, while for display of the next eight characters, the program needs to restart the cursor at address $C0. But Hitachi-make single-row types do not need to restart the cursor’s address after the eighth entry; the characters can be written consecutively up to ‘16,’ i.e., in a single row.

The program is named as ‘LCD_CHAR.asm’ and assembled into the ‘.hex’ file by typing ‘avr lcd_char’ and invoking the cross-assembler AVR. Now the lcd_char.hex file is generated. The AT-PROG programmer burns this code into the flash memory of the ATmega8535.

Note that while assembling this program using ‘avr lcd_char’ command, the definition file for IC ATmega8535 (m8535def.inc) should be in the same directory.

Method II. This message display program uses look-up table. In the message display program described in Method I, ‘Call lcdwr’ instruction was written for each character. Here, instead, if we enter all the bytes for ‘Electronics ForU’ in a table, they can be picked up one by one until the end and shown on the LCD screen. For the purpose, there is an instruction called load program memory (LPM).

The table, as also the name, is stored in the program memory. Here is the program along with necessary comments.


The actual-size PCB for programming and LCD message display are given in Figs 7 and 9, while their component layouts are shown in Figs 8 and 10, respectively.
 
Read more ...

Automated Line Following Robot

Sunday, 23 June 2013
Automated Line Following Robot


Line-following robots with pick-and-placement capabilities are commonly used in manufacturing plants. These move on a specified path to pick the components from specified locations and place them on desired locations.

Basically, a line-following robot is a self-operating robot that
detects and follows a line drawn on the floor. The path to be taken is indicated by a white line on a black surface. The control system used must sense the line and manoeuvre the robot to stay on course while constantly correcting the wrong moves using feedback mechanism, thus forming a simple yet effective closed-loop system.

Circuit description

Fig. 1 show the block diagram of the automated line-following robot. It consists of mainly four parts: two sensors, two comparators, one decision-making device and two motor drivers. The robot is built using microcontroller AT89C51 (used as the decision-making device), motor driver L293D, operational amplifier LM324 (comparator), phototransistor (sensor) and a few discrete components.

In the circuit, the sensors (phototransistors) are used to detect
the white strip on a black background. The sensor output is fed to the microcontroller, which takes the decision and gives appropriate command to motor driver L293D so as to move the motor accordingly.

Sensor.
The sensor senses the light reflected from the surface and
feeds the output to the comparator. When the sensor is above the white background the light falling on it from the source reflects to the sensor, and when the sensor is above the black background the light from the source doesn’t reflect to it. The sensor senses the reflected light to give an output, which is fed to the comparator.

Comparator.
The comparator compares the analogue inputs from
sensors with a fixed reference voltage. If this voltage is greater than the reference voltage the comparator outputs a low voltage, and if it is smaller the comparator generates a high voltage that acts as input for the decision-making device (microcontroller).
     
Microcontroller.
The microcontroller is programmed to make the robot move forward, turn right or turn left based on the input coming from the comparator. The outputs of the microcontroller are fed to the motor driver.

Motor driver.
The current
supplied by the microcontroller to drive the motor is small. Therefore a motor-driver IC is used. It provides sufficient current to drive the motor.
    

Fig. 2 shows the circuit of the automated line-following robot. When light falls on the phototransistor (say, T1), it goes into saturation and starts conducting. When no light falls on the phototransistor, it is cut-off. A white LED (LED2) has been used to illuminate the white path on a black background. Phototransistors T1 and T2 are used for detecting the white path on the black background.
    
Collectors of phototransistors T1 and T2
are connected to the inverting inputs of operational amplifiers A2 and A1. The signal voltage at the inverting input of the operational amplifier is compared with the fixed reference voltage, which is formed by a potential divider circuit of 5.6-kilo-ohm resistor and 10-kilo-ohm preset. This reference voltage can be adjusted by changing the value of the 10-kilo-ohm preset.
    
When sensor T2 is above the black surface, it remains cut-off as the black surface absorbs virtually all the light falling from LED2 and
no light is reflected back. The voltage at the inverting input (pin 2) of operational amplifier A1 is higher than the reference voltage at its non-inverting input (pin 3) and therefore the amplifier output at pin 1 becomes zero.
    
When sensor T2 is above
the white line, the light gets reflected from the white surface to fall on phototransistor T2. Phototransistor T2 goes into saturation and conducts. The inverting input (pin 2) of operational amplifier A1 goes below the reference voltage at its non-inverting input (pin 3) of operational amplifier A1 and therefore output pin 1 goes high. This way, the comparator outputs logic ‘0’ for black surface and logic ‘1’ for white surface.
    
Similarly, comparator A2 compares the input voltage
from phototransistor T1 with a fixed reference voltage.     
The outputs of operational amplifiers A1 and A2
are fed to microcontroller AT89C51. The AT89C51 is an 8-bit microcontroller having 4 kB of Flash, 128 bytes of RAM, 32 I/O lines, two 16-bit timers/ counters, a five-vector two-level interrupt architecture, on-chip oscillator and clock circuitry. A 12MHz crystal is used for providing the basic clock frequency. All I/O pins are reset to ‘1’ as soon as RST pin goes high. Holding RST pin high for two machine cycles while the oscillator is running resets the device. Power-on reset is derived from resistor R5 and capacitor C1. Switch S2 is used for manual reset. The microcontroller, based on the inputs from sensor T1 (say, left) and sensor T2 (say, right), controls the motor to make the robot turn left, turn right or move forward.
    
Port pins P2.0, P2.1, P2.2 and P2.3 are connected
to pins 15, 10, 7 and 2 of motor driver L293D. Port pins P2.0 and P2.1 are used for controlling the right motor, while port pins P2.2 and P2.3 are used for controlling the left motor. Three wheels can be used for this robot—one on the front and two at the rear. Front wheel can rotate in any direction as specified by the rear wheel. To make the robot turn left, the left-side motor should stop and the right-side motor should rotate in the clockwise direction. Similarly, to make the robot turn right, the right-side motor should stop and the left-side motor should rotate in clockwise direction. For forward motion, both the motors should rotate in clockwise direction.

Working

An actual-size, single-side PCB for the automated line-following robot is shown in Fig. 3 (View as PDF) and its component layout in Fig. 4 (View as PDF). Fig. 5 shows the path of the line-follower robot, where ‘L’ is the left sensor and ‘R’ is the right sensor.
     At the start, when the robot is at point ‘A,’ sensors T1 and T2 are above the black surface and port pins P3.0 and P3.1 of the microcontroller receive logic ‘0.’ As a result, the robot moves forward in straight direction.
    
At point ‘B,’ a left turn is encountered, and the left sensor comes above the white surface, whereas the right sensor remains above the black surface. Port pin P3.0 of the microcontroller receives logic ‘1’ from the left sensor and port pin P3.1 receives logic ‘0’ from the right sensor. As a result, the left motor stops and the right motor rotates, to make the robot turn left. This process continues until the left sensor comes above the black background.
    
Similarly, at point ‘C,’ where a right turn is encountered, the same procedure for right turn is executed. When
both the sensors are at the white surface, the robot should stop. The output of the microcontroller (IC2) depends on the inputs received at its port pins P3.0 and P3.1 as shown in table.

Software

The source program for the project is written in Assembly language and assembled using Metalink’s ASM51 assembler, which is freely available on the Internet for download. It is well commented for easy understanding and works as per the flow-chart shown in Fig. 6. The hex file ‘robot.hex’ is to be burnt into the microcontroller.










                                                   ROBOT.ASM
$MOD51
                                  ORG 0000H
                                  LJMP MAIN
                                  ORG 0030H
MAIN:                          SETB P3.0 ;Input for left sensor
                                  SETB P3.1 ;Input for right sensor
AGAIN:                         JB P3.0,NEXT
                                  JB P3.1,GO
                                  CLR P2.0
                                  SETB P2.1
                                  CLR P2.2
                                  SETB P2.3
                                  SJMP AGAIN
GO:                             CLR P2.0
                                  SETB P2.1
                                    CLR P2.2
                                    CLR P2.3
                                    SJMP AGAIN
NEXT:                         JB P3.1,GO1                             
                                    CLR P2.0
                                    CLR P2.1
                                    CLR P2.2
                                    SETB P2.3
                                    SJMP AGAIN
GO1:                             CLR P2.0
                                    CLR P2.1
                                    CLR P2.2
                                    CLR P2.3
                                    SJMP AGAIN
HERE:                            SJMP HERE
                                    END

Download actual-size, single-side PCB layout.

Download PCB
component layout.
Read more ...