Showing posts with label IR. Show all posts
Showing posts with label IR. Show all posts

Monday, November 14, 2011

§Automatic Railway gate control system using AVR

Hello Friends,
                 After a long delay, now again I am ready to post some interesting projects. Here I am sharing automatic Railway Gate control system using AVR micro controller. Gates will close automatically when train arrival and open when train departure from crossing. The main purpose of this project is to avoid accidents and save time.

  

This project utilizes Two IR Tx./Rx. Pair is placed at either side of the gate with some distance as shown in the pic above. When train cuts first sensor light signal toggled from Green to Red; a buzzer gets activated for 2 seconds and railway gate will closed. When train cuts second sensor then a countdown timer starts and when it counts zero light signal again toggled from Red to Green ; again buzzer gets activated for 2 Seconds and gates will closed. Timing for countdown timer is set in the controller according to the speed and length of the train. You can easily measure this timing for your toy train. I made this bidirectional so train’s direction doesn’t matter.

I design circuit using AVR ATmega8 microcontroller.IR sensors output is connected to comparator LM324.LM324 generates TTL High/Low signal at its output pins which is fed to MCU's pins as Input. According to input from LM324 Micro-controller take action. Two DC Motors is used for controlling the gate, these motor's current requirement is much more then MCU hence we need a Motor Driver IC L293D.

Required Components:
1.DC Geared Motors RPM:30 - 2
2.IR Tx./Rx. Pairs - 2
3.MCU ATmega8 - 1
4.IC-LM324 - 1
5.IC-L293D - 1
6. Registers 470E - 10,10K-2,4.7K-1
7.Capacitors : 1000uF.16volt -1 , 100nF-1
8.Seven Segment CC - 1
9.Some LED's : 2- Green, 2-Red, 3 others
10.7805 -1
11.6Volt,4.5MAh Battery
12.some wires, burg strips etc. 

and a Toy Train --


Circuit Diagram:


Making:
step 1 : First make the sensor setup.IR Tx./Rx. should be connected in line of sight. Two signal LEDs. Total five wire comes out from this sensor setup- VCC, GND, Sensor Output, Red LED anode, Green LED anode. Distance between IR Tx./Rx. is about 12cm.


Sensor Setup - 1


Sensor Setup - 2

Step:2 Gear Motor's setup.




Step:3 Circuit design. I design the layout in PCB-Wizard.


 


Step:4 Whole setup -




See Video for more clarification.

Software : source code is written in C. MCU - Atmega8 @1MHz internal.Compiler - WINAVR.

#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>

#define CUT1 bit_is_clear(PIND,0)
#define CUT2 bit_is_clear(PIND,1)

#define BEEP PORTD|=(1<<PD4);\
delayms(1500);\
PORTD &=~(1<<PD4);\

#define MOTOR_CW PORTC = 0B00111010;\
delayms(800);\
PORTC=0X00;\

#define MOTOR_ACW PORTC = 0B00110101;\
delayms(800);\
PORTC=0X00;\

#define RED_ON  PORTD|=(1<<PD6);\
PORTD&=~(1<<PD7);

#define GREEN_ON PORTD|=(1<<PD7);\
PORTD&=~(1<<PD6);

char seg[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

void delayms(uint16_t ms){
  while(ms){
    _delay_ms(1);
    ms--;
  }
}

int main()
{
DDRC = 0xFF;//All Outputs
DDRB = 0xFF;//All Outputs
DDRD = 0XF0;//PD0,PD1 Inputs,PD4-PD7 Outputs
PORTD|=(1<<PD0)|(1<<PD1);//Internal Pull Ups

int i,done;
while(1){
   done=0;
   GREEN_ON;
   PORTB=0X00;//Segment OFF

    if(CUT1){
    BEEP;
    while(CUT1);
    while(!CUT2){RED_ON;if(!done){MOTOR_CW;done=1;}}
    if(CUT2){for(i=9;i>=0;i--){PORTB=seg[i];delayms(700);}
    BEEP;GREEN_ON;MOTOR_ACW;
      }
    }

    if(CUT2){
    BEEP;
    while(CUT2);
    while(!CUT1){RED_ON;if(!done){MOTOR_CW;done=1;}}
    if(CUT1){for(i=9;i>=0;i--){PORTB=seg[i];delayms(700);}
    BEEP;GREEN_ON;MOTOR_ACW;}
    }
  }
 return 0;
}


After making this project I realize some limitation, first it required different type of IR sensors which should not detect human interrupt and second thing is at gate closing time if any vehicle present in between and below the gate then gate should detect the presence of any vehicle or obstacle. If you resolve these then please share.
 


                    circuit diagram

Video:
                                                                                                                ~Pratyush

Thursday, April 21, 2011

§Line Tracker : Tiny2313 based line follower robot


Hello,
          Here i am going to explain a very simple well known and Interesting project "Line Tracking Robot". Line tracker is a machine that can track a path. The path can be visible like a black line on a white surface  or it can be invisible like a magnetic field.
How to Sense Line??
Line can be Black on a White surface or White on a Black surface.To sense the line we can use LDR, IR Sensor etc. The basic concept is that when light falling on that Sensors they get activated.

 

When light falls on a black surface it will completely absorbed by the black surface. And when this light fall on the white surface it will be reflected through it. I am using IR Tx. Rx. pair to sense the black line. IR Tx. continuously spread IR light (Not visible to human Eye) and when this falls on IR Rx. it will generate output in millivolt.


I am using very low cost AVR series 20 pin Tiny2313 Micro-controller. We know that MCU understand TTL logic +5v for HIGH and 0v for LOW. The output of the IR sensor is fed to the MCU  pins but the output of the sensor is in millivolt ; MCU always consider it as LOW. Hence we require an Amplifier to amplify the sensor's output at TTL level.

We can use comparator which compares potentials at its Inverting and Non-inverting terminals and gives +5V or 0V signal at the output, now we can fed the output of comparator to MCU i/o pins. One major  advantage is to select Comparator as amplifier is that we can adjust the sensitivity of our sensors. LM324 is a 14-pin quad comparator IC.
LM324 Pin details
According to sensors outputs MCU takes decision and moves the Motors. Here again one thing  is to remember that the output current of MCU is not sufficient to drive the DC-Motors hence we require a Motor Driver IC. I am using very popular L293D Motor Driver IC.
Block Diagram according to above discussion-


IR Sensor and LM324 Connection.Repeat this circuit three times.The Output of LM324 is fed to the PORTD (PD0,PD1,PD2) of Tiny2313.

 Make the array of  IR sensors according to circuit below.Look the images in making steps which describes it clearly.
 
Motor Driver L293D Connections : The MCU generates outputs according to sensors input; output of MCU from PORTB(PB0,PB1,PB2,PB3) connected to pin 2,7,15,10 of L293D respectively.

  Look the table's below to understand how it work.
                

 Complete Circuit Diagram :

 

 Making Steps :
step:1
 step:2
 step:3
step:4
 step:5
 step:6
 step:7
 step:8
 step:9
 step:10
 step:11
 step:12
 step:13
 step:14
 step:15
 step:16
 step:17
 step:18
 step:19
 step:20

Code : Code is very basic and easy to understand for beginners. You can modify this to make more powerful.

/*Microcontroller: ATtiny2313
CPU Frequency: 1MHz Internal 
Compiler: WinAVR*/

#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>

#define TURN_LEFT                  0b00001011
#define TURN_RIGHT                0b00001110
#define MOVE_FORWARD       0b00001010
#define ROTATE                         0b00000110
#define MOVE_BACKWARD    0b00000101
#define STOP                               0b00001111

void delayms(uint16_t millis) {
  while ( millis ) {
    _delay_ms(1);
    millis--;
  }
}
int main(void){

  unsigned char sensor;
  
  DDRB = 0xFF;   //PORTB output port
  DDRD = 0x00;   //PORTD input port
 
  while(1) {

    sensor = (PIND & 0x07);

    switch(sensor)
        {
            case 0x00:PORTB = MOVE_FORWARD;   //000
                             break;
   
            case 0x01:PORTB = TURN_RIGHT;            //001
                            break;
   
            case 0x02:PORTB = MOVE_FORWARD;   //010
                             break;

            case 0x03:PORTB = TURN_RIGHT;            //011
                             break;

            case 0x04:PORTB = TURN_LEFT;              //100
                             break;

            case 0x05:PORTB = MOVE_FORWARD;    //101                   
                             break;

            case 0x06:PORTB = TURN_LEFT;                //110   
                             break;

            case 0x07:PORTB = STOP;                           //111
                            break;
               
            default:PORTB = MOVE_FORWARD;   
                       break;
        }
           }
     return 0;
  }

Troubleshooting :
1.First check the IR Transmitter is working or not. IR light is not visible to human eye ; use your mobile camera to see the IR light.
2.Check the power supply using multimeter.
3.If L293D gets heated don't worry its not a problem.
4.Most important thing is to adjust the sensitivity of the sensors by varying the 10k Pots.Without proper adjustment of Pots robot doesn't move properly.
5.You can connect one extra base for LM324 to extend this Robot in Obstacle Avoiding Robot in Future the circuitry will same only IR sensors is increased and little modification.
6.If motors rotate on opposite or reverse direction then change the polarity of motors.

Downloads :

Video: LINE-TRACKER

 

If this article is useful for you then don't forget to leave comment.Your suggestion and questions are also invited.
                                                                                                                        ~pratyush

PID Controlled Self balancing Robot using ESP8266 and MPU6050

This ROBOT is made using ESP8266 Node MCU and MPU6050 accelerometer. Motor used here is normal gear motor of 150 rpm with TB6612FNG motor dr...