On and off automatically when motion detected in motion sensor

Thread Starter

sweet_kelvin_sweet

Joined Dec 23, 2010
5
I m creating a visual C++ application. This application will switch on the light automatically for 30min after the motion sensor has detected the motion. If the detection still continue after 30min. Then the light will still ON.
2. this application connects to the PIC circuit.
Hope to hear from u all soon~ thanks a lot
if(WriteFile(WriteHandleToUSBDevice, &OUTBuffer, 65, &BytesWritten, 0)) // Blocking function, unless an "overlapped" structure is used
{
// Now get the response packet from the firmware.
INBuffer[0] = 0;
if(ReadFile(ReadHandleToUSBDevice, &INBuffer, 65, &BytesRead, 0)) // Blocking function, unless an "overlapped" structure is used
{
// INBuffer[0] is the report ID, which we don't care about.
// INBuffer[1] is an echo back of the command (see microcontroller firmware).
// INBuffer[2] contains the I/O port pin value for the LDR sensor state (see microcontroller firmware).
if((INBuffer[1] == 0x87) && (INBuffer[2] == 0x01))
{
Dark2 = FALSE;
}
if((INBuffer[1] == 0x87) && (INBuffer[2] == 0x00))
{
Dark2 = TRUE;
}
}
} This code is used to detect the motion sensor



if(WriteFile(WriteHandleToUSBDevice, &OUTBuffer, 65, &BytesWritten, 0)) // Blocking function, unless an "overlapped" structure is used
{
// Now get the response packet from the firmware.
INBuffer[0] = 0;
if(ReadFile(ReadHandleToUSBDevice, &INBuffer, 65, &BytesRead, 0)) // Blocking function, unless an "overlapped" structure is used
{
// INBuffer[0] is the report ID, which we don't care about.
// INBuffer[1] is an echo back of the command (see microcontroller firmware).
// INBuffer[2] contains the I/O port pin value for the pushbutton (see microcontroller firmware).
if((INBuffer[1] == 0x88) && (INBuffer[2] == 0x01))
{
LEDstate2 = TRUE;
}
if((INBuffer[1] == 0x88) && (INBuffer[2] == 0x00))
{
LEDstate2 = FALSE;
}
}
} This is manual on and off code
 

nerdegutta

Joined Dec 15, 2009
2,684
It would be very nice if you edited your message body, and inserted the code-tag around your code. It's the # icon in the editor menu-bar.

That way, you would increase the readability, and maybe get more people interested.

I did not really catch the question here...
 

Thread Starter

sweet_kelvin_sweet

Joined Dec 23, 2010
5
Hi,

Thanks for reply. Just to be simple, I want to create an application to turn ON and OFF the light when there is someone detected(motion)

1. This device is connected to PC via USB using PIC18F4550
2. This device is connected to the digital motion sensor
3. This device will turn ON the light for 30 min if motion detected.
 

spinnaker

Joined Oct 29, 2009
7,830
Why do you need the PC? There should be no need. You can do all of that on the PIC.

The only reason for the PC might be to configure some settings or maybe to capture and display some data.

But the PIC should be ab;e to do all of the main work.
 

Thread Starter

sweet_kelvin_sweet

Joined Dec 23, 2010
5
Thanks for reply spinnaker,

Hi, the reason of connecting PC is to monitor the status.

1. When motion detected, the light will be switched ON auto.
2. The status of the application in the PC will show the motion detected and light is ON.
Is there any way to solve this, thanks and hope to hear from u soon
 

thatoneguy

Joined Feb 19, 2009
6,359
An LED on the PIC could display the status, blinking means motion is detected, red meaning standing by.

You could also use an 18F2550, still gives USB and not so many ports to worry about. Though adding a PC in the loop is overkill.

For motion detection, a PIR Sensor would work much better than the photocell solution in the other thread.

A $2 16F628 PIC could directly control an optocoupler to a TRIAC to turn on the lights, time the 30 minutes, and change the LED status accordingly with about 99% of it's capacity to spare, but you wouldn't have a USB port.
 

thatoneguy

Joined Feb 19, 2009
6,359
Hi tatoneguy,

Thanks for reply man, I bought the PIR recently. It is not the one u mentioning.
http://www.cytron.com.my/viewProduct.php?pid=LC4rNQcHEQ03OhIVFhslM63Q!!!!!3iPuUCcKf274Sc3jRQ=
This link shows the PIR that I bought.

1. I wanna connect it to 18f4550 and change the firmware
There's already a PIC on that board, apparently a PIC16 series, but the source code is available for modification. I'd guess it is written in Hi-Tech C. The PIC in photo is a 28 pin SDIP (skinny dip). The 18F4550 is a 40 pin 300mil (wide) DIP, it wouldn't fit in the socket. The 18F2550 or 18F2445 would fit that same socket, though you'd still have to port the firmware.

What do you want to add to the board? It seems to be a rather complete system already. If you want X-10 automation, PICs can do that as well without a PC.

Download the source code & tools on that link and make sure you can compile it before making any changes to it. To download changes, you'll need a PICKit 2 or PiCKit 3 ICSP Programmer. There are DIY Programmers around, but people using them spend most of their time trying to get the programmer to work causing them to give up and walk away after 3 months of failures due to design of DIY programmers. A $35 PICKit 2 solves a TON of headaches.
 

Thread Starter

sweet_kelvin_sweet

Joined Dec 23, 2010
5
Thanks for observation and reply thatoneguy,
I wanna connect this via 18f4550 IC because it can connects to the PC via USB. This will be a monitoring system.
1. The system can be monitored by the PC via a visual C++ program.
 
Top