Saturday, April 28, 2012

Electronics Project: Basics for doing it yourself - 1

In this post I will discuss about some essential things you need in order to do electronics project. Electronics has always been my hobby and I spent most of my college time doing electronics projects. At the beginning of my college I learnt how to use bread-boards and knew about resistor, capacitors, diodes and transistors. When I learnt digital electronics and micro-controllers I was fascinated by them and kept on playing with them. I was regular subscriber of EFY magazine and I used to try DIY circuits in my home. Now, the time has come; I have to share my experience with you.

An electronic circuit is composed of individual electronic components, such as resistors, transistors, capacitors, inductors and diodes, connected by conductive wires through which electric current can flow. The different combination of these components when done properly is used to perform different operations such as signal amplification, computation of data, and so many things. The motherboard of your computer itself is an example of a complex electronic circuit which consists of different ICs. Whereas, inside your battery charger you can find a simple electronic circuit. So, the complexity is based on the application of the circuit. To be able to make an electronic circuit you must first know behaviour of each components when current flows through them. The components such as resistor, capacitor and inductors are passive components; meaning that the current flowing through them is directly governed by voltage applied to them. The other components such as diodes and transistors are active components. I would like to briefly introduce you about these components. You can go through your course book or find more information in the Internet about these component so, I will be more focused on their application in electronics projects.


Resistors offers a resistance to the flow of current. It is characterized by  resistance values measured in ohms and their power ratings measured in Watts.   Resistance is the ratio of potential difference (V) between the two terminals and the current (I) flowing through it i.e. Resistance (R)= V/I ohms. Resistances range from 10 ohm to 56Mohm(or more) and power ratings from 1/8W to 20W. We mostly use resistance in this range even though more power rating high value resistors are available. So, when you select a resistor its value and power rating should be the deciding parameter. Normally available resistors are 1/8W, you can see this type of resistors in the resistance box which contain resistances from 10 ohm to around 56Mohm, costs around Rs.30. But this resistor leads are flexible such that it will get bend easily. These 1/8W resistors are used in low power devices. The one which available in shops are of 1/4W which we mainly use. P= (I^2) * R, heat dissipation on resistor depends on the current flowing through it. Therefore for high current operations we use resistance of higher current ratings. The size of the resistor determines its power rating. Suppose if you put a resistor series with a motor which have a rating of 250mA(DC motor) -600mA(Stepper motor), then you can see that P= (I^2)*R = 0.25^2*R= 0.0625R. Assume R=10 ohm then P= 0.625W>1/2W. In this case you have to use a resistor of about 1W or more.There are two types of resistors - fixed and variable.

Now let's see how you can measure the resistance of a resistor. This is done by color coding over the resistor or you can use multimeter to measure resistance. As a beginner you should use color coding. See the following diagrams carefully, you can see that 4-band code, 5--band code and 6--band code (see next diagram). But we mainly get resistors of 4-band code.You can get a 1/4W resistor for Ps.20 irrespective of the value of its resistance. Due to the aging and other temperature effects, value of a resistor will change. That change is indicated using tolerance. The following figure show how to bend a resistor so that you can insert it in a breadboard. Don't bend too much close to the body of the resistor because it will leads to the breaking of the leads. So bend carefully. Sometimes you have to cut the leads of the resistor by some amount so that it can easily inserted properly.

Remember that all the values of fixed resistances are not available. Suppose if you want a 2Kohm resistor in your circuit, you can use a variable resistor (potentiometer) or two 1Kohm resistor in series. 

If you are interested in programming then I can send you the link to download a program with source code that calculates resistance of a resistor according to its colour code or by a value. This program was written using C#.NET with Framework  version of 3.5 so, you need .NET Framework 3.5 installed in your OS to run this program. If you are using Windows Vista or later you can enjoy using it as .NET Framework is pre-installed. Screenshot of this program is shown here. You have to be follower of this blog if want to get download link. I hope you will  do this by clicking follow at right sidebar of this blog.

Variable Resistor (Potentiometer):
Potentiometer is a variable resistor which is used to vary the resistance by rotating the shaft. Potentiometers are available from 100 ohm to 470Kohm (or more). Cost depends on the size of potentiometer, vary from Rs. 4 onwards. It is sometimes used as a voltage divider. If we connect  Lead A to Vcc and Lead B to ground then you can get voltages from 0 to Vcc by taking voltage at Lead A and Lead B.

Above figure shows different types of potentiometers available in market. Second and third potentiometers are mainly used when you want to change the value of resistance rarely and first one used when you had to vary resistance frequently. Second and third one are easy to be inserted in breadboard and they remain fixed. Resistance is varied by rotating the shaft in the body of the potentiometer.

A capacitor is a passive component that is used to store energy in an electric field. It is characterized its capacitance, measured in Farads (F). This is the ratio of electric charge (E), measured in Coulombs (C) on each conductor to the potential difference (V) between them i.e. Capacitance (C)= E/V Farad. Like resistor there is fixed as well as variable capacitor also. But, we mostly use fixed capacitor and variable capacitor is used in application such as radio frequency tuning. The capacitor may or may not have polarity. Ceramic and Mica capacitors available in the market have no polarity, but electrolytic capacitors have polarity. The capacitors have different symbols.
In the above figure, we can see that different symbols are used for capacitors. The non-polar capacitor can be placed in a circuit in either way but, when polarized (electrolytic) capacitor is to be placed we have to be careful in placing them in the circuit. We can differentiate negative and positive leads of electrolytic capacitor by their length however, it is best to differentiate them by looking at capacitor itself. The negative lead is indicated by black band imprinted in the body of capacitor, which contains - sign as you can see in the above figure. Also, the electrolytic capacitors have voltage ratings; which indicates the maximum potential difference the capacitor can tolerate between its terminals. It is a very important factor in choosing the capacitor for you circuit. If your circuit is operating in say 25V and you are placing 16V capacitor then you may damage the capacitor. So, you have to be very careful when choosing the capacitor in your circuit.

Ceramic capacitors in general have the rated values in pico-Farad (pF) and electrolytic capacitors have the values in micro-Farad (uF). Ceramic capacitors have many marking specification. Capacitance, tolerance, working voltage and temperature coefficient may be seen imprinted on the capacitor with black colour text. Capacitance values are found to be written as whole numbers without any identification as to units (uF, nF, pF). Whole numbers usually indicate pF and decimal numbers such as 0.1 or 0.47 are micro-farads. Larger whole numbers (>100) such as 473 means 47*10^3 pF = 0.047 uF.

Here, the capacitor rated as 22 has a capacitance of 22pF. The capacitance of capacitor rated 104 can be found as; the first two digit are significant digits and last digit indicate number of zeros after the significant digits. So, 104 means capacitance(C)= 10*10^4 pF= 100000 pF= 100nF= 0.1uF. Similarly, 103 means C= 10*10^3 pF= 10nF= 0.01uF. You may also find values such as 104K, 103M, 102J etc. where the last alphabet denotes tolerance of the capacitor i.e. how much the capacitance is varied from rated value. K indicates 10%, M indicates 20% and J indicates 5%.

Capacitors are widely used in electronic circuits for blocking direct current while allowing alternating current to pass, in filter networks, for smoothing the output of power supplies, in the resonant circuits that tune radios to particular frequencies and for many other purpose.

A diode is a two terminal semi-conductor device used for conducting current flowing through it only in one direction called forward direction. It has asymmetrical transfer characteristic, with low resistance to current flow in one direction, and high resistance in the other. A semiconductor diode is a crystalline piece of semiconductor material with P-N junction connected to the terminals. The unidirectional behaviour of diode is used to convert alternating current (AC) to direct current (DC), including extraction of  modulation from radio signals in radio receivers. There are different types of diode which has specific purpose such as; Zener diode is used for voltage regulation, Avalanche diode are used to protect the circuit from high voltage surges, Varactor diode is used to electronically tune radio and TV receivers, Tunnel diode is used to generate radio frequency oscillations and Light Emitting Diode (LED) is used to produce light. You can find more information about these diodes in the Internet so, we will only  focus on generic semiconductor diode and LED which are the most used diodes.

You can see a white ring close to one of the terminal which indicates N terminal of the diode and the other  is P terminal. You can see white text in black background in the form of 1Nxxxx, this represents model number of the diode that has charactersitics defined in its datasheet. You can Google the part number and find out its power rating, threshold voltage, and other required parameters. To determine whether a diode is working or not we need a multimeter with diode checking function. Then, we determine its forward voltage by connecting positive terminal and  negative terminal  of multimeter to the P-terminal and N-terminal (Forward Bias) of the diode  respectively. For 1N4001, it is about 1.2V and for 1N4007 it is about 1.4V. You can go through datasheet of the diode and find out their forward threshold parameter to check any diode. In the figure alongside, you can also see LED and from there you can determine P terminal and N terminal of a LED. The length of terminals as well as the shape of bottom view is used to determine them. The method to check a LED is similar to diode; we have to forward bias it and check to see whether it glows or not. Also, you have to note the voltage reading shown in multimeter because it is used to determine a series resistor connected to it's one of the terminals. Generally, you need to connect a series resistor to prevent excessive current flow in the LED otherwise, that current could damage the LED. The resistance is usually between 200 ohm to 2.2Kohm according to current being applied in the circuit.

Now, you can connect the circuit as shown below and use it as AC line indicator. Plug the P-terminal of diode to one of the terminal of AC line and plug one of the terminal of resistor in other terminal of AC line. This works because the diode rectifies positive half cycles of AC to DC and 100K ohm resistor is used here as series resistance to drop excessive voltage and block excessive current flow to LED. When positive half cycles reach P-terminal of LED the negative half cycles appear at N-terminal and the LED is forward biased and turns on and, when negative half cycles of AC appear at P-terminal of diode, it gets blocked (reverse biased) allowing no current to pass through it and the LED turns off. So, there is turning on and off of LED at every 0.02 second however, we cannot notice it. Thus, this circuit can be used as AC line indicator.

I hope this post has helped you understand as well as review some of the important terms you encounter while doing projects. If you like this post or you have comments please do not forget to write it. I like to hear from you.

Thank you.

Thursday, April 26, 2012

Card games made using VB.NET

In this post I will be introducing you some of the card games that I have made using VB.NET and C#.NET. You might have played some of the card games that came with Windows OS like Solitaire, Freecell, Hearts etc. These are well enough to seize your free times. I have made some other type of card games such as Solitaire 11, TenKiller etc. to introduce some other card games that are not available in Windows OS. Now, let me introduce Solitaire 11 card game.

Solitaire 11 is a single player card game for Windows OS. It is one of my first card game (Complete) that is bug free and works in Windows XP, Vista and 7. I have created it using Visual Studio 2005 with .NET Framework 2.0. The idea came to my mind when I first played the card game in my vacation with my friends. I planned to develop it using VB.NET as I was just moving from VB6 to .NET. As I am not an artist, I worried how could I draw the card faces. Then I captured all the card faces and deck designs from existing Windows card games so it becomes familiar to the player. I have not used windows title and border to make it more like game.

Game play:
A single pack of well shuffled card is distributed in twelve places without seeing them.  If the sum of two cards are 11 then they are covered by top cards in the pack. You can not put cards if it contains face cards like Jack, Queen and King. However, if they appeared at very first deal, and they are not overlapping any cards you can bring them back to bottom of the pack and replace them by placing a card from top of the pack.
In this game you need to click Deal at top-left corner. As soon as you click this button you will get twelve cards distributed from the pack. Then you have to click any two cards that have sum 11 like, 7 and 4, 6 and 5, 10 and Ace, etc. You can also replace Jack, Queen and King that appeared at first deal by clicking them. The more they appear at first deal the more there is chance to win. The game is won if you finished all the pack of cards and you loose if there is no any valid sum of 11 is left. The timer runs as soon as you click the deal and determines how fast you won the game which will be used to calculate your score (fate). To start a new game just click Deal again. You can click Help on/off to guide you. Its so cool.

See it in action. Please comment after watching the video.

Hope you enjoyed reading this post. I will post more games on my next post.

Thank you.

Some cool C# console applications

If you are new to C# and want to explore some cool features of this programming language, just mail with your short introduction and your purpose to me and  I will give you the link to download. The first three console application would demonstrate the object oriented programming in C#. If you want to explore more there is a Hangman game made using console application. Game description and screen-shots of the game is below:

Description of Hangman game:
I have always been interested in making games using different programming language such as C, C++, QBasic, Java, and Visual Basic. This time I decided to make this popular game using C# language to explore and face challenges in C#. I have tested this game many times and hopefully its bug free.  

Main Menu:
The main menu for this game is similar in operation as old DOS programs. It is entirely created using ASCII characters used for drawing box. Unfortunately, C# console application does not allow mouse events, so you cannot use mouse to select or click the menu items. The main menu consists of five items. You can view the description of each item on bottom-left corner of the screen. You can change category of words to guess using Categories menu. Also, you can turn sound on or off using Sound menu. These settings are saved and retained next time you open the game.

Game Play:
This is game play screen. Here you can see the chosen category in yellow colour. The words that you have to guess is from the particular category. You can also see how many words you have correctly guessed and how many of them are incorrect. You need to guess the word by pressing the alphabets in your keyboard. If your guess is correct it will appear there replacing - (dash) and if it is incorrect the body of a man appears at the base of the pole. You have ten chances, after that the man is suspended on the rope with pretty animation.

This is the about dialogue box. The game name is flashed with different colours; a kind of simple animation. Can you notice the shadows of the box, it is also present in Main Menu and Game screen. There is an amazing trick to display shadows in application like these. 

I hope after reading this you are interested in trying the game once and see the source code for the game. I have well documented the source code and its so easy to understand. You need Visual Studio 2010 to open the project files. Also, you need .NET Framework 3.5 or higher to run this game in your PC. If your PC meets the requirement just mail me I will send you the link.

See it in actions. Please comment after viewing this video.