Go Down

Topic: HC-SR501 with LDR attached to it. (Read 421 times) previous topic - next topic

arishy

I attached LDR to the pins as shown in the attachment.
This LDR is now inside the PIR.

My question is How to access the LDR values.
I am also attaching the schematic.

And here is the code I picked to modify:

Code: [Select]
#define LAMP  8  // choose the pin for the RELAY
#define PIR 13   // choose the input pin (for PIR sensor)                 
void setup()
{   
Serial.begin(9600);
  pinMode(LAMP, OUTPUT); // declare lamp as output
  pinMode(PIR,INPUT); // declare sensor as input                                                                                                                           
void loop()
{
 
 
  int value_ldr = analogRead(A4); // read LDR value
  int value_pir = digitalRead(PIR); // read input value
  Serial.println(value_ldr);
  Serial.println(value_pir);

 if((300>value_ldr) && ( value_pir==HIGH) ){
       digitalWrite(LAMP,1);  // Turn ON the light
       delay(6000);
       
 
}
else {
 
       digitalWrite(LAMP,0); // Turn OFF the light
       
}
 }


The code is using A4; and I have no way to connect to pin A4 since the LDR is inside the PIR as I mentioned earlier.

If someone used this sensor, he/she will be able to understand my confusion.

arishy

Here  what I found so far:

1. Very informative youtube
https://www.youtube.com/watch?v=2dxhbXHYEG0
2. I soldered the LDR and took a wire between R3 and the LDR ( see schematic ).
3. used the above sketch as is,just adding println to display ldr value and taking a wire to A4.

I am getting very low LDR value and the module is NOT responsive as it should be..

Any Ideas ???.

wvmarle

It doesn't sound like you're using the module the way you should.

Just get another LDR, and wire it up the proper way for your Arduino to read, and let the module take care of its own LDR.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

arishy

You are right....The way the module works internally is to measure the voltage across the added LDR.Then the mcu takes care of enable/disable based on that voltage measure.

And I think your solution will make me in full control of the LDR readings.

Thank you for your input

Wawa

If you connect the LDR like you did, then the PIR chip will ofcourse disable it's output when it's light outside.
So you can't control anything with the Arduino anymore unless ist's dark outside.
Leo..

arishy

Yes. The added feature ( installing LDR inside the module) is doing exactly that.
What triggered this post was: How dark and how light the mcu will perform the disabling of the PIR function.
Also can I hack it to specific range of Darkness.

If anyone of you care to join me in this little hack, I can give you my thoughts on it.

The question is;  is it worth it ?? For me it is the challenge.....there is no material benefits out of it.

wvmarle

Remove the LDR from the PIR sensor.
Use the Arduino to read darkness levels (using LDR or other light sensor).
When dark enough have it switch on the sensor: high side PNP transistor or logic level P-MOSFET in the Vcc line to the sensor (LOW signal will switch ON the sensor, HIGH signal switches it off).

Or if you mean have the Arduino respond to the PIR signal:
Remove the LDR from the PIR sensor.
Use the Arduino to read darkness levels (using LDR or other light sensor).
When dark enough start acting on the signal coming from the sensor, otherwise simply ignore it.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

arishy

I will go with your first approach. Can you please look at the script that I got from Internet (see above)
I need to latch the relay when I get the signal from PIR ( yes after removing the LDR and installing it externally)

Is it possible to help in modifying the script to work with your suggested PNP solution.

The way I am visualizing your approach is; The signal from PIR will go to the base of the PNP with say 1 K ohm.
The collector will control the Relay, And the relay will LATCH the lamp ON.
If I want to switch the lamp OFF I will use the physical switch .

Of course life in NOT that easy; because of this dumm switch status. ( is it ON...Is it OFF ???? )

wvmarle

#8
May 22, 2018, 11:30 am Last Edit: May 22, 2018, 11:31 am by wvmarle
So you want to have the PIR work in the dark only, and switch on a latching relay, that stays on until you press a button (momentary switch).

So the only thing the Arduino has to do, is detect dark/light and switch on the PIR sensor accordingly, right? Sounds a very overengineered solution to just adding the LDR to the PIR sensor directly. If you want better control for the darkness level at which it switches - which is based on the resistance of the LDR, low resistance is light, high resistance is dark - it may work to add a 100k pot.

Then all that's left is the latching relay, that's also a routine circuit. Easiest is if you have a double relay, where one set of poles switches the light, the other set latches the relay itself.

Like this:

Note: the NPN transistor is probably built into your relay module already, together with the base resistor.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

arishy

Thank you for taking the time to help me out with this project.

By "overengineering" you mean there is no need for arduino. Just a combination of PIR, LDR and relay.
( I misguided you when I said Latched Relay ) I do not have a lathed relay I have normal 5v relay module.

I learned a lot from you comments and schematics:

1. The physical switch must be momentary switch to toggle the status of the lamp. 
2. Using pot will make it easy to adjust the darkness level, which was a major request from my side.
3. I wonder then if arduino is not used I should rely on my effort to do it and NOT bothering you ( Arduino community) with a problem that is pure electronics.

If my comments make sense to you, then please advice I am at a loss here


wvmarle

A latched relay is just a way of having a relay keeping itself on. Nothing special, really. I drawn it using a double relay; you can also use a second relay to switch the lamp, which in turn is kept on by the latching one. A momentary push button can break this circuit and switch off the light after the PIR signal has gone low.

A PIR will normally keep the line high for a certain amount of time (a few seconds to about 10 minutes), then turn it low again. You can not interrupt this, you can however adjust it through a pot present on the unit.

Make sure your button out of view of the PIR sensor or just the motion of pushing it will trigger the sensor again.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

arishy

This is great....Really....

Now...what I have so far is adjustable Dark range and the Lamp is on ONLY in the dark that I specified though the pot as you suggested.
 
And yes the lamp goes off after few second. This is great so far.

Now latching the relay and the momentary switch. I like the idea of second relay.But I have no idea how to connect it to latch the lamp on after these few seconds!!!

Also how the momentary switch does the flipping of on/off of the lamp. HOW ?? your explanation will be greatly appreciated.

I will make sure that the PIR is hidden to avoid the retriggering and messing things up.

wvmarle

Latching relay works as I have shown above - the moment it's activated the NO contacts close, keeping the relay activated. The momentary button breaks that circuit, releasing the relay. Just use the output of that one to not only switch itself on, but also another relay. That's quite straightforward.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

arishy

I will follow the wiring that you posted above. The only difference using TWO relays instead of the

(DPDT) RELAY  you used, is that I have to trigger BOTH relays with PIR signal ( using NPN Transistor) and short circuiting pins following your schematic, will provide the latching. ( is that true ????)

 I assume that I need only ONE momentary switch to do the unlatching which will provide the lamp on/off function.

I will do it as I explained here and hope for the best.

P.S. May be..Just may be ...people prefer using microprocessor to do what I am trying to do. Just a thought !!!

wvmarle

Well, not stopping you to use a MCU for this project. It's just that not every project that can be done with an MCU should be done with an MCU.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up