Cognoscis

Think. Understand. Apply

Simple line follower

Posted by cognoscis on 6th November 2009

I have covered the sensors part in detail in previous posts. Now I will go ahead and describe how to build a very simple line follower (Something I should have done a long time ago). There are a few important things that you must consider before actually building a line-follower. First and foremost, what kind of sensors are you going to use? LDRs are easy to build and very cheap but are not efficient in noisy environment. If the environment in which you intend to use it is noiseless (Has uniform lighting or illumination) then you can go ahead and use LDRs. On the other hand, if you are looking at a sensor that can withstand high noise, then IR sensors are the way to go. The choice of sensor is independent of the rest of the circuit. It is only important from the sensitivity point of view.

Now that you have chosen a sensor, always remember that it will give you a HIGH or a LOW output at the end. Now you can make this high to represent either a presence or absence of a white line (say). It is completely in your control. For the sake of example let us consider a white line on a black background. Now, you place your sensors so that it is on the background, then the sensor sees black. Now set your comparator such that it will output a high when this voltage is fed at its input. A NOT gate can be used to reverse this if you want to. It is completely flexible and in your hands to modify. Next is to decide on a logic circuit to drive the bot. Depending on your logic, the number of sensors will vary. In this example, I am going a use a very simple logic that requires only two sensors. Next, you must consider the placement of sensors. Lastly, the motor driver, meaning, the circuit that will enable you to drive the motors. So, lets start building now.

I will build a white line follower (White line on a black background). For this, LDR or IR sensors can be used. For construction of LDR sensor click here and for IR click here. Now, we have two sensors which are like two eyes of our bot. Using these “eyes” we make it see the line and make it follow the line. Once you have built the sensors’ circuits and tested them individually as explained in those posts, you must no consider their placement. Placement is very very important. Make sure you place them towards the front of the vehicle and they must be on the black background when stationary and not on white line. Now you may wonder why that would be? That is because, its the best way to follow any line. Always, try to locate the background (this I learnt from experience). Refer the figure below to understand it

Placement of the sensors

Placement of the sensors

In the figure, the green circles are the two sensors that hover over the sides of the central white line that is to be followed. The yellow part to which we attach all our circuits, motors and batteries is called the chassis (Pronounced cha-see). Anyway, Now that the placement of the sensors is taken care of, i.e., the eyes have been placed. Now, you need to give it “legs” that being the motors and wheels.

For this purpose, there are many methods that are used. first lets see our “driving force” that is given by the motors. Two important considerations are to be kept in mind. First, what will be the total weight that will be driven by these motors. That will help you in choosing the right torque for the motors. Generally speaking, most of the motors are rated in terms of rpm (rotations per minute). One thumb rule is that lower the rpm of a motor, higher is its torque for the same voltage. So, for starters, I would suggest you to go for 150 – 200 rpm 12 V motors. This will give you reasonable torque and controllable speed for our primitive logic circuit. Second, consideration is the battery power. As suggested above, if you use 12 V motors, you can run them on a 9 V battery, but its rpm and torque will be reduced because the energy supplied by the battery is not what the motor expects for full performance. Of course, you can use 9 V + 3 V to make 12 V and supply it to the motors. That time the motors will run at full speed. But once the battery drains (which is fast if the robot is heavy) the rpm will reduce. You need to consider these things when you start building high precision robots. But for now, we can ignore it for time being.

For wheels, you can use wooden wheels. I use wooden wheel that we got from a wood works shop after a lot of requesting. You can also try toy wheels and use adhesives to fix the wheel to the shaft. You might go for the commercial wheels sold in shops along with the motors if you can access them. When using wooden wheels do remember to put a piece of cycle tube around it for frictional purposes. As for the front, you get Caster wheels wheel that are the best suited for such applications, the ones that are used in movable chairs and stools, but only very small in size. This can be seen in the image below

Ball caster wheels

Ball caster wheels

Then depending on your motors you can use either L-clamp or U-clamp to fix the motors to your chassis. Now comes the electronics part of the robot. Remember, if you use 12 V DC motors, then you will need two separate power supplies. One 12 V for your motors, and the other 5 V for your sensor and control circuit ICs. Since this is not feasible, we will use a “Voltage Regulator” that will take 12 V as input and give 5 V as output. There are many such ICs, we will use the popular LM 7805 voltage regulator (its datasheet can be downloaded from here). The circuit diagram and the image of the IC is as shown in the figure below. The two capacitors are very crucial and must not be omitted from the circuit.

LM 7805 IC with Circuit Diagram

LM 7805 IC with Circuit Diagram

Once we have over come the issue of dual power supply, we can now go ahead and try to run the motors. But, there is a problem, the output of sensors is 5 V but the motors need 9-12 V at least to run. That means, we need to have some kind of a mechanism to convert that 5 V signal to 12 V signal. A number of options are available for this. Pure mechanical relays can be used but these are bulky and not preferred by many. We can then turn to what are called as motor driver ICs which are specially made for this purpose. One more advantage of using them is that we will get some familiarity at the initial stage itself and we will be one step ahead while designing more complex robots as we may require to operate the motors in two different directions (ex. Remote controlled vehicle). That time, these motor drivers come in very handy and will considerably reduce the circuit size. There are a number of motor drivers in the market, many beginners prefer ULN 2003, but I think we can go for L293D motor driver or rather quadraple half H-Drivers as they are called. Datasheet can be found here. Just observe the circuit diagram of the IC in the figure below

L293D internal circuitry

L293D internal circuitry

As seen in the internal diagram, this driver IC has 4 half H-drivers (Triangular buffers in the figure). Each of this driver is made up of transistors to form a H-bridge (totally 6 transistors) that are capable of driving the motors in one direction. So, to drive a motor in both the directions, we need to utilize two such half bridges. As shown above, the pins 4, 5, 13 and 12 are ground pins that must be connected to your circuit ground. Pin 16 is Vcc1 which supplies for the IC. So, we connect it to 5 V as shown in figure below. Now, a 5 V at pin 1 will enable the driver 1 and driver 2 where as a 5V at pin 9 will enable driver 3 and driver 4. In our circuit below, we are using drivers 1 and 4 for the convenience of connection and hence we connect pin 1 and pin 9 to Vcc1 which is 5 V. Since we only go forward following the line, we will use only half the bridge. So, we connect one end of the motor to output of the driver which is pin 3 for driver 1 and pin 14 for driver 4. The other end of the motor is grounded. Make sure that same ends of motor are grounded and the motor is rotating in the forward direction only. If it is rotating in reverse direction, just interchange the connections and you will be able to drive the motors forward all the time. Now, the output of your two sensors must be given as input to these motor driver bridges. That is pin 2 for driver 1 and pin 15 for driver 4 as shown in the figure below. Finally, the most important part is the 12V connection must connected to pin 8 which is Vcc2. Make sure you connect the left sensor output to left motor driver and right sensor output to right motor driver.

L293D with Circuit Diagram

L293D with Circuit Diagram

Thats all! Now just to clarify, for the chassis you can use almost anything. You can use a piece of plywood sheet, or a switch board plate which is a Bakelite plastic or you can use Aluminium sheet or perforated sheets that you gets in some shops. It totally depends on you and what materials are available to you. Now that we are done, its time to try out the line follower. Take a big sheet and paint it black and make a white track. Then calibrate your sensors ( on how to calibrate refer the sensor related posts that here towards the end of the post). Once that is done, just place your robot on the track and watch it go. Once you actually make this first robot, you will become aware of all the practical difficulties that one faces during making a robot work. This is the first step one must take to enter the field of robotics. The first one I ever made, I made it “see” the white line (which I advised you to avoid) and hence it was not very successful when it was presented with obstacle. Watch the 3gp video of the same :D

Any problems, suggestions, broken links; please notify using the comments :)

Tags: , , , , , , , , , , , , , , ,
Posted in Robotics | 2 Comments »

Modulated IR sensor

Posted by cognoscis on 3rd October 2008

You want better quality sensors that are immune to noise and have a good range too. All the conventional methods yield low range. Hence, we go for the modulated IR sensors. Modulation is a process of imposing the message signal on a “carrier”. Anyways, lets not get deep into it. For the context, its just that we use a particular frequency to transmit and receive the signal that is used in the sensor. Now, I am going to discuss the circuit that works around a IR receiver IC called TSOP. This receiver works at 38kHz frequency, hence the transmitter must be woring at the same frequency. So, lets design an IR transmitter for the same.

As shown, we use 555 timer in the astable mode to get the required frequency and supply it to the IR LED. The operation of the timer is pretty straight forward. The relevant equation is given below

f=1/(0.693 x C2 x (R1 + 2 x R2))

The values I have given are just an example. You can try out different combinations so that you will be able to place resistors that are close to the calculated values(meaning, we dont get resistors with value 111? so choose the value carefully). The reisitors R3 and R4 are current limiters and the transistor 2N2222 is used as a switch. You may use any other transistor as a switch. Now, lets come to the tricky part

The LED will always need more cooling time. You cant pump in more current into the LED than what it can take. If you dont take care of that, the LED will overheat and will be spoilt or worse generate very high noise. Hence, be sure of the current it can take and set a suitable value to R4. of course you can calculate the current flowing through the LED by considering the branch from VCC-R4-transistor-LED-ground. Usually the drop across the transistor will be 0.2V (It depends on which transistor you use) and the drop across the LED is around 2V (Again it depends on your LED). So, 5V for VCC minus 2.2V which leaves 2.8V across the resistor R4. So, 2.8/47? ? 60 mA .

This is the same current that flows through you LED!! Simple right? Now, depending on your LEDs you can increase the current flowing. Varying R3 will increase the current too so you may use that to tweak your power. Also, you can send the 38kHz as bursts for short time. This will allow the LED to cool between bursts. By doing this, we can increase the current that is driven through the LED thereby increaing the power output. More power means, more range. But be careful NOT to send more that 125% of the rated current calue through your LED. A simple burst circuit may consists of two timers, one at 38kHz and other at 1kHz and these are given to AND gate. Hence, the output will be burst of 38kHz waves for 0.5ms(50% duty cycle). You can use 2 LEDs in the same circuit, but you need to decrease the resistance R4 appropriately. But more than 2 is not recommended.

Now lets look into the receiver part. TSOP is an IR receiver module. It has many series that work at 38kHz and 40kHz. Lets consider the 38kHz(Since I have used it, I am considering it. You may try the other receiver modules as well, there are plenty of modules available in the market).

Its a 3 pin IC as shown and the pin that is away from the other two is pin number 3. Pin 1 in ground and pin 2 is Vcc. Pin 3 is the output of the sensor which will be a logic 1 or logic 0. Please read the datasheet for more details. Anyways, this receiver IC makes our life much simple as we dont need to break our head to build a receiver circuit and get digital output from it. The simplest way to connect the circuit is as shown below

Simple right? Anyways, you need to orient your sensor and transmitter correctly so that you can receive the reflected wave efficiently. So, mounting is very important of both your LED and TSOP. The receiver has a directivity of 45°. So, you might want to see to it that you will keep it aligned as straight as possible. To use this IC efficiently, as mentioned earlier, use two timers and AND gate to send burst of signals. That will eliminate noise and the efficiency and accuracy of the receiver will improve. As said in the data sheet “After each burst which is between 10 cycles and 70 cycles a gap time of at least 14 cycles is neccessary.” Hence, by sending bursts, you will be able to improve the range also. This circuit must give you a range of 30 cm from transmitter and receiver.

Any suggestions, corrections or queries please comment :)

Tags: , ,
Posted in Robotics | 7 Comments »

IR sensors

Posted by cognoscis on 13th June 2008

After the LDRs, I now come to the next level of sensors, the Infra red sensors. I am going to describe the use of IR LED and IR photodiodes today. Now, if you have my post about LRD sensors(http://cognoscis.wordpress.com/2008/05/01/sensor-ldr/), you will notice that the working of the IR sensors in exactly the same. Then whats the advantage of using these sensors one might wonder. The main advantage of IR sensors in that it will not be affected by noise as much as the LRDs would be. Since LRD use white light, there can be many sources of noise for it.

IR LEDPhotodiode

IR LED(left) and IR detector(right)

The picture shows an IR LED and a photodiode that can detect IR radiations. We use the same principle as that of the LDR when we use these IR sensors to follow a white line. Once you have seen its working, you can apply it for different purposes. Similar to LDR, the photodiode will conduct only when IR light falls on it. That is, its resistance is very high when IR light DOES NOT fall on it; and its resistance is very low when IR light falls on it. Here again the output will be analog in nature as in the LDR circuit. So, if you are using this output to drive any IC, you will need to convert this to a digital signal first. That can be done in two ways, using comparators or using ADCs(Analog-to-Digital Converters). I will be using the comparator(similar to the LDR circuit) as its very easy to handle and also cheap. After the comparator, you will get a signal that can be fed to any IC, be it a micro-controller or logic gates.

IR emitter and detector circuit

IR Sensor circuit (Click to view)

The above circuit shows a simple design of sensor circuit. Towards the left is the emitter part. The 120? resistance is to limit current through the diode. You can make the LED grow brighter of dimmer by changing the value of resistance. But the problem with IR is that we cannot see it. But, the cameras can. If you have digital camera, mobile camera or a web camera, just see the image being formed on the screen, you will find that the LED glows with a green or blue colour. See, how easy it is :)

Now, lets see what happens in the detector part. This is the same as the LDR circuit. The comparator used here is the ever popular LM339D. its a quad comparator IC package. It has four comparators and here only one of them is shown. The potentiometer R2 acts as the reference voltage for the comparator. You can use a potentiometer of 10k?/10 turns so that you can set a suitable reference value. The IR detector is placed between VCC and ground. Now this acts as a switch. When OFF, the input to the comparator is VCC. When ON, input to the comparator is zero. Now, after you set up the circuit( preferably on your bread board) check the various voltage levels once.

See the voltage at the center pin of the pot(potentiometer) that is given to the pin 7 of LM339D. Now, by turning the pot you will be able to vary this voltage. Set it to 2.5V initially. Now, you check the voltage at pin 6 that is due to the detector. First, when the IR detector is covered, you will see that the voltage is equal to VCC. Now, allow the light to fall on the IR detector and see the fall in the voltage. It will around 0.5 to 1 V. Now, that you have tested your inputs, its time to see if you are getting the proper output.

The resistance R3 at the output is called the pull up resistor. The chip provides an output of only ground. hence, you pull up the output line to high using this resistor unless the IC pulls it down. Now, when the light falls on the IR detector, the input at in 6 will be less than the reference voltage which we have set at 2.5V. Now, the output will be low. If you take the light off the IR detector, the voltage at pin 6 rises above the reference. Hence, the output will be high. Thus, we get a digital output from the circuit. Now, one more good thing about this circuit is that you can set your reference voltage level by varying the pot. This will help to operate the sensor in any environment. All you need to do is check the minimum and maximum voltage from the LDR as described before and set the reference voltage value somewhere in between the two values obtained. Thats how you calibrate your sensors to a given environment.

Any problems or additions, please post as comments )

Tags: ,
Posted in Robotics | 12 Comments »

Sensor – LDR

Posted by cognoscis on 1st May 2008

Sensors help the robots become autonomous. Sensors, are just like eyes, ears and skin of the robot. They give your robot the necessary tools to sense its environment and decide on its own what to do next. Depending on your applications, there are different sensors available. Some of the common ones used by hobbyists are LDRs, IR detecting diodes, modulated IR receivers, Ultrasound sensors and the LASER sensors.

LDRs and the IR detecting diodes are the ones that have short range and are usually used in robots like a line follower which does not require a longer range. The are relatively cheap and easy to work with. So, as the topic name goes, I will be describing about using LDRs today.

Light Dependant Resistors or photoresistors or photocells are devices that change their resistance when light falls on them. When there is no light, it will have very high resistance. As the light intensity increases, its resistance decreases. Hence, we can use a LED and focus the light on to and surface that you want to detect. Place a LDR in the path of reflection. Thus, depending on the intensity of the reflected light, we will have different resistance and hence, the robot will be ale to sense its surroundings. Lets see how to use the LED and LDR to detect a white line.

I will be using a white LED(meaning it will emit white light) in this post. White LED will give good sensing ability for the fact that white light is reflected fully by a white line. So, we will be able to sense the white line distinctly using a white LED. Now, the one thing you must be aware before going into building the circuit is that the output of the sensor you get will be analog in nature. So, if you are using this output to drive any IC, you will need to convert this to a digital signal first. That can be done in two ways, using comparators or using ADCs(Analog-to-Digital Converters). I will be using the comparator as its very easy to handle and also cheap. After the comparator, you will get a signal that can be fed to any IC, be it a micro-controller or logic gates.

LRD sensor circuit LDR sensor circuit

LDR sensors

LDR sensors

The above circuit shows a simple design of sensor circuit. Towards the left is the emitter part. The 120? resistance is to limit current through the diode. You can make the LED grow brighter of dimmer by changing the value of resistance.

Now, lets see what happens in the LDR circuit part. The comparator used here is the ever popular LM339D. its a quad comparator IC package. It has four comparators and here only one of them is shown. The potentiometer R1 acts as the reference voltage for the comparator. You can use a potentiometer of 10k?/10 turns so that you can set a suitable reference value. The output from the LDR is given to the other input of the comparator as shown. Now, after you set up the circuit( preferably on your bread board) check the various voltage levels once.

See the voltage at the center pin of the pot(potentiometer) that is given to the pin 7 of LM339D. Now, by turning the pot you will be able to vary this voltage. Set it to 2.5V initially. Now, you check the voltage at pin 6 that is due to the LDR. First, when the LDR is covered, you will see that the voltage is less. Depending on the lighting conditions, it must be well within 1V. Now, allow the light to fall on the LDR and see the rise in the voltage. It will around 4 – 4.5 V. Now, that you have tested your inputs, its time to see if you are getting the proper output.

The resistance R3 at the output is called the pull up resistor. The chip provides an output of only ground. hence, you pull up the output line to high using this resistor unless the IC pulls it down. Now, when the light falls on the LDR, the input at in 6 will be less than the reference voltage which we have set at 2.5V. Now, the output will be low. If you take the light off the LDR, the voltage at pin 6 rises above the reference. Hence, the output will be high. Thus, we get a digital output from the circuit. Now, one more good thing about this circuit is that you can set your reference voltage level by varying the pot. This will help to operate the sensor in any environment. All you need to do is heck the minimum and maximum voltage from the LDR as described before and set the reference voltage value somewhere in between the two values obtained. Thats how you calibrate your sensors to a given environment.

Any problems or additions, please post as comments :)

Tags: ,
Posted in Robotics | 10 Comments »