Thursday, February 28, 2013

PIR sensor


General Description
The PIR (Passive Infra-Red) Sensor is a pyroelectric device that detects motion by measuring changes in
the infrared levels emitted by surrounding objects. This motion can be detected by checking for a high
signal on a single I/O pin.

Calibration
The PIR Sensor requires a ‘warm-up’ time in order to function properly. This is due to the settling time
involved in ‘learning’ its environment. This could be anywhere from 10-60 seconds. During this time
there should be as little motion as possible in the sensors field of view.

This is the explanation of program written in pir_test.ino
PIN connection
Vcc(PIR)--3.3V(Arduino)
GND(PIR)--GND(Arduino)
OUT(PIR)--pin7(arduino)
by:moin
creaed :@date 28-02-2013 @time 6:22


Since PIR, sends 'HIGH' signal for 3sec(vary with devices), just after sending a LOW signal for 2sec(vary with devices),
to check motion, this phenomenon of PIR is interpreted as positive motion lots of time by the compiler.
And hence cause wrong results many times. to over come this problem ,we need to specify a time condition,
so that if and only if that condition is satisfied, our compiler should consider that signal as a positive motion

to this we first need to calculate time at which PIR is sending 'LOW’ signal,
to do this I have written a if loop as shown below ,
this program calculates the time at which PIR is LOW, and prints the value to serial com .
                                   


                                    if(digitalRead(pir)==LOW){
                                      offtime=millis();//stores time at which pir pin turned low
                                      digitalWrite(led,LOW);//pir status is 
                                      Serial.print("\n offtime");
                                      Serial.println(offtime);
                                      delay(100);
                                    }


to this we first need to calculate time at which PIR is sending 'HIGH’ signal,
to do this I have written a if loop as shown below ,
this program calculates the time at which PIR is 'HIGH’, and prints the value to serial com .

                                    else if(digitalRead(pir)==HIGH){
                                      ontime=millis()-offtime;//store's time at which pir was high**
                                     digitalWrite(led,HIGH);//pir status on led
                                      Serial.print("\n ontime:");
                                      Serial.println(ontime);
                                      delay(200);
                                        }
imp:: ontime=millis()-offtime;
      here int above statement ontime is calculated by [millis()-offtime] formula,
            because millis(),gives the total time taken by compiler since the program is started.
            so if you can see in the first if loop , we are using [offtime=millis();]millis();direct to store the time at which
            PIR signaled LOW, so by applying simple math’s we can understand that the above formula can give us ontime.


Now after calculating time for which PIR is HIGH, we need check if PIR is high for minimum 5sec to confirm motion,

                                     if(ontime>condition){
                                      Serial.print("\n motion sensed");
                                      delay(1000);
                                    }
                                   
                                    if(ontime<condition){
                                      Serial.print("\n motion not sensed");
                                      delay(1000);
                                     }
Condition is initialized to 5000;
                                    long condition=5000;
this program is working as expected. and here is the program copy and paste it to arduino platform
//@dat 28-feb-2013
//by moin
*************//working sketch for pir*************************************************
#define pir 7
#define led 12
//int pir_state =LOW;
long offtime=0;//make sure it is initialized to zero**
unsigned long ontime;
long condition=5000;//should saty high to confirmmotion**
void setup(){
  pinMode(pir,INPUT);//make pir pin as input to micro controller
  pinMode(led,OUTPUT);//make led to show pir status
  Serial.begin(9600);
  //time requierd by PIR to callibrate
  Serial.print("calibrating sensor\n ");
    for(int i = 0; i < 30; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE\n");
    delay(50);
}
void loop(){
  //check if pir pin is low and store the time at which it is low

  if(digitalRead(pir)==LOW){
      offtime=millis();//stores time at which pir pin turned low
      digitalWrite(led,LOW);//pir status is  
     // Serial.print("\n offtime");
      //Serial.println(offtime);
      delay(100);
    }
    
    //check if pir pin is high and store time 
    else if(digitalRead(pir)==HIGH){
    ontime=millis()-offtime;//store's time at which pir was high**
    digitalWrite(led,HIGH);//pir status on led
    //Serial.print("\n ontime:");
   // Serial.println(ontime);
    delay(200);
  }
  //check if led was high for 5 sec**
  if(ontime>condition){
    Serial.print("\n motion sensed");
    digitalWrite(led,HIGH);
    delay(1000);
  }
   if(ontime<condition){
    Serial.print("\n motion not sensed");
    delay(1000);
  }
}
*********************************************************************************  
    


Thank you for Reading.

Sunday, February 10, 2013

configuring cc2500 to transmitt and recieve data to atmegaxx

 CC2500 Serial Transreceiver Wireless Module is designed to meet the requirement for the low cost, low power wireless device to transmit and receive serial data. The module operates on 2.4 GHz frequency band. The module can also be used as Wireless Sensor Network (WSN) node.

Hey folks this is about how to configure a cc2500 RF .to recieve and transmitt data to and from a atmega micro.
1.Download this smart rf softwere to get start with it.
http://focus.ti.com/docs/toolsw/folders/print/smartrftm-studio.html


2.Install and run the program .
it looks something like this

3.Now click on 2.4 ghz.you will find a list of components select cc2500 from it.


4.Now check on the right most part of the tool you will see a list of register of cc2500,
and here is the the thing we need to configure these registers to configure  our cc2500 to act as a transreciever.
so lets just beging with conguration now.
NOTE: To enter a value for perticular register just click on the value given infront of that register
here the list of the register and their corresponding value in the table given below
IMPORTANT :Setting the register bit PKTCTRL0.PKT_FORMAT=1 in the CC2500 radios enables
serial synchronous mode.
for my cc2500 i hve used GDO2 as clock and GDO0 as output.refrence value is given in the table below
 

//To check what particular register is doing ,simply double click on the register about which you want to know//
5. save your work by clicking on file-save-cnfig  we need this file in future so keep it safe.

6
  To know weather we are sending or recieving data.we got status resisters ,here is the list of status available in cc2500
 Status byte summary

NOTE:
Manchester encoding disabled, the frequency of the clock on the clock pin is equal to the programmed bit-rate (MDMCFG4.DRATE_E and MDMCFG3.DRATE_M register fields) in the radio.
For example, if the programmed data rate is 10 kbps, the frequency of the clock coming out of the clock pin will be 10 kHz.
Enabling Manchester encoding (available for 2-FSK, GFSK, ASK/OOK modulations) makes
the transmit/receive data rate half the programmed data rate.i.e it transmitts data for positive clock only and remains shut for the other.

here is the program for cc2500 and atmega


spi control register SPCR