Sign In

Trouble In Interfacing Dht22 And Digital Heart Beat Sensor

Mohit mohitsharmaece15@gmail.com India

Hardware: Atmega16 With 8mhz Software: C Project Using Atmel Studio 6

Patient monitoring system with gsm

Images

Replies

R Avinash Gupta
2017-05-03 05:06:55
what trouble?
R MOHIT SHARMA
2017-05-03 10:06:47
thank you , sir for being here to figure me out from this problem. my issue is that my heart beat sensor is a digital sensor nd i m using timer1 for capturing pulses/ signals of the sensor and it is connected on portb pin T1 and now im counting pulses for 1 minute and after one minute no of pulses will be printed on lcd that is connected on portc in 4bit mode , nd further adding i have also a dht22 humidity sensor that i m gonna to use but could not make possible , while on porta there is lm35 connected on adc0 for temperature .
major problem is that heart beat sensor is not working fine ......so with that humidity seensor snd gsm...
i need your help your and waiting for positive reply.
thank you so much
Mohit Sharma
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
//#include "lcd_file.h"

 #define lcdport PORTC
 #define rs PC0
 #define rw PC1
 #define en PC2
 
 void int0_init();
 void lcdinit(void);
 void lcdcmd(char);
 void lcddata(char);
 void lcdstring(char *);
 void serial_init(void);
 void cmden(void);
 void daten(void);
 
 void serial_init(void);
 void serial_tx();
 void status_report_msg(char *str1,char *str2); //Status report to doctor side
 void reg_new_number();             //reg new patient number
 void send_msg(char *str1,char *str2);         //alert to patient relatives

 int *p1,*p2;
 int coun1,coun2, j,humid=0,h_beat=0,b_temp=0,mob_num,temp;
 int humid_arr[4], h_beat_arr[5],b_temp_arr[3],count_arr[3];
 unsigned char num[10];
 unsigned char ch[70],a[12];
 unsigned int i=0;
 unsigned int dur;
 unsigned int pulse;


 void send_temp();
 void send_data(char);
 void txstring(char * );


unsigned int pulse;
unsigned int dur;
unsigned int k,n,i;

ISR(TIMER0_OVF_vect)
{
	i++;
}

void main()
{
	sei();
	DDRC=0XFF;
	lcdinit();
	
	lcdcmd(0X01);
	lcdcmd(0X80);
	lcdstring("PATIENT MONITOR");
	lcdcmd(0XC0);
	lcdstring("----SYSTEM----");
	_delay_ms(15000);
    lcdcmd(0x01);
	lcdcmd(0X80);
    lcdstring("INTIALIZING GSM    ");
    lcdcmd(0XC0);
    lcdstring(" Wait........    ");
	_delay_ms(5000);
    _delay_ms(5000);
	   // char mob=receive_msg();
	
	//lcdstring(mob);
	
	lcdcmd(0x01);
	lcdcmd(0x80);
	lcdstring(" System Ready  ");
	_delay_ms(10000);
	
	lcdcmd(0X01);
	lcdcmd(0x80);
	lcdstring("PLACE UR FINGER");
	_delay_ms(8000);
	_delay_ms(8000);
	lcdcmd(0xc0);
	lcdstring("FETCHING DATA...");
	while(1)
	   {
    back:DDRD|=(1<<6);
	    int b_temp = adc_0();
		PORTD|=(1<<6);		
		TIMSK=0X04;
		TCCR1B=0X07;
		for (int k=0;k<=60;k++)
			        _delay_ms(1000);
        
		PORTD&=~(1<<6);
        _delay_ms(8000);		   
		TCCR1B=0x00;
		TIMSK=0x00;
		dur=TCNT1;
		pulse=dur+i*65536;
		TCNT1=0x0000;
		i=0;
		
		_delay_ms(5000);

lcdcmd(0x01);
lcdcmd(0x80);
lcdstring("BEAT:");
lcdcmd(0X85);
    pulse=(pulse*6000/100);
	//pulse=(pulse/10);
	//pulse=(pulse*60)/100;
	sprintf(h_beat_arr,"%d",pulse);
	//if(pulse>10 && pulse<130)
	    lcdstring(h_beat_arr);
		//else 
		 // pulse= 0;
    p1=h_beat_arr;
lcdcmd(0X88);
lcdstring("bpm.           ");
lcdcmd(0xC0);
lcdstring("TEMP:");
   // b_temp=(b_temp/4);
	lcdcmd(0xc5);
	sprintf(b_temp_arr,"%d",b_temp);
	lcdstring(b_temp_arr);
	p2=b_temp_arr;
lcdcmd(0xc8);
lcdstring("deg.           ");
_delay_ms(5000);
_delay_ms(5000);
_delay_ms(5000);

 if(pulse>10 && pulse<50)
    {
	 //lcdcmd(0x01);
	 //lcdcmd(0x80);
	 //lcdstring("  ALERT !!!");
	 //lcdcmd(0XC0);
	 coun1++;
	 //lcdstring("LOW HEART RATE");
	  _delay_ms(1000);
	 if(coun1==3)
	 {send_msg(p1,p2);coun1=0;} 
		      goto back;
   }

if(pulse>100)
     { 
	  //lcdcmd(0x01);
	  //lcdcmd(0X80);
	  //lcdstring("    ALERT !!!");
	  lcdcmd(0XC0);
	  coun2++;
	  //lcdstring("HIGH HEART RATE");
	   _delay_ms(1000);
	  
	  if(coun2==3)
	       {send_msg(p1,p2);coun2=0;}
	  goto back;
	 }

if(b_temp>40)
    { 
      //lcdcmd(0x01);
      //lcdcmd(0x80);
      //lcdstring("Warning Body");
      //lcdcmd(0xc0);
      //lcdstring("Temp is High");
	    _delay_ms(2000);
	  send_msg(p1,p2);
	  goto back;	 
     }
  }//while
}//main



int adc_0()
	 {
		 ADCSRA=0b10000111;//0x87
		 ADMUX=0b11100000;//0xe0
		 ADCSRA|=(1<<ADSC);//START ADC
		 while( (ADCSRA&(1<<ADIF))==0){}
		 char left=ADCH;
		 return left;
	 }
/*
void adc_btemp()
{
	int arr2,n;
  lcdcmd(0xc0);
  lcdstring("TEMP:");
  lcdstring(arr2);
  while(n>30)
	    {
		 lcdcmd(0x01);
		 lcdcmd(0x80);
		 lcdstring("Warning Body");
		 lcdcmd(0xc0);
		 lcdstring("Temp is High");
	     status_report_msg(pulse,b_temp);
	    }
}
*/

void send_msg(char *str1,char *str2)
{
	send("ATr");
	_delay_ms(1000);
	send_data(0x22);
	
	lcdcmd(0x01);
	lcdstring("Sending Report");
	send("ATEr");
	_delay_ms(1000);
	send_data(0x22);
	
	send("AT+CMGF=1r");
	_delay_ms(1000);
	send_data(0x22);
	lcdcmd(0Xc0);
	lcdstring("  ALERT !!!  ");
	send("AT+CMGS=");
	send_data(0x22);
	
	txstring("7834869425");
	send_data(0x22);
	send_data('r');
	_delay_ms(500);
	txstring("PATEINT CURRENT STATUS:");
	txstring("BEAT: ");
	txstring(str1);
	txstring("   &&   ");
	txstring("TEMP: ");
	txstring(str2);
	txstring("   ");
	send_data('r');
	send_data(0x0d);
	send_data(26);
	_delay_ms(100);
	return 0;
}

 void serial_init()
 {
	 UCSRB=0x18;
	 UCSRC=UCSRC|(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
	 UBRRL= 0x33;
 }

 void serial_rx()
  {
	 while((UCSRA & (1<<RXC))==0);
	 ch[i]=UDR;
	 i++;
	 if(ch[i-1]=='#')
	 {
		 temp=1;
	 }
   }
 
 void send(char item)
   {
	 UDR=item;
	 while(!(UCSRA & (1<<UDRE)));
	 UCSRA|=1<<UDRE;
   }

 void serial_tx(char *str)
 {
	 while(*str)
	 {
		 send(*str);
		 str++;
	 }
 }

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

 
 int  receive_msg()
 {
	 int j=0,k=0,i=1;
	 serial_tx("ATE0");
	 send(0x0d);
	 _delay_ms(1000);
	 serial_tx("AT+CMGF=1");
	 send(0x0d);
	 _delay_ms(1000);
	 lcdcmd(1);
	 lcdstring(" FETCHING DATA");
	 serial_tx("AT+CNMI=2,2,0,0,0");
	 send(0x0d);
	 _delay_ms(1000);
	 send(0x0d);
	 _delay_ms(1000);
	 send(26);
	 lcdcmd(0xc0);
	 _delay_ms(9000);
	 lcdstring("WAITING FOR MSG");
	 while(i==1)
	 {
		 serial_rx();
		 if(temp==1)
		 {
			 while(k<i)
			 {
				 if(ch[k]=='*')
				 {
					 k++;
					 while(ch[k]!='#')
					 {
						 a[j]=ch[k];
						 j++;
						 k++;
					 }
				 }
				 k++;
			 }
			 lcdcmd(0x01);
			 lcdstring("Message Received");
			 _delay_ms(5000);
			 lcdcmd(1);
			 lcdcmd(0x80);
			 lcdstring(" Patient Mob: ");
			 lcdcmd(0xc2);
			 lcdstring(a);
			 j=0;k=0;temp=0;
			 _delay_ms(5000);
			 if (a[11]==0)
			 {
				 lcdcmd(0x01);lcdstring("  Thank you  ");
				 lcdcmd(0xc0);lcdstring(" for Registration ");
				 i=0;
				 _delay_ms(5000);
				 return a;
			 }
			 else
			 {
				 lcdcmd(0x01);
				 lcdstring("-Invalid Number-");
				 lcdcmd(0xc0);
				 lcdstring(" MSG valid no");
			 }
			 
			 if(i==0)
			 {return a;
			 break;}
		 }
	 }
 }
 
 void txstring(char *str)
 {
	 while(*str)
	 {
		 send_data(*str);
		 str++;
	 }
 }


 
////*********************   LCD MODULE    **************************************************///

void lcdinit()
{
	lcdcmd(0x02);
	lcdcmd(0x28);
	lcdcmd(0x0c);
	lcdcmd(0x06);
	serial_init();
}


void lcdstring(char *str)
{
	while(*str)
	{
		lcddata(*str);
		_delay_ms(50);
		str++;
	}
}
void lcdcmd(char x)
{
	PORTC=x & 0xf0;
	lcdcmdwrite();
	PORTC=(x<<4) & 0xf0;
	lcdcmdwrite();
}
void lcdcmdwrite()
{
	PORTC=PORTC&~(1<<0);
	PORTC=PORTC&~(1<<1);
	PORTC=PORTC|(1<<2);
	_delay_ms(10);
	PORTC=PORTC&~(1<<2);
	_delay_ms(50);
}
void lcddata(char x)
{
	PORTC=x & 0xf0;
	lcddatawrite();
	PORTC=(x<<4) & 0xf0;
	lcddatawrite();
}
void lcddatawrite()
{
	PORTC=PORTC|(1<<0);
	PORTC=PORTC&~(1<<1);
	PORTC=PORTC|(1<<2);
	_delay_ms(10);
	PORTC=PORTC&~(1<<2);
	_delay_ms(50);
}

void defualt()
{
	_delay_ms(5000);
	lcdcmd(1);
	lcdstring("System Ready");
}

Post a reply to Mohit

Think you can help Mohit ? Then post your thoughts that might help Mohit . You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.