Solved: pir sensor source code input

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use CodeVisionAVR V3.32a Evaluation.

 

I am trying to identify human body detection by using a human body infrared sensor to plug LEDs into PORTB.4 and PORTB.1.

The human body infrared sensor is connected to PF4 (pin 58).

 

 

pir The sensor name is NS-IRHSM.

 

I looked for the pir sensor source code.

=> http://exploreembedded.com/wiki/PIR_motion_Sensor_interface_with_Atmega128

 

<before>

  #include <avr/io.h>
  #include "lcd.h"
   
  #define PIR_sensor PA0
   
  unsigned int PIR_Status = 0;
  int main()
  {
   
  DDRA = (0 << PIR_sensor); // Configure PORTA as INput to connect switches
  /*Connect RS->PB0, RW->PB1, EN->PB2 and data bus to PORTC.4 to PORTC.7*/
  while(1)
  {
  while(((PINA) & (1<<PIR_sensor)) == 1)
  {
  LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PC_4,PC_5,PC_6,PC_7);
  LCD_Init(2,16);
  LCD_DisplayString("Motion Detected!");
   
  }
  LCD_Clear();
   
  while(((PINA) & (1<<PIR_sensor)) == 0)
  {
  LCD_SetUp(PB_0,PB_1,PB_2,P_NC,P_NC,P_NC,P_NC,PC_4,PC_5,PC_6,PC_7);
  LCD_Init(2,16);
  LCD_DisplayString("Motion Ended!");
  }
  LCD_Clear();
   
   
   
  }
   
  return (0);
  }

 

We modified the source code according to the code vision.

<after codevision>

#include <io.h>
#include <mega128.h>
#include <delay.h>            
#define PIR_sensor PF4
 
 
unsigned int PIR_Status = 0;
void main()
{
     PORTB = 0x00;
     DDRB = 0xFF;
 
     DDRF = (0 << PIR_sensor);           // Configure PORTA as INput to connect switches
     /*Connect RS->PB0, RW->PB1, EN->PB2 and data bus to PORTC.4 to PORTC.7*/
     while(1)
     {
         while(((PINF) & (1<<PIR_sensor)) == 1)
         {
            PORTB.4=0;
            PORTB.1=1;
             
         }
          
          
         while(((PINF) & (1<<PIR_sensor)) == 0) 
         {
             PORTB.4=0;
             PORTB.1=1;
         }     
     
   
     
  }
  

 }

 

An error occurred in the source code.!!!!!!

How do I fix the source code?

 

and

 

How do I write the source code when I try to express the behavior as a Buzzer with the pir sensor?

Please tell us TT

 

I modified it with PINF4 and I got a new error.

 

Sources to fix

: while(PINF & (1<<PIR_sensor))

Last Edited: Fri. May 18, 2018 - 03:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's not PF4, it is PINF4

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you for the reply.
I modified it with PINF4 and I got a new error.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ChoHyeonsu wrote:

thank you for the reply.
I modified it with PINF4 and I got a new error.

 

That's a warning not an error. It just says that you have declared a global variable but that you have not made use of it in your code.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What should I do?
I entered the source code and it does not work properly.

Photo after action.

Last Edited: Tue. May 15, 2018 - 02:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ChoHyeonsu wrote:
I entered the source code and it does not work properly.

Go on - I bet there's very few people who can just enter a load of source code and expect it to work straight off!

 

You need to debug it!

 

Take it step-by-step - don't just write the whole lot in one go and expect it all to "just work" ...

 

See: https://www.avrfreaks.net/commen...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ChoHyeonsu wrote:

I entered the source code and it does not work properly.

 

So what are you expecting to happen?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
So what are you expecting to happen?

 

@ChoHyeonsu: See the linked "How To Debug" - the key questions you need to ask yourself are there:

  1. What should be happening?
  2. What actually is happening?
  3. How can I explain the difference?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ChoHyeonsu wrote:
PF4 (pin 58).
58 is PF3, not PF4.

 

Idea for later:

Those PIR module's have some opamps in them with very high amplification because the sensor generates a uV level signal.

After amplification there usually is a very simple flipflop and timer circuit (with the potentiometers).

If you make a tap of the last OPamp amplification stage and feed that into an analog pin of your AVR you can do a lot of usefull things with it.

You can analyse the shape of the input signal, and reject high frequency spikes (often caused by radio frequency signals / EMI pickup from the input circuit).

The more expensive (burglar alarm) PIR sensors sometimes claim they can distinguish between pet's and humans by analysing the signal.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you for the reply.
 

PORTF(PF7~PF0) => PIN 54-61

 

PF0 PF1 PF2 PF3 PF4 PF5 PF6 PF7

 54  55   56   57  58  59   60   61

 

Is not this?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your schematic shows AVCC not wired - it is required to be connected!

Mega128 needs the M103C fuse cleared, otherwise the code may not work.

C4,5 need to be 22pF not nF! the crystal has no hope of working with 22nF caps.

 

Does the 78L05 get hot? I'd expect it would with the lcd backlight. You may require a 7805 and a heatsink.

Last Edited: Wed. May 16, 2018 - 05:08 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you for the reply.

The schematic incorrectly entered the capacitor value.
The source code was new and connected to AVCC.

 

#include <io.h>
#include <mega128.h>
#include <delay.h>            
#define PIR_sensor PINF4
 
void main()
{
     PORTB = 0x00;
     DDRB = 0xFF;
 
     DDRF = (0 << PIR_sensor);         
     
     while(1)
     {
         while(((PINF) & (1<<PIR_sensor)) == 1)
         {
            PORTB.4=0;
            PORTB.1=1;
            PORTB.2=1;
            PORTB.3=1;
             
         }
          
          
         while(((PINF) & (1<<PIR_sensor)) == 0) 
         {
             PORTB.4=1;
             PORTB.1=0;
             PORTB.2=1;
             PORTB.3=1;
         }     
     
         
                 
     }

 

The light of the LED, which means 'not detected here', comes on. Like 'PORTB.1=0'

 

It seems to be connected to AVCC.
Why does not human body detection work?

Last Edited: Wed. May 16, 2018 - 11:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This will never be true:

while(((PINF) & (1<<PIR_sensor)) == 1)

 

should be:

while(PINF & (1<<PIR_sensor))

 

 

Last Edited: Wed. May 16, 2018 - 11:52 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you for the reply.
It works fine.