Interfacing KS0108 based 128×64 Graphical LCD with AVR MCU.

Those how are building microcontroller based project for little long must have got bored with the good old character LCDs. Whether you are bored or your application require to present more data to the user in a better way, you need Graphic LCD. Character LCD Interfacing is quite easy so every one uses it, but when I comes to Graphic LCD you need a well written and powerful graphic library. Its not enough that you read the LCD datasheet and connect it your MCU and start sending data. Because the LCD just appears to be block of memory whose contents are directly visible on screen. The datasheet can only guide you how to access this memory. You just can’t do much by writing to the memory. The graphic library is a piece of software that has complex algorithms to render graphic primitives like line, rectangles, circles, images and more. It also helps load fonts and render text and numbers on screen. So it provide high level access to the LCD screen and applications can be written much more easily. While I was researching for graphic library for the GLCDs, I found some but I was not fully satisfied by any of them. So I began to write a clean, powerful, portable and easy to use library that can handle sever […]

Interfacing MMA7260 Triple Axis Accelerometer with ATmega32 – AVR Tutorial

Accelerometers are recently developed solid state electronics devices that makes it very easy to measure acceleration. They are completely modular and very tiny devices which gives voltage proportional to acceleration. These type are called analog accelerometers as their output is voltage. Some other gives a PWM output or direct binary digital data, they are called digital accelerometers. Accelerometers are used widely in modern devices. Apple iPhone,iPad and Nokia series 60v5 devices for automatic screen orientation changing. Also for motion gaming and other showoff stuff like Xpress Beer in above devices. Portable Hard disk and Notebooks for fall detection. Anti-theft devices. Motion Gaming Consoles like Nintendo Wii. Balancing Robots and UAVs. Experiments which needs to find force, like car crash experiments. And Possibly many other. Accelerometers can measure acceleration in 2 dimensional or 3 dimensional space. They are called 2D and 3D accelerometers respectively. Accelerometers have certain range, i.e. the maximum acceleration they can measure. It is specified in terms of g. ‘g’ is the acceleration due to gravity of earth and it is equal to 9.80665m/s2. Common accelerometers can have a range of 1.5g to 6g. It is obvious that 1.5g accelerometer is more precise than 6g. So use 1.5g where more accuracy is needed while use 6g for much more harsh experiments. Renault R26 can pick up 100km/hr is […]

Interfacing LM35 Temperature Sensor with PIC Microcontroller.

The are many cool sensors available now a days, ranging from IR distance sensor modules, accelerometers, humidity sensors, temperature sensors and many many more(gas sensors, alcohol sensor, motion sensors, touch screens). Many of these are analog in nature. That means they give a voltage output that varies directly (and linearly) with the sensed quantity. For example in LM35 temperature sensor, the output voltage is 10mV per degree centigrade. That means if output is 300mV then the temperature is 30 degrees. In this tutorial we will learn how to interface LM35 temperature sensor with PIC18F4520 microcontroller and display its output on the LCD module. First I recommend you to go and read the following tutorial as they are the base of this small project. Interfacing LCD Module with PIC Microcontrollers. Making the LCD Expansion Board for PIC18F4520. Using the ADC of PIC Microcontrollers. After reading the ADC tutorial given above you will note the the PIC MCU’s ADC gives us the value between 0-1023 for input voltage of 0 to 5v provided it is configured exactly as in the above tutorial. So if the reading is 0 then input is 0v, if reading is 1023 then input is 5v. So in general form if the adc read out is val then voltage is. unsigned int val; val=ADCRead(0); //Read Channel 0 voltage= […]


Using the ADC (Analog to Digital Converter) of PIC Microcontroller

Many electrical signals around us are Analog in nature. That means a quantity varies directly with some other quantity. The first quantity is mostly voltage while that second quantity can be anything like temperature, pressure, light, force or acceleration. For example in LM35 temperature sensor the output voltage varies according to the temperature, so if we could measure voltage, we can measure temperature. But most of our computer (or Microcontrollers) are digital in nature. They can only differentiate between HIGH or LOW level on input pins. For example if input is more than 2.5v it will be read as 1 and if it is below 2.5 then it will be read as 0 (in case of 5v systems). So we cannot measure voltage directly from MCUs. To solve this problem most modern MCUs have an ADC unit. ADC stands for analog to digital converter. It will convert a voltage to a number so that it can be processed by a digital systems like MCU. This enables us to easily interface all sort of analog devices with MCUs. Some really helpful example of analog devices are Light Sensors. Temperature Sensors. Accelerometers. Touch Screens. Microphone for Audio Recording. And possibly many more. In this tutorials we will learn to use the internal ADC of PIC18 devices (Example is for PIC18F4520 which is […]

Remote Controlled Fan Regulator using ATmega8

This device can be used to remotely control the speed of an AC fan and to switch it on or off. The remote control is a cheap NEC Format remote, usually supplied with small DVD players. Three buttons are used to command the circuit. The UP key increase the fan’s speed while the DOWN key decrease it. The ENTER key is used to switch on or off the fan. The unit provides 10 way speed control from 0 to 9. The current speed is displayed in a seven segment display. The yellow LED on the PCB indicates the power status of the load. If the load is switched off using the R/C then the LED will also be switched off. In the Video below you can check out the project in action. The main parts of the circuit is labeled below. The seven segment display used to show the current speed level. The TSOP1738 sensor is used to pick up commands from remote control. The Yellow LED indicates the power status of the load. OUT – Here the AC load is connected in series. Tested on 220v 50Hz AC line. IN – Power supply from a 12-0-12 transformer is applied here. MCU – ATmega8 AVR 8 bit Microcontroller. SWITCH – Manual Switch used to operate the unit without the remote […]

Servo Motor Control by Using AVR ATmega32 Microcontroller

Servo motors are a type of electromechanical actuators that do not rotate continuously like DC/AC or stepper motors, rather they used to position and hold some object. They are used where continuous rotation is not required so they are not used to drive wheels (unless a servo is modified). In contrast they are used where something is needed to move to particular position and then stopped and hold there. Most common use is to position the rudder of aircrafts and boats etc. Servos can be used effectively here because the rudder do not need to move full 360 degrees nor they require continuous rotation like a wheel. The servo can be commanded to rotate to a particular angle (say 30) and then hold the rudder there. Servos also employs a feedback mechanism, so it can sense an error in its positioning and correct it. This is called servomechanism. So if the air flow exerts pressure on rudder and deflects it the servo will apply force in opposite direction and try to correct the error. Say if you ask servo to go and lock itself to 30 degrees and then try to rotate it with your hand, the servo will try hard and its best to overcome the force and keep servo locked in its specified angle. Servos are also used […]

Obstacle Avoiding Robot using AVR ATmega32 – Part III

Hello All, Welcome to the third part of the Obstacle Avoiding Robot Tutorial. Till now we have completed the mechanical construction and made the sensor for our robot. I have shown you how to control the motors and read values from sensor in last two parts of the tutorial. In this tutorial we create the master program for our robot. The job of the program is simple, to read values from the sensors, make a decision and command two motors. In this way our robot will roam about the room avoiding obstacles in its path. In our program we define three constants, namely RTHRES,CTHRES and LTHRES in the following way :- //Threshold Values For Sensor Triggering #define RTHRES 195 #define CTHRES 275 #define LTHRES 195 The constant value next to them is the triggering values. You can get this values as described in previous tutorial. Simply run the IR Sensor Test program and bring any obstacle near the sensor at about 15cm (6 inches) and note down these values against respective sensor threshold values. Do same for all three sensor. Now the program knows when the value comes near this threshold value, the sensor has a obstacle in front of it. Note that the value shown above is may not match with the values you obtained, that OK. In our […]

Making “The LCD Expansion Board” for PIC18F4520

In this tutorial I you show you how to make a very useful expansion board for our PIC development board. It will be a Do It Your self (DIY) LCD Expansion board. The expansion board can be plugged into the PIC development board to add 16×2 Alphanumeric LCD Support to it. Since LCDs are required in many projects and experiments it will be a very helpful board. I recommend you to read the LCD Interfacing Tutorial before you proceed. It will give you an Idea how LCD is connected to PIC Microcontrollers. So lets start! Schematic for LCD Expansion Board. Fig.: LCD Module Interface with PIC Microcontroller. The board is very easy to make as the MCU core unit is already done for you. So you need to just care about the LCD part. It consists of the 16×2 LCD Module and A variable resistor (10K) only! Optionally you can add a 47ohm series resistor with the LED backlight of the LCD Module, to enable the backlight. The variable resistor is used to adjust the contrast of the module. If NO text is displayed adjust this pot. All I/O ports and power supply is available at the top of expansion board. Fig.: A blank expansion. As you can see the top row in the board lists all I/O port of […]

Introduction to PIC18′s Timers – PIC Microcontroller Tutorial

Timers are common features of most microcontroller. In simplified terms a timer is just a register whose value keeps increasing (or decreasing) by a constant rate without the help of the CPU. The CPU can read or write this register any time. It reads it find out how much time has elapsed. The Timer register can have the following bit length 8 bit timers – These can count between between 0-255 16 bit timers – These can count between 0-65536 32 bit timers – These can count between 0-4294967296 A timer has a clock source, for example of the clock source of 10KHz is input to a timer then one increment will take 100uS (micro second). This clock source can be obtained from the CPU clock. The CPU clock of popular MCU ranges from 1 MHz to 20Mhz, this can be sometimes too fast. To help us out their is a thing called prescaler in the MCU. The job of prescaler is to divide the CPU clock to obtain a smaller frequency. The PIC Micro that we will use in this example has the following prescaler division factors available. 256 128 64 32 16 8 4 2 1 (Prescaler by-passed) Timers are also called Counters this is because they can be used to count external events. The following example illustrate […]

RS232 Communication using PIC18F4520′s USART – PIC Microcontroller Tutorial

Hello Friends! In this tutorial I will discuss how to practically do a simple communication over RS232 interface. For those who are completely new to this I clarify that the motive is to send and receive data between two device using a standard called RS232. RS232 is serial interface that means that data is transferred BIT by BIT at a time. Since data is transferred BIT by BIT so we need only a single wire two send data and an another one to receive data. One more common wire (called GND) is required between two separate circuit to enable current flow. So a total of three wire are required for communication. RS232 can be used to communicate between a variety of devices. Like your MCU and a GSM module or a PC. In this tutorial we will demonstrate a link between a PIC18F4520 MCU and a standard PC. On PC we will run a terminal program like RealTerm or Hyperterminal. A terminal program is used to send and receive text data. So any text send by the MCU will be visible on Terminal Screen and Any keypress you make on the PC keyboard will be send over RS232 to your MCU. This configuration is the simplest setup to test and understand RS232 communication. When you have enough knowledge you can […]

Obstacle Avoiding Robot using AVR ATmega32 – Part II

Hello and Welcome back to the second part of Obstacle Avoiding Robot Tutorial. In the last part we studied the drive system and the mechanical construction of our robot. In this part we will make the sensor part. The sensors will help our robot detect obstacle in its path. The sensor system is of very basic type of infrared(IR) reflectance sensor. It is made up of an IR Transmitter and an IR receiver. The IR transmitter is an IR LED which emits light in IR spectrum that is invisible to human eye. The IR receiver can detect those rays. A Matching Pair of IR Rx and Tx, The Blue One is Tx (LED). The IR Sensor Element The IR Sensor element is made up of an IR Tx,IR Rx and few resistors. The schematic is given below. We need three such elements mounted in front of the robot to sense obstacles in front of it. IR Reflectance sensor schematic. As you can see the sensor element has two pins for power supply and an Output pin. The output is a variable voltage between 0 and 5v depending on the type and distance of the obstacle. It tends to 5v as some obstacle comes near it. IR Sensor Construction Guidelines. The value of R1 is 150 ohms and R2 is 22K. […]

Multiplexed Seven Segment Display using PIC16F877A and HI-TECH C

#include <htc.h> #define _XTAL_FREQ 20000000UL typedef unsigned char UINT8; typedef signed char INT8; typedef unsigned int UINT16; typedef signed int INT16; //Connection of Seven segment display #define SEVEN_SEGMENT_LAT PORTD #define SEVEN_SEGMENT_TRIS TRISD //MUX Control #define MUX_PORT PORTB #define MUX_START_POS 1 //From which bit on port the select lines start //MUX settings #define MUX_DISP_COUNT 4 //Number of displays //Global Varriable UINT8 DisplayArray[MUX_DISP_COUNT];//Holds ‘data’ for each disp void SevenSegmentWrite(UINT16 n) { /* n=data to dislay example: n=1234 will display 1234 in a 4 segment display Working: This function breaks apart a given integer into separete digits and writes them to the display array i.e. digits[] */ UINT8 i=0; UINT8 j; while(n) { DisplayArray[i]=n%10; i++; if(i==MUX_DISP_COUNT) break; //We don’t have room for more digits n=n/10; } //Fill Unused area with 0 for(j=i;j<MUX_DISP_COUNT;j++) DisplayArray[j]=0; } void WriteSegment(UINT8 num) { switch (num) { case 0: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B01000000; break; case 1: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B01111001; break; case 2: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B00100100; break; case 3: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B00110000; break; case 4: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B00011001; break; case 5: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B00010010; break; case 6: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B00000010; break; case 7: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B01111000; break; case 8: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B00000000; break; case 9: //-GFEDCBA SEVEN_SEGMENT_LAT = 0B00010000; break; } } void Wait() { UINT8 i; for(i=0;i<1;i++) __delay_ms(10); } void main() […]