Sunday, June 29, 2014

Device Controlling Using Android

The purpose of this project is to demonstrate the basic principles of external device controlling using your android phone.

The basic principle in this project is that by interfacing an Android phone with a Arduino Board we can turn "off" or "on" some relays.
Components Required

  •           Serial Port Bluetooth Module( TTL )
  •           Arduino Microcontroller Board (ET-BASEAVR EASY328 ) Arduino Compatible Board
  •           8 channel Output Relay Board
 Connection Diagrams








Source Code For Arduino Board



For Arduino Microcontroller Board Source code

#define LED_PIN1  4
#define LED_PIN2  5
#define LED_PIN3  6
#define LED_PIN4  7

#define LED_PIN5  8
#define LED_PIN6  9
#define LED_PIN7  10
#define LED_PIN8  11

int firstSensor = 0;         // first analog sensor
int secondSensor = 0;    // second analog sensor
int thirdSensor = 0;        // digital sensor
int inByte = 0;               // incoming serial byte
boolean status_unlock;
boolean status_bluetooth;

long interval = 1000;           // interval at which to blink (milliseconds)
long previousMillis = 0;        // will store last time LED was update
int minite,sec;


void setup()
{
  // start serial port at 9600 bps:
  Serial.begin(9600);
  //pinMode(2, INPUT);   // digital sensor is on digital pin 2
  //establishContact();    // send a byte to establish contact until receiver responds
 
  pinMode(LED_PIN1, OUTPUT);
  pinMode(LED_PIN2, OUTPUT);
  pinMode(LED_PIN3, OUTPUT);
  pinMode(LED_PIN4, OUTPUT);

  pinMode(LED_PIN5, OUTPUT);
  pinMode(LED_PIN6, OUTPUT);
  pinMode(LED_PIN7, OUTPUT);
  pinMode(LED_PIN8, OUTPUT);
 
  digitalWrite(LED_PIN1, LOW);  // switch off LED
  digitalWrite(LED_PIN2, LOW);  // switch off LED
  digitalWrite(LED_PIN3, LOW);  // switch off LED
  digitalWrite(LED_PIN4, LOW);  // switch off LED
   
  digitalWrite(LED_PIN5, LOW);  // switch off LED
  digitalWrite(LED_PIN6, LOW);  // switch off LED
  digitalWrite(LED_PIN7, LOW);  // switch off LED
  digitalWrite(LED_PIN8, LOW);  // switch off LED
 
  status_bluetooth = true;
  status_unlock = false;
  sec = 0;
}

void loop()
{
  if (Serial.available() > 0) {  
      
    inByte = Serial.read();                      // get incoming byte: 

    if(inByte == 'A'){   
      digitalWrite(LED_PIN1, HIGH);        // switch on LED
      Serial.print('A', BYTE);                    // send a char
      delay(800);
      digitalWrite(LED_PIN1, LOW);        // switch off LED
      status_unlock = false;
      inByte = 0;    
    }
   
    if(inByte == 'a'){   
      digitalWrite(LED_PIN2, HIGH);        // switch on LED
      Serial.print('a', BYTE);                    // send a char
      delay(800);
      digitalWrite(LED_PIN2, LOW);        // switch off LED
     
      status_unlock = true;
      sec = 0;
      inByte = 0;    
    }
   
    if(inByte == 'B'){   
      digitalWrite(LED_PIN3, HIGH);        // switch on LED
      Serial.print('B', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'b'){   
      digitalWrite(LED_PIN3, LOW);        // switch off LED
      Serial.print('b', BYTE);                   // send a char
      inByte = 0;    
    }
   
    if(inByte == 'C'){   
      digitalWrite(LED_PIN4, HIGH);        // switch on LED
      Serial.print('C', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'c'){   
      digitalWrite(LED_PIN4, LOW);        // switch off LED
      Serial.print('c', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'D'){   
      digitalWrite(LED_PIN5, HIGH);        // switch on LED
      Serial.print('D', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'd'){   
      digitalWrite(LED_PIN5, LOW);        // switch off LED
      Serial.print('d', BYTE);                   // send a char
      inByte = 0;    
    }
   
    if(inByte == 'E'){   
      digitalWrite(LED_PIN6, HIGH);        // switch on LED
      Serial.print('E', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'e'){   
      digitalWrite(LED_PIN6, LOW);        // switch off LED
      Serial.print('e', BYTE);                   // send a char
      inByte = 0;    
    }
   
    if(inByte == 'F'){   
      digitalWrite(LED_PIN7, HIGH);        // switch on LED
      Serial.print('F', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'f'){   
      digitalWrite(LED_PIN7, LOW);        // switch off LED
      Serial.print('f', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'G'){   
      digitalWrite(LED_PIN8, HIGH);        // switch on LED
      Serial.print('G', BYTE);                    // send a char
      inByte = 0;    
    }
   
    if(inByte == 'g'){   
      digitalWrite(LED_PIN8, LOW);        // switch off LED
      Serial.print('g', BYTE);                   // send a char
      inByte = 0;    
    }   
   
    if(inByte == 'S'){   
     
      Serial.print('S', BYTE);                  // send a char
      status_bluetooth = true;
      sec = 0;
         
    }   
  } // if(Serial
 
  /*
  unsigned long currentMillis = millis();
     
              if(currentMillis - previousMillis > interval) {           
                previousMillis = currentMillis;         // save the last time you blinked the LED
               
                sec++;
               
                if(status_unlock==true){
               
                  if(sec== 11){
               
                      digitalWrite(LED_PIN1, HIGH);        // switch on LED
               
                      delay(800);
                      digitalWrite(LED_PIN1, LOW);        // switch off LED
               
                      status_unlock = false;                 
                      sec = 0;
                  }
                }
                else sec = 0;               
               
              }
 
 */
   
} //Loop

void establishContact() {
  while (Serial.available() <= 0) {
    Serial.print('.', BYTE);                   // send a capital A
    delay(500);
  }
}
ANDROID BLUETOOTH CONTROLLED DEVICE
 Android Bluetooth control application helps to control up to 8 external electrical or electronic devices. Use Android Bluetooth mobile device to  remote control your device with Bluetooth Receiver hardware Device.
Main features of the program
  • It can control  up to  8 devices.
    These devices can be turned off /on by setting Timer to ON / OFF the device and show the time.(the timer can be set to 1 minute, 15 minutes, 30 minutes, 1 hour, 2 hours, 4 hours).
    Use with Receiving device (Bluetooth Receiver Hardware Device see below).
  • Design for the Android version 4 and a screen resolution of 480 x 800 (WVGA).
  • Freeware with AD (free software)

Thursday, June 12, 2014

Interfacing LED's with a micro controller(AT89c51)

In this chapter we will learn how to interface LED using Micro controller. Here I have used the micro controller AT89c51. 
The AT89C51 is a low-power, high-performance C MOS 8-bit microcomputer with 4K
bytes of Flash programmable and erasable read only memory (PEROM). The device is manufactured using Atmel’s high-density nonvolatile memory technology and is compatible with the industry-standard MCS-51 instruction set and pin-out. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with Flash
on a monolithic chip, the Atmel AT89C51 is a powerful microcomputer which provides
a highly-flexible and cost-effective solution to many embedded control applications.
First let's see the architecture of AT89c51
 As you can see, the controller has 40 pins, of them 32 pins are the parallel ports that are used for interfacing. These 32 pins are divided into 4 ports having 8pins for each. They are named as port 1, port 2, port 3, port 4. 
Port 1:- p0.0,p0.1,p0.2,p0.3,p0.4,p0.5,p0.6,p0.7 ( pin no: 39-32)
Port 2- p1.0,p1.1,p1.2,p1.3,p1.4,p1.5,p1.6,p1.7 ( pin no: 1-8)
Port 3:- p2.0,p2.1,p2.2,p2.3,p2.4,p2.5,p2.6,p2.7 ( pin no: 28-21)
Port 4:- p3.0,p3.1,p3.2,p3.3,p3.4,p3.5,p3.6,p3.7 ( pin no: 10-17) 
Pin 18 and 19 are for connecting crystal oscillator, pin 20 is ground and 40 is vcc. 
You can use any/all of the 4 ports to interface LED's. In this experiment i had selected the Port  1:(p 0.0 - p0.7).

In this experiment we are going to interface 8 LED's. 

Components required:-


1.      8 LEDs.
2.      Micro controller AT89c51.
3.      8 registers. (330 ohm)
4.      12MHz crystal oscillator.
5.      10 KΩ fixed register.
6.      10 μf (25v) capacitor.

Circuit diagram

 

 


  Connections are made as per the circuit diagram. Here LED's are running of negative logic. That means normally every pin of port 1 have +5v as output. Here cathode of every LED is connected with Micro controller port pin and anode of all the LED's are connected to +5v supply. Thus both the legs of LED are supplied with +5v. So we  required to give 0v at the output of micro controller in order to 'ON' the LED's.

            We are sending the sequence of 0x055 and 0x0AA alternatively with some delay. Delay is in the range of few milliseconds.

Code :

        #include<reg51.h>

void delay(int time)        //This function produces a delay in msec.
{
    int i,j;
    for(i=0;i<time;i++)
      for(j=0;j<1275;j++);
}

void main()
{
      while(1)
      {
          P1=0x00; // this code turns ON the LED's
          delay(100);
          P1=0xff;  // this code turns OFF the LED's
          delay(100);
      }
}

If port 2 is used then the code becomes :-

  #include<reg51.h>


void delay(int time)       
{
    int i,j;
    for(i=0;i<time;i++)
      for(j=0;j<1275;j++);
}

void main()
{
      while(1)
      {
          P2=0x00;    // P1 changed to P2. If p3 is used then write P3 here.
          delay(100);
          P2=0xff;
          delay(100);
      }
}

 If more than one port is used then the circuit diagram becomes:-

 


 Here Port 1 and Port 3 are together used for interfacing 16 LED's. 




Code (All 16 turned ON at a times)

        #include<reg51.h>

void delay(int time)       
{
    int i,j;
    for(i=0;i<time;i++)
      for(j=0;j<1275;j++);
}

void main()
{
      while(1)
      {
          P1=0x00; // this code turns ON the LED's in Port 1
            P3=0x00; // this code turns ON the LED's in Port 3
          delay(100);
          P1=0xff;  // this code turns OFF the LED's in Port 1
            P3=0xff;  // this code turns OFF the LED's in Port 3
          delay(100);
      }
}
Code (Only 8 LED's turned ON at a times)

        #include<reg51.h>

void delay(int time)       
{
    int i,j;
    for(i=0;i<time;i++)
      for(j=0;j<1275;j++);
}

void main()
{
      while(1)
      {
          P1=0x00; // this code turns ON the LED's in Port 1
            P3=0xff;  // this code turns OFF the LED's in Port 3
          delay(100);
          P1=0xff;  // this code turns OFF the LED's in Port 1
            P3=0x00; // this code turns ON the LED's in Port 3
           
          delay(100);
      }
}
tags: interfacing LED with PIC, embedded projects for beginners, embedded tutorials for beginners, LED interfacing circuits, LED tutorials, LED blinking circuits, LED blinking tutorials, AT89c51 beginners projects, AT89c51 tutorials, micro controller tutorial projects, micro controller circuits for beginners

Parallel Ports Basics

In this chapter we will discuss about the parallel ports.

Parallel ports are a set of pins used to interface external devices. The number of such ports are different for different micro controllers. Simply it can be defined as, we know that a micro controller is a programmed device which will perform as per the program. So in order to perform some actions the controller should be connected to some device/ circuit. As an example, in circuit we want to blink an LED for 5 seconds whens a key is pressed.Then we have to connect a switch and a LED to the controller. So we use the parallel ports to connect these components. The below picture shows the basic structure to connect an LED and switch to the controller.




We can choose any two pins( depends on the type of controller) and assign one pin(say pin-1) for the switch and the other(pin-2) for connecting the LED. And the a program is written in a manner that when the switch is pressed blink the LED for next five seconds.

Program logic: when the switch is closed the pin is actually connected to ground. That means a 'zero' is given as input. Then as per the program when a 'zero' is detected in pin-1, a loop/timer starts counting till 5 seconds, and an output is given to the pin-2 till the loop/timer ends. Out put means a 'one' is given to the pin-2 which is +5 volts causes the LED to blink.


Uses of parallel ports:

Usually micro controllers are not used in simple circuits as stated above. They are always used in much bigger circuits and devices that have lots of functions depending on the situations. Situations simply mean the conditions that are given by the user.

 As example suppose we want a device, when temperature in a room is becomes higher than a particular value, which will turn on the air conditioner  and if the temperature falls beyond a value then turn offs the air conditioner. Then we have got two conditions that are, two temperatures.  Using a digital thermometer we continuously  check the temperature and the readings are given to the micro controller through any one pin of the micro controllers parallel port. Then we wright the program to detect the condition ( both the values of temperature) and also what to do for that conditions.




Or in some other devices we have to detect several conditions and have to perform so many functions. Also these ports are used to interface other chips and external memory. That will be discussed in the following chapters.

What is a microcontroller

In the first chapter we will discuss about - what is a micro controller?

So first let me tell you what is the difference between an IC and a micro controller or what is the difference between normal IC controlled circuit and a micro controller controlled circuit.


A normal IC is or integrated circuit , sometimes called a chip or microchip, is a semiconductor wafer on which thousands or millions of tiny resistors, capacitors, and transistors are fabricated. An IC can function as an amplifier, oscillator, timer, counter, computer memory, or microprocessor. A particular IC is categorized as either linear (analog) or digital, depending on its intended application.
Such an IC is pre programmed or the purpose of its application is defined by the manufactures and those IC's can be used only for that purpose.



Now come to micro controller

A micro controller is a small, low-cost computer-on-a-chip which usually
includes:–
  • An 8 or 16 bit microprocessor (CPU)
  • A small amount of RAM
  • Programmable ROM and/or flash memory
  • Parallel and/or serial I/O
  • Timers and signal generators
  • Analog to Digital (A/D) and/or Digital to Analog (D/A) conversion.
 In a micro controller, the device is user programmable. That is the user can write programs as per his needs and can be loaded into the micro controller. So a single micro controller can be used for various purposes by changing the program written into it.  
It is also called embedded controllers, because the micro controller and support circuits are often built into, or embedded in, the devices they control.Embedded products are designed to allow the user to provide input and receive results.



Basic structure of a micro controller 


Block diagram explanation:

Crystal oscillator:- It has the same function as that of a human heart. It generates the clock pulses through which the entire functions of the micro controller are carried out.

ADC/DAC:- Since the micro controller is a digital device, the ADC/DAC port/pin is used for interfacing the external analog devices

Timers/Counters:- The timer TMR0 has a wide range of applications in practice. Very few programs don't use it in some way. It is very convenient and easy to use for writing programs or subroutines for generating pulses of arbitrary duration, time measurement or counting external pulses (events) with almost no limitations.

Parallel I/O ports:- have a wide range of alternative functions:
  UART                           Universal asynchronous receiver/transmitter

  SSI                                Synchronous serial interface

  I2C                                Inter-integrated circuit

  Timer                            Periodic interrupts, input capture, and output compare

  PWM                            Pulse width modulation

  ADC                              Analog to digital converter, measure analog signals

  Analog Comparator      Compare two analog signals

  QEI                              Quadrature encoder interface

  USB                              Universal serial bus

  Ethernet                        High-speed network

  CAN                             Controller area network





Detailed explanation of the block diagram will be published in the following posts, thank you.






























tags: embedded for beginners, embedded tutorials, micro controller tutorials, micro controller basics, micro controller tutorials, micro controller basics

Wednesday, November 6, 2013

PIC Serial Communication Tutorial (UART)

First, a quick history of RS232. What is RS232? It's just a name for a standard that has propagated from generation to generation of computers. The first computers had serial ports that used RS232, and even current computers have serial ports (or at least USB ports that act like RS232 ports). Back in the day, serial information needed to be passed from devices like printers, joysticks, scanners, etc to the computer. The simplest way to do this was to pass a series of 1s and 0s to the computer. Both the computer and the device agreed on a speed of information - 'bits per second'. A computer would pass image data to a printer at 9600 bits per second and the printer would listen for this stream of 1s and 0s expecting a new bit every 1/9600 = 104us (104 micro-seconds, 0.000104 seconds). As long as the computer output bits at the pre-determined speed, the printer could listen.
Zoom forward to today. Electronics have changed a bit. Before they were relatively high power, high voltage devices. The standard that is 'RS232' dictates that a bit ranges from -12V to +12V. Modern electronics do not operate at such high positive and negative voltages. In fact, our PIC  runs 0V to 5V. So how do we get our 5V micro to talk the RS232 +/-12V voltages? This problem has been solved by the IC manufacturers of the world. They have made an IC that is generically known as the MAX232 (very close to RS232, no?).
The MAX232 is an IC originally designed by a company called Maxim IC that converts the +/-12V signals of RS232 down to the 0/5V signals that our PIC  can understand. It also boosts the voltage of our PIC  to the needed +/-12V of the RS232 protocol so that a computer can understand our PIC  and vice versa. To get our PIC  IC sending serial characters to a computer, we have to send these serial signals through a MAX232 circuit so that the computer receives +/-12V RS232 signals. Don't worry if you're working with a chip labeled 'ICL232' or 'ST232' - these are just generics of the MAX232. Everyone says 'MAX232'. The ICs all function the same and nearly all have the same pinout.


                                                                 Discussion Group

Circuit
 
 
 

FM Radio jammer


FM Radio jammer


Description.
Circuit shown here can be used to jam FM radios in its vicinity. The circuit is nothing but a classic single transistor oscillator operating in the VHF region. Working principle of the circuit is very simple and straight forward. Powerful VHF oscillations from the circuit will interfere with the FM signals to nullify it. Jammer circuits like this are illegal in many countries and you must assemble this circuit on your own responsibility. This circuit is intended only for fun and i request you not to misuse it.
Circuit diagram.
FM radio jammer
Notes.
  • For L1 make 6 turns of 16AWG enamelled copper wire on a 9mm plastic former.
  • The circuit can be powered using a 9V PP3 battery.
  • For extended range, use an antenna.
  • A 30cm long wire connected anywhere on the coil will do for the antenna.
  • For better performance, assemble the circuit on a good PCB.




Reference : www.circuitstoday.com, www.wikipedia.com, www.microcontrollerprojects00.blogspot.in