Monday, 7 July 2014

Interfacing lcd (4-bit mode)with ATmega 16

write this code in avr studio4/6....
/*this programs prints "S"char on lcd
#include <avr/io.h>
#include <util/delay.h>
#define lcd_port PORTD
#define rs 0
#define rw 1
#define en 2


void  lcd_init();
void lcd_cmnd(unsigned char);
void lcd_data(unsigned char);
void dis_cmnd(unsigned char);
void dis_data(unsigned char);

void main()
{
    DDRD=0b11111111;//portd as output port


while(1)
{
lcd_init();
dis_cmnd(0x80);//position to display character
dis_data('S');
}
}

void lcd_init()
{

dis_cmnd(0x28);//
dis_cmnd(0x02);//home position
dis_cmnd(0x0e);displays char or int with cursor .'0x0c' for no cursor
dis_cmnd(0x06);
dis_cmnd(0x01);//lcd clear
_delay_ms(1);
}

dis_cmnd(unsigned char abc)//to break 8 bit data in 2 (4bits)parts and send to instruction register
{
char div;
div=((0xf0)&abc);
lcd_cmnd(div);
abc=(abc<<4);
div=((0xf0)&abc);
lcd_cmnd(div);
}
dis_data(unsigned char abc)//to break 8 bit data in 2 (4bits)parts and send to instruction register
{
char div;
div=((0xf0)&abc);
lcd_data(div);
abc=(abc<<4);
div=((0xf0)&abc);
lcd_data(div);
}
lcd_cmnd(unsigned char abc)//sends command to lcd port
{
lcd_port=abc;
lcd_port&=~(1<<rs);//rs=0
lcd_port&=~(1<<rw);//rw=0
lcd_port|=(1<<en);//en==1
_delay_ms(1);
lcd_port&=~(1<<en);//en=0

}
lcd_data(unsigned char abc)//sends data to lcd port
{
lcd_port=abc;
lcd_port|=(1<<rs);//rs=1
lcd_port&=~(1<<rw);//rw=0
lcd_port|=(1<<en);//en==1
_delay_ms(1);
lcd_port&=~(1<<en);//en=0

}
//string and integer display function will be introduced in next blog...

Sunday, 16 March 2014

INTRODUCTION TO ARDUINO

An Arduino board consists of an Atmel 8-bit AVR microcontroller with complementary components to facilitate programming and incorporation into other circuits. An important aspect of the Arduino is the standard way that connectors are exposed, allowing the CPU board to be connected to a variety of interchangeable add-on modules known as shields. Some shields communicate with the Arduino board directly over various pins, but many shields are individually addressable via an I²C serial bus, allowing many shields to be stacked and used in parallel. Official Arduinos have used the megaAVR series of chips, specifically the ATmega8, ATmega168, ATmega328, ATmega1280, and ATmega2560. A handful of other processors have been used by Arduino compatibles. Most boards include a 5 volt linear regulator and a 16 MHz crystal oscillator (or ceramic resonator in some variants), although some designs such as the LilyPad run at 8 MHz and dispense with the onboard voltage regulator due to specific form-factor restrictions. An Arduino's microcontroller is also pre-programmed with a boot loader that simplifies uploading of programs to the on-chip flash memory, compared with other devices that typically need an external programmer. This makes using an Arduino more straightforward by allowing the use of an ordinary computer as the programmer.




At a conceptual level, when using the Arduino software stack, all boards are programmed over an RS-232 serial connection, but the way this is implemented varies by hardware version. Serial Arduino boards contain a level shifter circuit to convert between RS-232-level and TTL-level signals. Current Arduino boards are programmed via USB, implemented using USB-to-serial adapter chips such as the FTDI FT232. Some variants, such as the Arduino Mini and the unofficial Boarduino, use a detachable USB-to-serial adapter board or cable, Bluetooth or other methods. (When used with traditional microcontroller tools instead of the Arduino IDE, standard AVR ISP programming is used.)


The Arduino board exposes most of the microcontroller's I/O pins for use by other circuits. The Diecimila, Duemilanove, and current Uno provide 14 digital I/O pins, six of which can produce pulse-width modulated signals, and six analog inputs. These pins are on the top of the board, via female 0.10-inch (2.5 mm) headers. Several plug-in application shields are also commercially available.



The Arduino Nano, and Arduino-compatible Bare Bones Board and Boarduino boards may provide male header pins on the underside of the board to be plugged into solderless breadboards.


There are many Arduino-compatible and Arduino-derived boards. Some are functionally equivalent to an Arduino and may be used interchangeably. Many are the basic Arduino with the addition of commonplace output drivers, often for use in school-level education to simplify the construction of buggies and small robots. Others are electrically equivalent but change the form factor, sometimes permitting the continued use of Shields, sometimes not. Some variants use completely different processors, with varying levels of compatibility.To learn arduino in detail FOLLOW THIS LINK
www.ele.uri.edu/courses/ele205/...Lab.../Arduino%20-%20Learning.pdf

Wednesday, 26 February 2014

A very simple IR remote control switch for an electrical appliance





project describes a technique of adding the remote control feature to an electrical appliance. The goal is to construct a black box where you can plug-in your 120V AC appliance (it can be easily modified for 220 V mains supply too) and control the ON and OFF operations with a TV or DVD remote that uses modulated infra-red (IR) pulse train of 38 KHz frequency. I did this project for my wife who studies late at night on her bed and later feels tired to stand up and turns the light off. Now she does it from bed with the TV remote. The good thing about this project is that it does not use any microcontroller and is only based on the CD4017 decade counter IC.







Circuit diagram
The original circuit diagram for this project was published in the May 2005 issue of theElectronics For You magazine. The circuit diagram below is mostly the same. It uses a TSOP1738 IR receiver module at the input side to receive the 38 KHz frequency IR pulses from the remote control. Under normal condition, the output pin of the IR module is at logic High, which means the transistor T1 (BC557 PNP) is cut-off and its collector terminal is at logic Low. The collector of T1 drives the clock line of the CD4017 decade counter.
Now lets see what happens when somebody faces a TV or DVD remote towards the TSOP1738 and presses any key on it. The TSOP 1738 module receives the train of 38 KHz IR pulses from the remote, that makes its output to oscillate too. These pulses are inverted at the collector of T1, which finally go to the clock input of the decade counter. The arriving pulses could increment the CD4017 counter at the same rate (38 KHz), but because of the presence of the RC filter circuit (R1 = 100K, C1 = 10 uF) between the collector and the ground, the train of pulses appear as a single pulse to the counter. Thus, on each key pressing, the CD4017 counter advances only by a single count. When the user releases the key, the C1 capacitor discharges through the R1 resistor, and the clock line is back to zero. So every time the user presses and releases a key on the remote, the CD4017 counter receives a single pulse at its clock input.Initially, when the circuit is just powered on, the Q0 output of the CD4017 decade counter goes high. The counter increments for each low-to-high going pulse arriving at its CLK pin (14). When the first pulse arrives, Q0 goes Low and Q1 is turned High. This activates the relay and the AC appliance connected to it is turned on. The status LED connected to Q1 also glows to indicate the appliance is switched on. When the user presses a key again, the second pulse arriving at the CLK line increments the counter by 1. This makes Q1 back to Low (which means the relay is deactivated and the appliance is turned off) and Q2 is pulled High. Since Q2 is wired to the Reset input, the second key press actually brings the CD4017 IC back to the power-on-reset conditions with Q0 High. Thus, it basically operates as an ON/OFF toggle switch controlled with any key of an infrared remote.
The power supply for the circuit can be derived from the mains AC itself using a step down transformer and a bridge-rectifier circuit. For +5V power supply, the LM7805 regulator IC can be used as shown below.

I have enclosed the circuit board with the power supply inside a wooden box as shown in the pictures below. The electrical appliance to be controlled can be powered from the AC outlet at the front side.



This was a very simple and fun project to do. If you are thinking about making this device for yourself, be careful with the direct 120 V AC lines used in the project.

LINE FOLLOWING ROBOT USING MICROCONTROLLER ATMEGA16

FIG:-  Funtional  Block diagram

EXPLANATION:-
The robot uses IR sensors to sense the line, an array of 8 IR LEDs (Tx) and sensors (Rx), facing
the ground has been used in this setup. The output of the sensors is an analog signal which
depends on the amount of light reflected back, this analog signal is given to the comparator to
produce 0s and 1s which are then fed to the uC.
                                     
          Left Center Right
          Sensor Array
          Starting from the center, the sensors on the left are named L1, L2, L3, L4 and those on the right
          are named R1, R2, R3, R4.
Let us assume that when a sensor is on the line it reads 0 and when it is off the line it reads 1
The uC decides the next move according to the algorithm given below which tries to position the
robot such that L1 and R1 both read 0 and the rest read 1.
                 
                      L4 L3 L2 L1 R1 R2 R3 R4
                       1   1   1   0   0   1     1     1
Desired State L1=R1=0, and Rest=1

Algorithm:
1. L= leftmost sensor which reads 0; R= rightmost sensor which reads 0.
If no sensor on Left (or Right) is 0 then L (or R) equals 0;
Ex:
Left Center Right
Here L=3 R=0
Left Center Right
Here L=2 R=4
2. If all sensors read 1 go to step 3,
else,
If L>R Move Left
If L<R Move Right
If L=R Move Forward
Goto step 4
3. Move Clockwise if line was last seen on Right
Move Counter Clockwise if line was last seen on Left
Repeat step 3 till line is found.
4. Goto step 1.
L4 L3 L2 L1 R1 R2 R3 R4
1     0   0    1   1    1    1    1
L4 L3 L2 L1 R1 R2 R3 R4

1     1    0   0   0    0    0    0


will be updated soon...............................................
#include <avr/io.h>
#include <util/delay.h>
#define lcd_port PORTD
#define rs 0
#define rw 1
#define en 2



void  lcd_init();
void lcd_cmnd(unsigned char);
void lcd_data(unsigned char);
void dis_cmnd(unsigned char);
void dis_data(unsigned char);



void lcd_init()
{

dis_cmnd(0x28);//4-bit mode
dis_cmnd(0x02);//home position
dis_cmnd(0x0c);//no cursor
dis_cmnd(0x06);//auto increment
dis_cmnd(0x01);//clear
_delay_ms(1);
}

dis_cmnd(unsigned char abc)
{
char div;
div=((0xf0)&abc);
lcd_cmnd(div);
abc=(abc<<4);
div=((0xf0)&abc);
lcd_cmnd(div);
}
dis_data(unsigned char abc)
{
char div;
div=((0xf0)&abc);
lcd_data(div);
abc=(abc<<4);
div=((0xf0)&abc);
lcd_data(div);
}
lcd_cmnd(unsigned char abc)
{
lcd_port=abc;
lcd_port&=~(1<<rs);//rs=0
lcd_port&=~(1<<rw);//rw=0
lcd_port|=(1<<en);//en==1
_delay_ms(1);
lcd_port&=~(1<<en);//en=0

}
lcd_data(unsigned char abc)
{
lcd_port=abc;
lcd_port|=(1<<rs);//rs=1
lcd_port&=~(1<<rw);//rw=0
lcd_port|=(1<<en);//en==1
_delay_ms(1);
lcd_port&=~(1<<en);//en=0

}
void string1(unsigned char abc[])
{
int i=0;
while (abc[i]!='\0')
{

char c;
c=abc[i];
if(i==16)
{


dis_cmnd(0xc0);


}
dis_data(abc[i]);
i++;
}
}

*********make a HEADER FILE  named lcd1 and paste it in util folder of avr
*********LFR WITH LCD CONNECTED ON PORT D*********88
#include <avr/io.h>
#include <util/lcd1.h>
#include <util/delay.h>

void main(void)
{  
DDRD=0b11111111;//lcd output
lcd_init();
DDRA=0b00000000;//sensor
DDRB=0b11111111;//motor

    while(1)
    {
      if((PINA&0b00000011)==0b00000011)
 {
dis_cmnd(0X01);
_delay_ms(10);
 string1("FORWARD");
 PORTB=0b00001010;//forward
_delay_ms(10);
 }

 if((PINA&0b00000011)==0b00000010)
 {
 dis_cmnd(0X01);
 _delay_ms(10);
 string1("RIGHT");
 PORTB=0b00001000;//right
  _delay_ms(10);
 }

 if((PINA&0b00000011)==0b00000001)
 {
 dis_cmnd(0X01);
 _delay_ms(10);
 string1("LEFT");
 PORTB=0b00000010;//left
  _delay_ms(10);
 }
  if((PINA&0b00000011)==0b00000000)
  {
  dis_cmnd(0X01);
  _delay_ms(10);
  string1("STOP");
  PORTB=0b00000000;//stop
  _delay_ms(10);
  }




    }
}
//in next post telepathic line follower (one robot follows other through rf)

TEST YOUR BASIC ELECTRONICS KNOWLEDGE (50 MCQ)

Electronics within you!!   
Note:    1. ALL QUESTIONS ARE COMPULSARY .                                                      maximum marks:100
2.NO Negative Marking            3.Each Question Carries 2 Marks 
Name:                                         rollno:                                  branch:                     year:
1. Which is not a "common" value of resistance:
a)2k7     b)4k4     c)1m8        d)330R
http://www.talkingelectronics.com/images/50-Q's/50-Qs-19.gif3. The four symbols are:



a)      Capacitor, Microphone, Potentiometer, Electrolytic
b)      Electrolytic, Microphone, Resistor, Capacitor 
c)      Capacitor, Piezo, Resistor, Electrolytic
d)     Electrolytic, Coil, Resistor, Capacitor
5. 223 on a capacitor represents:
a) 0.022u     u = microfarad
b) 220n          n = nanofarad
c) 22,000p    p = picofarad
 d) All of the above
7. Identify the correctly connected LED:
http://www.talkingelectronics.com/images/50-Q's/50-Qs-35.gifa)A     b)B    c)C     d)D
9. The number 0000(ignore carry) would appear just immediately after
(
a) FFFF (hex)   (b) 1111 (binary)   (c) 7777 (octal)  (d) All of the above.
11.what is the frequency of a clock waveform if the period of the wave form is 1.5 us?
a)  8khz  b)0.8 khz  c)  0.8 mhz   d)8mhz
13.The .................ensures the only one IC is active at a time to avoid a conflict caused by two IC’s writing different data to the same bus.
a)Control bus            b) control instructions
c)Address decoder    d)CPU 
15.A basic multiplexer can be demonstrated through the use of a
a)Single pole relay        b) DPDT Switch
c)Rotatory Switch          d)Linear stepper
17.It is required to construct a counter to count upto 100(decimal). The minimum number of flipflops
required to construct the counter is
(A) 8   (B) (C) 6   (D) 5

18.As a general rule for a stable Flip-Flop triggering,the clock pulse rise and fall times must be:
a)very long
b) very short
c)at a maximum value to enable the input control signals to stabilize.
d)of no consequence.

19.What type of circuit is used at the interface point of an output port in the microprocessor?
a)decoder   b)latch    c)tri –State Buffer  d)none

21.The input/output relationship of the common –collector and common-base amplifiers is:
a) 270 degree  b)180 degree  c)90 degree d)0 degree

23.The voltage where current may start to flow in a reverse-biased pn junction is called the
a) breakdown voltage      b)barrier potential
c)forward voltage             d)biasing voltage

25. 4 resistors in ascending order are: 
a) 22R   270k   2k2   1M    b) 4k7   10k   47R   330k
c) 3R3   4R7   22R   5k6     d) 100R   10k   1M   3k3
 http://www.talkingelectronics.com/images/50-Q's/50-Qs-22.gif27. The control terminal (pin5) of 555 timer IC is normally connected to ground through a capacitor
(~ 0.01μF). This is to
(A) protect the IC from inadvertent application of high voltage
(B) prevent false triggering by noise coupled onto the pin
(C) convert the trigger input to sharp pulse by differentiation
(D) suppress any negative triggering pulse
32.in 8051 microcontroller The contents of the accumulator after this operation
MOV A,#0BH
ANL A,#2CH
will be

a) 11010111        b) 11011010
c) 00001000        d) 00101000
36. channel current is reduces on application of a more positive voltage to the GATE of the
depletion mode n-channel MOSFET (true/false)

37.. Which of the following effects can be caused by a rise in temperature
a. Increase in MOSFET current (IDS)                    b. decrease and then Increase in BJT current (IC)
c. Decrease in MOSFET current (IDS)                   d. increase and then Decrease in BJT current (IC)

38.

This figure is a schematic representation of a/an:
A. differential amplifier.                                      B. inverting amplifier.
C. noninverting amplifier.                                   D. voltage follower.
41.  A red-red-red-gold resistor in series with an
      orange-orange-orange-gold resistor produces:

5k5    35,200 ohms    55k         None of the above
43. The signal at the collector will be . . . with the base.
 Inverted . . .
 In-phase . .        .
C)no output 
                         d)none of these



44.What does ‘0L’or ‘1’ on a digital multimeter stands for??
A:  A Open Circuit  B: A Closed Circuit 
C: Inductance   D: None of these
45. What value does hFE on a  digital multimeter represent?
A: Voltage Gain               B: Current  Gain     C: ‘Beta’ value of the transistor
D: ‘alpha’ value of the transistor
46. On the transistor chip BC 547,what  does B stands for?
A: A silicon made transistor        
 B: A germanium made transistor
C: A High Power Transistor      
  D: A Low frequency Transistor
49. In an intrinsic semiconductor, the Fermi-level is
(A) closer to the valence band   (B) midway between conduction and valence band
(C) closer to the conduction band   (D) within the valence band






2. The resistor identified in brown is called the:   
http://www.talkingelectronics.com/images/50-Q's/50-Qs-9.gif  a)Base bias resistor
 b)Load resistor

c)Emmiter feedback resistor

d)Bypass Resistor

http://www.talkingelectronics.com/images/50-Q's/50-Qs-39.gif4. The purpose of the capacitor:
a) To pass AC on the input to the base.
b) To  allow the transistor to self-bias
c) Block DC from the input line
d) To allow the stage to operate
http://www.talkingelectronics.com/images/50-Q's/50-Qs-26.gif6.  A capacitor and coil in parallel is called:
a)Tuned circuit
b)A Timing circuit
c)A delay circuit
d)A Schmit circuit

8. What is the octal equivalent of the binary number:
10111101
A: 675   B: 275   C:  572  D:  573
10.The following waveform pattern is for a(n) ________.
http://www.indiabix.com/_files/images/digital-electronics/digital-fundamentals/mcq5_02300.gif 
a)2 input AND gate   b)2 input OR gate
c)Exclusive-OR gate   d)none of these
12.In a 16-bit microprocessor, words are stored in two consecutive memory locations. The entire word can be read in one operation provided the first
(a) word is even   (b) word is odd
 (c) memory location is odd  (d) memory address is even
14.The technique of assigning a memory address to each  I/O device in the computer system is called:
a)    memory mapped I/O      b)Ported I/O
c)dedicated I/O                      d)Wired I/O
16.The ............ is defined as the time the output is active divided by the total period of the output signal.
a)On time   b)Off time    c)Duty cycle   d)Active ratio
20.when transistors are used in digital circuits the usually operate in the:
a)active region                       b)breakdown region
c)saturation and cutoff region   d)Linear region
22.The dc current through each diode in a bridge rectifier equals:
a)the load current              b)half the dc load current
c)twice the dc load             d)one fourth the dc load

24.. If the voltage on the base of a transistor increases, does it:
a)Turn On  b)Turn Off   c)Not enough information
d)Remain the same

26:  A resistor and capacitor in series is called a:
http://www.talkingelectronics.com/images/50-Q's/50-Qs-22.gifhttp://www.talkingelectronics.com/images/50-Q's/50-Qs-38.gifa)Pulse circuit
b)Timing/Delay circuit
c)Oscillator Circuit/Frequency Circuit
d)Schmitt Circuit


28.  Technician A says that LED-1 will be ON and LED-2 will be OFF when the circuit is connected as shown below. Technician B says that both LED-1 and LED-2 will be ON when the circuit is connected as shown below. Who is correct? :
http://www.hwscience.com/physics/electronics/multiplechoice/diode2.jpg

a)technician A only.                              b)technician B only
.

c)neither Tech A nor Tech B.      d) Technician A nor Technician B
29. In an intrinsic semiconductor, the Fermi-level is
(A) closer to the valence band         (B) midway between conduction and valence band
(C) closer to the conduction band     (D) within the valence band

30. The dual of the Boolean expression: x + y + z is
(A) x .y + z    (B) x + yz    (C) x . y . z    (D) x.y.z

31. The type of power amplifier which exhibits crossover distortion in its output is
(A) Class A   (B) Class B    (C) Class AB   (D) Class C

33. Zener diodes are most commonly used in:
A. voltage amplifier circuits.            B. oscillator circuits.
C. power supply circuits.                 D. current limiting circuits

34.A resistor with colour bands Red, Violet, Green and Black will have a value
 (A)27 K±10%K  (B)2.7 M±20% K  (C)270 K±5% K    (D)2.7 K±2%K

35.The following data refers to an experiment carried out on a Zener diode:
Reverse voltage
Reverse current
1 V
1 µA
2 V
2 µA
3 V
10 µA
4 V
20 µA
The Zener voltage will be between:
(a)   1 V and 2 V  (b) 2 V and 3 V  (c) 3 V and 4 V  (d)none of these

39. What is the approximate characteristic voltage that develops
    across a red LED?
a)1.7 V       b)3.4V       c)0.6V         d)5V

40.  The resistor marked  is: 
http://www.talkingelectronics.com/images/50-Q's/50-Qs-21.gif
Base Bias Resistor
Load Resistor
Emitter Feedback Resistor
Bypass Resistor

42. Name the 4 components: 
http://www.talkingelectronics.com/images/50-Q's/50-Qs-24.gif










Photo darlington transistor, switch, capacitor, coil
Transistor, mercury switch, piezo, coil
Photo transistor, reed switch, piezo, coil
Photo darlington transistor, reed switch, piezo, coil
47: A minterm of the Boolean-function, f(x, y, x) is
(A x¢ + y + z       (B) x y z¢    (C) x z    (D) (y +z) x

48.Space charge region around a p-n junction
(A) does not contain mobile carriers
(B) contains both free electrons and holes
(C) contains one type of mobile carriers depending on the level of doping of the p or   n   regions
(D) contains electrons only as free carriers


50. The gate that assumes the 1 state, if and only if the input does not take a 1 state is   called________.
(A) AND gate                    (B) NOT gate 
 (C) NOR gate                   (D) Both (B) & (C)


                                       
Answer:
1-d,        2-b           3-a  4-c   5-c  6-a  7-b  8-b  9-d  10-b  11-c  12-d   13-c  14-a  15-c  16-c  17-a
18-b  19-b  20-c  21-d  22-a  23-a  24-c  25-c  26-b  27-b  28-a  29-c  30-c  31-b  32-c  33-c  34-b
35-b  36-b37-c 38-d 39-a 40-a 41-b 42-d  43-a 44-a 45-b 46-a 47-b  48-a  49-c       50-d


for exciting mini project http://electrofb.blogspot.in/2014/02/70w-inverter.html