Monday, 26 June 2017

Introduction to Matlab

Introduction to Matlab:


MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include:




RFID RC522 Send Data to Raspberry Pi

RFID RC522 Send Data to Raspberry Pi:



import MFRC522
import signal
import requests
import time
continue_reading = True
MIFAREReader = MFRC522.MFRC522()

cardA = [46,165,34,124,112]
cardB = [201,428,256,12,435]
cardC = [57,45,453,453]

def end_read(signal, frame):
  global continue_reading
  continue_reading = False
  print "Ctrl+C captured, ending read."
  MIFAREReader.GPIO_CLEEN()

signal.signal(signal.SIGINT, end_read)

while continue_reading:
  (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
  if status == MIFAREReader.MI_OK:
    print "Card detected"
  (status,backData) = MIFAREReader.MFRC522_Anticoll()
  if status == MIFAREReader.MI_OK:
    print "Card read UID: "+str(backData[0])+","+str(backData[1])+","+str(backData[2])+","+str(backData[3])+","+str(backData[4])
    time.sleep(3)
    if  backData == cardA:
      response = requests.get('http://192.168.1.134/rfid_read.php?allow=1&id='+str(backData[0])+","+str(backData[1])+","+str(backData[2])+","+str(backData[3])+","+str(backData[4]$
      print "is Card A"
    elif backData == cardB:
      response = requests.get('http://192.168.1.134/rfid_read.php?allow=1&id='+str(backData[0])+","+str(backData[1])+","+str(backData[2])+","+str(backData[3])+","+str(backData[4]$
      print "is Card B"
    elif backData == cardC:
      print "is Card C"
    else:
      print "not valid Card"


Circuit Diagram:





DHT22 sensor data send to thingspeak cloud using Raspberry Pi

DHT22 sensor data send to thingspeak cloud using Raspberry Pi:


import sys
import RPi.GPIO as GPIO
from time import sleep
import Adafruit_DHT
import urllib2
myAPI = "Your key Generated on thingspeak"
def getSensorData():
   RH, T = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 2)
   return (str(RH), str(T))
def main():
   print 'starting...'
   baseURL = 'https://api.thingspeak.com/update?api_key=%s' % myAPI
   while True:
       try:
           RH, T = getSensorData()
           f = urllib2.urlopen(baseURL +
                               "&field1=%s&field2=%s" % (RH, T))
           print f.read()
           f.close()
           sleep(5)
       except:
           print 'exiting.'
           break
# call main
if __name__ == '__main__':
   main()


Circuit Diagram:



Motion Detection using Arduino

Motion Detection using Arduino:



int ledPin = 13;                //  for the LED
int inputPin = 2;               // input pin
int pirState = LOW;          
int val = 0;                  

void setup() {
  pinMode(ledPin, OUTPUT);    
  pinMode(inputPin, INPUT);  

  Serial.begin(9600);
}

void loop(){
  val = digitalRead(inputPin);
  if (val == HIGH) {          
    digitalWrite(ledPin, HIGH);
    if (pirState == LOW) {
   
      Serial.println("Motion detected");
     
      pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW);
    if (pirState == HIGH){
   
      Serial.println("Motion ended");
   
      pirState = LOW;
    }
  }
}



Circuit Diagram:



Sound Sensor data plot in graph using Arduino and Raspberry Pi

Sound Sensor data plot in graph using Arduino and Raspberry Pi :


Arduino Code:


const int analogIn = A0;
int analogVal = 0;

void setup() {
  Serial.begin(19200);
}

void loop() {

  analogVal = analogRead(analogIn);
  Serial.println(analogVal);
  delay(1000);
}

Python Script:

import serial
import matplotlib.pyplot as plt
from drawnow import *

values = []

plt.ion()
cnt=0

serialArduino = serial.Serial('/dev/ttyACM0', 19200)// this is com port

def plotValues():
    plt.title('Serial data from Arduino')
    plt.grid(True)
    plt.ylabel('Values')
    plt.plot(values, 'rx-', label='values')
    plt.legend(loc='upper right')

#pre-load dummy data
for i in range(0,26):
    values.append(0)
 
while True:
    while (serialArduino.inWaiting()==0):
        pass
    valueRead = serialArduino.readline()

    #check if valid value can be casted
    try:
        valueInInt = int(valueRead)
        print(valueInInt)
        if valueInInt <= 1024:
            if valueInInt >= 0:
                values.append(valueInInt)
                values.pop(0)
                drawnow(plotValues)
            else:
                print "Invalid data"
        else:
            print "Invalid! too large value"
    except ValueError:
        print "Invalid! cannot used"

Circuit Diagram:




Interfacing of Sound Sensor with Arduino:

Interfacing of Sound Sensor with Arduino: 


const int analogIn = A0;
int analogVal = 0;

void setup() {
  Serial.begin(19200);
}

void loop() {

  analogVal = analogRead(analogIn);
  Serial.println(analogVal);
  delay(1000);
}


Circuit Diagram:




Obstacle detector using Ultrasonic sensor and Arduino:

Obstacle detector using Ultrasonic sensor and Arduino: 


int Echo1 = A4; //LEFT_SENSOR ECHO
int Trig1 = A5; //LEFT_SENSOR TRIG
int Echo2 = A2; //MID_SENSOR ECHO
int Trig2 = A3; //MID_SENSOR TRIG
int Echo3 = A0; //RIGHT_SENSOR ECHO
int Trig3 = A1; //RIGHT_SENSOR TRIG

int in1 = 8;
int in2 = 9;
int in3 = 6;
int in4 = 7;
int ENA = 5;
int ENB = 11;
int ABS = 200;
int Left_Distance = 0,Right_Distance = 0,Middle_Distance = 0 ;
void _mForward()
{

digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
analogWrite(ENA,ABS);
 analogWrite(ENB,ABS);
Serial.println("ROBOT_MOVING_FORWARD");
}
void _mBack()
{

digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
digitalWrite(in3,HIGH);
digitalWrite(in4,LOW);
analogWrite(ENA,ABS);
 analogWrite(ENB,ABS);
Serial.println("ROBOT_MOVING_BACKWARD");
}
void _mleft()
{

digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
digitalWrite(in3,LOW);
digitalWrite(in4,LOW);
analogWrite(ENA,ABS);
 analogWrite(ENB,ABS);
Serial.println("ROBOT_MOVING_LEFT");
}
void _mright()
{

digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
analogWrite(ENA,ABS);
 analogWrite(ENB,ABS);
Serial.println("ROBOT_MOVING_RIGHT");
}
void _mStop()
{
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
digitalWrite(in3,LOW);
digitalWrite(in4,LOW);
 digitalWrite(ENA,LOW);
  digitalWrite(ENB,LOW);
Serial.println("ROBOT_STOP");
}

int Left_Distance_test()
{
digitalWrite(Trig1, LOW);
delayMicroseconds(2);
digitalWrite(Trig1, HIGH);
delayMicroseconds(20);
digitalWrite(Trig1, LOW);
float Fdistance = pulseIn(Echo1, HIGH);
delay(10);

Fdistance= Fdistance/ 29 / 2;
return (int)Fdistance;
}
int Middle_Distance_test()
{
digitalWrite(Trig2, LOW);
delayMicroseconds(2);
digitalWrite(Trig2, HIGH);
delayMicroseconds(20);
digitalWrite(Trig2, LOW);
float Fdistance = pulseIn(Echo2, HIGH);
delay(10);
Fdistance= Fdistance/ 29 / 2;
return (int)Fdistance;
}
int Right_Distance_test()
{
digitalWrite(Trig3, LOW);
delayMicroseconds(2);
digitalWrite(Trig3, HIGH);
delayMicroseconds(20);
digitalWrite(Trig3, LOW);
float Fdistance = pulseIn(Echo3, HIGH);
delay(10);
Fdistance= Fdistance/ 29 / 2;
return (int)Fdistance;
}
void setup()
{
Serial.begin(9600);
pinMode(Echo1, INPUT);
pinMode(Trig1, OUTPUT);
pinMode(Echo2, INPUT);
pinMode(Trig2, OUTPUT);
pinMode(Echo3, INPUT);
pinMode(Trig3, OUTPUT);
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(in3,OUTPUT);
pinMode(in4,OUTPUT);
 pinMode(ENA,OUTPUT);
  pinMode(ENB,OUTPUT);

_mStop();
}
void loop()
{
Left_Distance = Left_Distance_test();
delay(10);
Middle_Distance = Middle_Distance_test();
delay(10);
Right_Distance = Right_Distance_test();
delay(10);
Serial.println("Left_Distance\tMiddle_Distance\tRight_Distance\tStatus\n");
Serial.print(Left_Distance);
Serial.print("cm\t\t");
Serial.print(Middle_Distance);
Serial.print("cm\t\t");
Serial.print(Right_Distance);
Serial.print("cm\t\t");
 if(Middle_Distance<=50)
    {  

               
      if(Right_Distance>Left_Distance)
      {
        if((Right_Distance<=30)&&(Left_Distance<=30))
       {_mStop();
      delay(200);
        _mBack();
        delay(1000);
     
       }
      else{
     
   
        _mright();
        delay(500);}
     
      }
       else if(Right_Distance<Left_Distance)
       {
        if((Right_Distance<=30)&&(Left_Distance<=30))
     
       {_mStop();
      delay(200);
        _mBack();
        delay(1000);
       }
       else{
 
        _mleft();
        delay(500);
       }
    }
    }
    else if(Right_Distance<=15)
    {
      _mleft();
      delay(500);
    }
 
    else if(Left_Distance<=15)
    {
      _mright();
      delay(500);
    }
    else{
        _mForward();
        }
     
}


Circuit Diagram:



Temperature and Humidity data send to google spreadsheet using Arduino with Ethernet shield:

Temperature and Humidity data send to google spreadsheet using Arduino with Ethernet shield:


#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDA, 0xDA, 0xEA, 0xFA, 0xAE, 0xEA }; //Setting MAC Address
char server[] = "api.pushingbox.com"; //pushingbox API server
IPAddress ip(192,168,0,56); //Arduino with Ethernet Shield IP address.
EthernetClient client; //define 'client' as object
String data; //GET query with data
float tempt;
boolean value= false;

void setup() {

  Serial.begin(9600);

  if (Ethernet.begin(mac) == 0) {
  Serial.println("Failed to configure");
  Ethernet.begin(mac, ip);
  }

  delay(1000);
}

void loop(){
  int baca_ADC = analogRead(A0); //read analog input on pin A7
   tempt = baca_ADC ; // ADC to celcius conversion
   getData(); //packing GET query with data
   Serial.println("connecting");
   if (client.connect(server, 80)) {
     sendData();
     value  = true; //connected = true
   }
   else{
     Serial.println("connection failed");
   }

  while(value){
    if (client.available()) {
    char c = client.read(); //save http header to c
    Serial.print(c); //print http header to serial monitor
    }
    if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
          Serial.print("Temperature Sent :");
          Serial.println(tempt); //print sent value to serial monitor
    client.stop();
          value = false;
          data = ""; //data reset
    }
  }
  delay(5000); // interval
}

void getData(){
  data+="";
  data+="GET /pushingbox?devid=<ENTER YOUR DEVICE ID>&tempData=";
  data+=tempt;
  data+=" HTTP/1.1";
}
void sendData(){
  Serial.println("connected");
  client.println(data);
  client.println("Host: api.pushingbox.com");
  client.println("Connection: close");
  client.println();
}


Circuit Diagram:




Interfacing of Temperature Sensor (LM35) with Arduino:


Interfacing of Temperature Sensor (LM35) with Arduino:



float temp;      
int sensor = 0;     // LM35 middle pin is analog pin 0

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  temp = analogRead(sensor);        //analog read pin read the temp value then store in temp
  temp = temp * 0.48828125;         //converting volts to degrees celsius ----- 0.48828125 = [(5V*1000)/1024]10

  Serial.print("The temperature is :");
  Serial.print(temp);
  Serial.println("deg. Celsius");
  delay(1000);
}


Circuit Diagram:



Sunday, 25 June 2017

GPS Send Data to LCD using AVR

GPS Send Data to LCD using AVR:


#define F_CPU 8000000UL
#include <util/delay.h>
#define rs 0
#define rw 1
#define en 2

#include <avr/io.h>
#include <avr/interrupt.h>
#include<string.h>

//#include"serial_header.h"
//function declaration
void recgps(void);
void delay(int);
void cmden();
void lcdcmd(char);
void lcdinit(void);
void daten(void);
void lcddata(char);
void txdata(char);
unsigned char rxu0(void);
void serial_init();

static unsigned char lat[10];
static unsigned char lon[11];
unsigned char maps_link[50]="www.maps.google.com/";


void cmnd()
{
PORTB&=(~(1<<rs));
PORTB&=(~(1<<rw));
PORTB|=(1<<en);
_delay_ms(50);
PORTB&=(~(1<<en));
}
void lcdcmd(char ch)
{
PORTB=ch & 0xf0;
cmnd();
PORTB=(ch<<4) & 0xf0;
cmnd();
}
void lcdinit()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
}
void data()
{
PORTB|=(1<<rs);
PORTB&=(~(1<<rw));
PORTB|=(1<<en);
_delay_ms(50);
PORTB&=(~(1<<en));
}
void lcddata(char ch)
{
PORTB=ch & 0xf0;
data();
PORTB=(ch<<4) & 0xf0;
data();
}
void lcdstring(char *str)
{
while(*str)
{
lcddata(*str);
str++;
}
}


void serial_init()
{

UCSRB=0x18;
UCSRC=0x86;
UBRRL=0X33;
}
char uart_read()
{
while(!(UCSRA & (1<<RXC)));
return UDR;
}

void txstring(char *str)
{
while(*str)
{
txdata(*str);
str++;
_delay_ms(20);
}
}


void txdata(char ch)
{
UDR=ch;
while(!(UCSRA & (1<<UDRE)));
_delay_ms(10);
}

void recgps()
{
unsigned char p;
int gps=0;
int i;

while(gps==0)
{
p=uart_read();
while(p!='$')
{
p=uart_read();
}
p=uart_read();
if(p=='G')
{
}
else
continue;
p=uart_read();
if(p=='P')
{
}
else
continue;

p=uart_read();
if(p=='G')
{
}
else
continue;

p=uart_read();
if(p=='G')
{
}
else
continue;

p=uart_read();
if(p=='A')
{
while(p!=',')
{
p=uart_read();
}
p=uart_read();
while(p!=',')
{
p=uart_read();
}
for(i=0;i<9;i++)
{
lat[i]=uart_read();
}
p=uart_read();
while(p!=',')
{
p=uart_read();
}
p=uart_read();
while(p!=',')
{
p=uart_read();
}
for(i=0;i<10;i++)
{
lon[i]=uart_read();
}
lat[9]='\0';
lon[10]='\0';
gps=0;
}
else
continue;
}
}

int main()
{
int i;
DDRB=0XFF;
lcdinit();
serial_init();

lcdcmd(0x80);
lcdstring("Send on LCD ");


  lcdcmd(0x01);
  lcdstring(" Ready... ");
  while(1)
{

lcdcmd(1);
recgps();
lcdstring("Lat:");
lcdstring(lat);
lcdcmd(0xc0);
lcdstring("Lon:");
lcdstring(lon);
_delay_ms(3000);
}

}

Circuit Diagram:




GPS Send Location to Lcd using Arduino

GPS Send Location to Lcd using Arduino:


// Creating a Simple GPS Receiver
#include <TinyGPS.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );

TinyGPS gps;
void getgps(TinyGPS &gps);
void setup()
{
Serial.begin(4800);
lcd.begin(16, 2);
}
void getgps(TinyGPS &gps)
// The getgps function will display the required data on the LCD
{
float latitude, longitude;
//decode and display position data
gps.f_get_position(&latitude, &longitude);
lcd.setCursor(0,0);
lcd.print("Lat:");
lcd.print(latitude,5);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Long:");
lcd.print(longitude,5);
lcd.print(" ");
delay(3000); // wait for 3 seconds
lcd.clear();
}
void loop()
{
byte a;
if ( Serial.available() > 0 ) // if there is data coming into the serial line
{
a = Serial.read(); // get the byte of data
if(gps.encode(a)) // if there is valid GPS data...
{
getgps(gps); // grab the data and display it on the LCD
}
}
}

Circuit Diagram:



Rain Detected then GSM Module Send Email using Arduino

Rain Detected then GSM Module Send Email using Arduino:


#include<SoftwareSerial.h>
SoftwareSerial mySerial(9,10); //RX,TX
int Analog_Out=A0;            //ANALOG INPUT
int Analog_In=0;
void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  pinMode(Analog_Out,INPUT);    //DECLARE A0 AS INPUT
  delay(50);
}

void loop() {
  Analog_In=analogRead(Analog_Out); // SENSOR VALUE
  if(Analog_In<500)                 //when raindrop sensor detect analog value then value
                                          // will be reduce
  {
 
    Serial.println("It's Rainging Outside");
    SendEmail();                    //Send Mail to Gsm module GSM MODULE
    while(analogRead(Analog_Out)<800);//HOLDING STATE UNTIL RAIN STOP
  }
  else if(Analog_In>500 && Analog_In<800)   // this is for rain Warning
  {
    Serial.println("About To Rain");
  }
  else if(Analog_In>800)     //when not raining
  {
    Serial.println("It's Sunny Outside");
  }
delay(1000);
}


void SendEmail()        //SENDING EMAIL
{
  mySerial.println("AT");
  delay(100);
  mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r");  //CONFIGUREING BEARER PROFILE
  delay(10000);

  mySerial.println("AT+SAPBR=1,1");       //OPEN A GPRS CONTEXT
  delay(15000);
  mySerial.println("AT+SAPBR=2,1");      //QUERY THE GPRS CONTEXT
  delay(3000);
  mySerial.println("AT+EMAILCID=1");     //SET PARAMETERS OF EMAIL
  delay(4000);
  mySerial.println("AT+EMAILTO=30");    //REFRESHING IN EVERY 30 SEC IF NO WORKIS HAPPING  mySerial.println("AT+SMTPSRV=\"OUTGOING SERVER ID \",PORT_NO \r"); //SET SMTP SERVER ADDRESS AND PORT
  delay(5000);
    mySerial.println("AT+SMTPSRV=\"OUTGOING SERVER ID \",PORT_NO \r"); //SET SMTP SERVER ADDRESS AND PORT
    delay(3000);
  mySerial.println("AT+SMTPAUTH=1,\"USER_ID\",\"PASSWORD\"\r");   //SET SMTP ID & PASSWORD
  delay(8000);
  mySerial.println("AT+SMTPFROM=\"SENDER_EMAIL_ID\",\"SENDER_NAME\"\r");    //SET SENDER Email ID
  delay(6000);
  mySerial.println("AT+SMTPRCPT=0,0,\"TO_EMAIL_ADDRESS\",\"TO_NAME\"\r");         //SET RECIPIENT (TO:)
  delay(5000);
  mySerial.println("AT+SMTPRCPT=1,0,\"CC_TO_EMAIL_ADDRESS\",\"CC NAME\"\r");      //SET RECIPIENT(Cc:)
  delay(5000);
 mySerial.println("AT+SMTPRCPT=2,0,\"BCc_TO_MAIL_ADDRESS\",\"BCc NAME\"\r");    //SET RECIPIENT (BCc)
  delay(5000);
  mySerial.println("AT+SMTPSUB=\"FROM YOUR RAIN DROP DETACTOR\"\r");          //ENTER YOUR EMAIL SUBJECCT
  delay(5000);
  mySerial.println("AT+SMTPBODY");                                            // FOR EMAIL BODY
  delay(5000);
  mySerial.println("IT'S RAINING OUTSIDE.\n \n *Regards,*\n*Your GSM Module*");   //YOUR EMAIL BODY
  delay(1000);
  mySerial.println((char)26);                                             //FOR CTRL+Z
  delay(5000);
  mySerial.println("AT+SMTPSEND");                                        //EMAIL SEND
  delay(100000);
 }

Circuit Diagram:




Rain Detected then GSM Module Send SMS using Arduino

Rain Detected then GSM Module Send SMS using Arduino:


#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10);  //(RX,TX)
int d=0;
void setup() {
  mySerial.begin(9600);  
  Serial.begin(9600);  
  pinMode(11,INPUT);            //FOR DIGITAL INPUT
  pinMode(A0,INPUT);            //FOR ANALOG INPUT
  delay(50);
}
void loop() {
 
int sensorReading = analogRead(A0); //value detected Raindrop Sensor


    if(sensorReading<500)             // when raindrop sensor detect analog value then value
                                          // will be reduce
    {          
        Serial.println("Its Raining Outside");
        SendMessage();                  //Send Sms to Gsm module
        while(analogRead(A0)<800);      //HOLDING STATE UNTIL RAIN STOP
      }
   
            else if((sensorReading>500)&&(sensorReading<800))   // this is for rain Warning
           {
              Serial.println("Rain Warnigitng");
           }

              else if(sensorReading>800)          //when not raining
              {
                  Serial.println("NotRaining");
               
              }

  delay(1000);
}



void SendMessage()                
{
  mySerial.println("AT+CMGF=1");    //SELECT SMS Text Mode
  delay(1000);
  mySerial.println("AT+CMGS=\"+91XXXXXXXXXX\"\r");   //GIVE YOUR MOBILE NUMBER

  delay(1000);
  mySerial.println("IT IS RAINING OUTSIDE )");
  delay(100);
  mySerial.println((char)26);
  delay(1000);
}

Circuit Diagram:



Interfacing of GSM with AVR

Interfacing of  GSM with AVR:


#include <avr/io.h>
#include <util/delay.h>
#include <string.h>
#define rs 0
#define rw 1
#define en 2
unsigned char data;
void lcd_init();
void serial_init();
void serial_send_char(unsigned char x);
void serial_send_string(unsigned char *x);
char serial_receive();
void lcd_cmd(unsigned char);
void lcd_string(unsigned char*);
//void receive_sms();
//void response();
/*void receive_sms()
{
serial_send_string("ATE0\r\n");
_delay_ms(5000);
response();
serial_send_string("AT\r\n");
_delay_ms(5000);
response();
serial_send_string("AT+CMGF=1\r\n");
_delay_ms(5000);
response();
serial_send_string("AT+CNMI=2,2,0,0,0\r\n");
_delay_ms(5000);
response();
}
void response()
{
int i = 0;
char data[10];
while(serial_receive()>0)
{
data[i] = serial_receive();
i++;
}
if(strcmp(data ,"OK")==0)
{
lcd_cmd(0x01);
lcd_string("OK");
}
else if(strcmp(data ,"ERROR")==0)
{
lcd_cmd(0x01);
lcd_string("Error");
}

}*/
void display_msg()
{
unsigned int i;
unsigned char msg[32],ch;

lcd_cmd(0xc0);
lcd_string("Reading MSG...");

serial_send_string("AT+CMGR=1\r\n");

//delay_sec(1);

for(i=0;ch!='*';i++)
{
ch=serial_receive();
}

for(i=0;ch!='$';i++)
{
ch=serial_receive();
msg[i]=ch;
// lcd_display(msg[i]);

}

lcd_cmd(0x01);
lcd_cmd(0x80);
for(i=0;((i<16)&&(msg[i]!='$'));i++)
lcd_char(msg[i]);

lcd_cmd(0x01);
lcd_cmd(0xc0);
for(i=16;((i<32)&&(msg[i]!='$'));i++)
lcd_char(msg[i]);


serial_send_string("AT+CMGD=1\r\n");
_delay_ms(100);
}



int main(void)
{
unsigned char msg_chk[9];
int i;
DDRB = 0xFF;

serial_init();
_delay_ms(100);
lcd_init();
_delay_ms(100);

lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_string("WELCOME TO GSM module");
_delay_ms(500);
serial_send_string("ATE0\r\n");
_delay_ms(500);
serial_send_string("AT\r\n");
_delay_ms(200);
serial_send_string("ATE0\r\n");
_delay_ms(200);
serial_send_string("AT&W\r\n");
_delay_ms(200);
serial_send_string("AT+CMGF=1\r\n");
_delay_ms(200);
serial_send_string("AT+CMGS=\"+919999999999\"\r\n");
_delay_ms(200);
serial_send_string("Ready\r\n");
_delay_ms(200);
serial_send_string(0x1A);
_delay_ms(200);

    /* for(i=0;i<strlen(arr);i++)
{
serial_send_char(arr[i]);
 _delay_ms(2);
}*/
lcd_gotoxy(0,0);
lcd_string("Message Received");
_delay_ms(1000);
lcd_cmd(0xc0);
while(1)
{
del_msg();

for(i=0;i<9;i++)
{
 msg_chk[i]=serial_receive();
}
if(strncmp(msg_chk+3,"+CMTI:",6)==0)
{
lcd_gotoxy(0,0);
lcd_string(" 1 Message Receive");
display_msg();
}

else if(strncmp(msg_chk+3,"+CNMI:",6)==0)
{
lcd_gotoxy(0,0);
lcd_string(" 1 Message Received");
display_msg();
}
}
/* while (1)
{
if(serial_receive()=='+')
{
if(serial_receive()=='C')
{
if(serial_receive()=='M')
{
if(serial_receive()=='T')
{
if(serial_receive()=='I')
{
while(serial_receive()!=',');
a =serial_receive();
_delay_ms(50);
serial_send_char(0x0D);
serial_send_char(0x0A);
serial_send_string("AT+CMGF=1");
serial_send_char(0x0D);
serial_send_char(0x0A);
serial_send_string("AT+CMGR=");
serial_send_char(a);
serial_send_char(0x0D);
serial_send_char(0x0A);
while(serial_receive()!=0x0A);
while(serial_receive()!=0x0A);
while(serial_receive()!=0x0A);
for(i=0;i<15;i++)
{
read[i]=serial_receive();
}
  lcd_string(read);
_delay_ms(5000);                            
}
}
}
}
}
}*/
// while(1)
// {
// data = serial_receive();
// _delay_ms(5);
// lcd_char(data);
// _delay_ms(5);
// }
return 0;
}
void lcd_cmd(unsigned char x)
{
PORTB = x & 0xF0;
PORTB &= ~(1<<rs);
PORTB &= ~(1<<rw);
PORTB |= (1<<en);
_delay_ms(50);
PORTB &= ~(1<<en);
_delay_ms(50);

PORTB = (x<<4)&0xF0;
PORTB &= ~(1<<rs);
PORTB &= ~(1<<rw);
PORTB |= (1<<en);
_delay_ms(5);
PORTB &= ~(1<<en);
_delay_ms(5);
}
void lcd_char(unsigned char x)
{
PORTB = x & 0xF0;
PORTB |= (1<<rs);
PORTB &= ~(1<<rw);
PORTB |= (1<<en);
_delay_ms(5);
PORTB &= ~(1<<en);
_delay_ms(5);

PORTB = (x<<4)&0xF0;
PORTB |= (1<<rs);
PORTB &= ~(1<<rw);
PORTB |= (1<<en);
_delay_ms(5);
PORTB &= ~(1<<en);
_delay_ms(5);

}
void lcd_string(unsigned char *ch)
{
while(*ch!='\0')
{
 lcd_char(*ch);
 _delay_ms(10);
 ch++;
}

}
void lcd_init()
{
lcd_cmd(0x02);//cursor at home
lcd_cmd(0x28);//lcd in 4 bit mode
lcd_cmd(0x0E);//display on
lcd_cmd(0x01);//clear the display
lcd_cmd(0x06);//display and shift cursor to the right
}
void serial_init()
{
UCSRB = (1<<TXEN)|(1<<RXEN);
UCSRC = (1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1);
UBRRL = 51;
_delay_ms(10);

}
void serial_send_char(unsigned char x)
{
while(!(UCSRA & (1<<UDRE)));
UDR = x;
_delay_ms(10);

}
void serial_send_string(unsigned char *x)
{
while(*x!='\0')
{
serial_send_char(*x);
x++;
}

}
char serial_receive()
{
while(!(UCSRA &(1<<RXC)));
_delay_ms(5);
return UDR;

}

void lcd_gotoxy(unsigned char row,unsigned char column) //move cursor to the specified position
{
if(row==0)
{
lcd_cmd(0x80+column);
}
else if(row==1)
{
lcd_cmd(0xC0+column);
}
}


Circuit Diagram:



Temperature and Humidity data send to Bluetooth using Smart phone and Arduino

Temperature and Humidity data send to Bluetooth using Smart phone and Arduino:


#include <dht.h>

dht DHT;


#define DHT22_PIN 4

void setup()
{
    Serial.begin(9600);
    Serial.println("DHT value ");
    Serial.print("LIBRARY VERSION: ");
    Serial.println(DHT_LIB_VERSION);
    Serial.println();
    Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}

void loop()
{
    // READ DATA
    Serial.print("DHT22, \t");
    int chk = DHT.read22(DHT22_PIN);
    switch (chk)
    {
        case DHTLIB_OK:
            Serial.print("OK,\t");
            break;
        case DHTLIB_ERROR_CHECKSUM:
            Serial.print("Checksum error,\t");
            break;
        case DHTLIB_ERROR_TIMEOUT:
            Serial.print("Time out error,\t");
            break;
        default:
            Serial.print("Unknown error,\t");
            break;
    }
    // DISPLAY DATA
    Serial.print(DHT.humidity, 1);
    Serial.print(",\t");
    Serial.println(DHT.temperature, 1);

    delay(5000);

}


Circuit Diagram:




Interfacing of Bluetooth with Arduino:

Interfacing of Bluetooth with Arduino:


#include <SoftwareSerial.h>//
int led=13;
long previousMillis = 0;      

long interval = 1000;        
int ledState = LOW;          
long Counter=0;
void setup() {

  Serial.begin(9600);
  Serial.println("Bluetooth Connected....");
  pinMode(led,OUTPUT);
}

void loop() {

  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {
 
    previousMillis = currentMillis;
     Counter+=1;

    Serial.println(Counter);

    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

   
    digitalWrite(ledpin, ledState);
  }
}

Circuit Diagram:




Interfacing of Fingerprint with Arduino

Interfacing of Fingerprint with Arduino:


#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

int getFingerprintIDez();

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
  while (!Serial);  // For Yun/Leo/Micro/Zero/...

  Serial.begin(9600);
  Serial.println("Adafruit finger detect test");

  // set the data rate for the sensor serial port
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  Serial.println("Waiting for valid finger...");
}

void loop()                     // run over and over again
{
  getFingerprintIDez();
  delay(50);            //don't ned to run this at full speed.
}

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  return -1;

  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  return finger.fingerID;
}

Circuit Diagram:



How to Enroll Finger in Fingerprint using Arduino:

How to Enroll Finger in Fingerprint using Arduino:



#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

uint8_t id;

uint8_t getFingerprintEnroll();

// Software serial for when you dont have a hardware serial port
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
// On Leonardo/Micro/Yun, use pins 8 & 9. On Mega, just grab a hardware serialport
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

// On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white
//Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial1);


void setup()
{
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(500);
 
  Serial.begin(9600);
  Serial.println("Adafruit Fingerprint sensor enrollment");

  // set the data rate for the sensor serial port
  finger.begin(57600);
 
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
}

uint8_t readnumber(void) {
  uint8_t num = 0;
  boolean validnum = false;
  while (1) {
    while (! Serial.available());
    char c = Serial.read();
    if (isdigit(c)) {
       num *= 10;
       num += c - '0';
       validnum = true;
    } else if (validnum) {
      return num;
    }
  }
}

void loop()                     // run over and over again
{
  Serial.println("Ready to enroll a fingerprint! Please Type in the ID # you want to save this finger as...");
  id = readnumber();
  Serial.print("Enrolling ID #");
  Serial.println(id);
 
  while (!  getFingerprintEnroll() );
}

uint8_t getFingerprintEnroll() {

  int p = -1;
  Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(1);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
 
  Serial.println("Remove finger");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  Serial.print("ID "); Serial.println(id);
  p = -1;
  Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(2);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
 
  // OK converted!
  Serial.print("Creating model for #");  Serial.println(id);
 
  p = finger.createModel();
  if (p == FINGERPRINT_OK) {
    Serial.println("Prints matched!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }  
 
  Serial.print("ID "); Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }  
}

Interfacing of Arduino with Touch Sensor and Appliance

Interfacing of Arduino with Touch Sensor and Appliance


#define TouchSensor 9 // Pin for touch sensor

int bulb = 3;

boolean currentState = LOW;
boolean lastState = LOW;
boolean bulbState = LOW;

void setup() {
  Serial.begin(9600);
  pinMode(bulb, OUTPUT);
  pinMode(TouchSensor, INPUT);
}

void loop() {
  currentState = digitalRead(TouchSensor);
    if (currentState == HIGH && lastState == LOW){
    Serial.println("pressed");
    delay(1);
 
    if (bulbState == HIGH)
      digitalWrite(bulb, LOW);
      bulbState = LOW;
    }
    else {
      digitalWrite(bulb, HIGH);
      bulbState = HIGH;
    }
  }
  lastState = currentState;
}

Circuit Diagram:



RFID interface with Ethernet:

This summary is not available. Please click here to view the post.