LDR (Light Dependent Resistor
Moderator: Benj
-
- Posts: 192
- Joined: Mon Mar 04, 2013 8:07 pm
- Has thanked: 29 times
- Been thanked: 15 times
- Contact:
LDR (Light Dependent Resistor
LDR (Light Dependent Resistor
I hope that someone could help with the following situation:
I have power LEDs and I want these to dim by an LDR.
Connections:
LDR > PIC16F690 > NPN MOSFET > Power LEDs
In this situation the LEDs must be about 30% to 40% less brighten when it is totally dark. In daylight they must be 100% brighten.
I have this LDR:
http://www.farnell.com/datasheets/409710.pdf
I’m searching this forum for some examples about how to calculate this, because I don’t have any idea how to do this. I hope that someone have an working example for me.
Thanks,
Frank
I hope that someone could help with the following situation:
I have power LEDs and I want these to dim by an LDR.
Connections:
LDR > PIC16F690 > NPN MOSFET > Power LEDs
In this situation the LEDs must be about 30% to 40% less brighten when it is totally dark. In daylight they must be 100% brighten.
I have this LDR:
http://www.farnell.com/datasheets/409710.pdf
I’m searching this forum for some examples about how to calculate this, because I don’t have any idea how to do this. I hope that someone have an working example for me.
Thanks,
Frank
Last edited by Frank607 on Fri Jul 07, 2017 10:14 am, edited 1 time in total.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: LDR (Light Dependent Resistor
Hi Frank,
Use the LDR as one side of a potential divider (Z1) and a fixed resistor as the other side (Z2).
https://upload.wikimedia.org/wikipedia/ ... er.svg.png
Vin would be your system VCC, say 5V or 3V3.
VOut would be the signal to an Analog enabled microcontroller input pin.
GND would be the system VSS or Ground.
Switching the resistor and the LDR (Z1 and Z2) in the potential divider circuit will have the effect of reversing the voltage, e.g. dark = low voltage and dark = high voltage.
The resistance of the fixed resistor should probably be in the region of 1K to 10K to give you a nice varying signal.
To drive the LED brightness use a PWM output to drive the MOSFET and vary the PWM duty based on your analog LDR reading.
https://www.matrixtsl.com/wikiv7/index. ... :_General)
Use the LDR as one side of a potential divider (Z1) and a fixed resistor as the other side (Z2).
https://upload.wikimedia.org/wikipedia/ ... er.svg.png
Vin would be your system VCC, say 5V or 3V3.
VOut would be the signal to an Analog enabled microcontroller input pin.
GND would be the system VSS or Ground.
Switching the resistor and the LDR (Z1 and Z2) in the potential divider circuit will have the effect of reversing the voltage, e.g. dark = low voltage and dark = high voltage.
The resistance of the fixed resistor should probably be in the region of 1K to 10K to give you a nice varying signal.
To drive the LED brightness use a PWM output to drive the MOSFET and vary the PWM duty based on your analog LDR reading.
https://www.matrixtsl.com/wikiv7/index. ... :_General)
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 315
- Joined: Sun Jun 23, 2013 1:29 pm
- Has thanked: 28 times
- Been thanked: 61 times
- Contact:
Re: LDR (Light Dependent Resistor
Hi Frank,
http://www.petervis.com/electronics%20g ... R/LDR.html
Remember Google is your friend!!!
Matt
http://www.petervis.com/electronics%20g ... R/LDR.html
Remember Google is your friend!!!
Matt
-
- Posts: 192
- Joined: Mon Mar 04, 2013 8:07 pm
- Has thanked: 29 times
- Been thanked: 15 times
- Contact:
Feeling sad
By this topic made by me:
XXX
I’m happy with all the answers I get on this question but I need some example to understand this LDR with PWM and some explanation. This PWM stuff is all new to me.
Ok, I have just bought FlowCode 7 with some modules. I also saw under a hidden button the module “Read my mind” I also bought this module and I hope it will work as expected.
I only cant register this (my) version of FlowCode, not by my Matrix user name (administer mode) and also not on a manual way > 504 Gateway time out.
Cancel is closing the program. Yes I followed all the instructions in the email and step by step.
(I understand that my Forum user account can be different from the Matrix main website user account. I can login on the main Matrix website with my credentials.)
XXX
I’m happy with all the answers I get on this question but I need some example to understand this LDR with PWM and some explanation. This PWM stuff is all new to me.
Ok, I have just bought FlowCode 7 with some modules. I also saw under a hidden button the module “Read my mind” I also bought this module and I hope it will work as expected.
I only cant register this (my) version of FlowCode, not by my Matrix user name (administer mode) and also not on a manual way > 504 Gateway time out.
Cancel is closing the program. Yes I followed all the instructions in the email and step by step.
(I understand that my Forum user account can be different from the Matrix main website user account. I can login on the main Matrix website with my credentials.)
Last edited by Frank607 on Thu Jul 06, 2017 6:32 pm, edited 1 time in total.
-
- Posts: 315
- Joined: Sun Jun 23, 2013 1:29 pm
- Has thanked: 28 times
- Been thanked: 61 times
- Contact:
Re: Feeling sad
Hi Frank
Point 1) Is a continuation of your original question - you are effectively doubling posting (forum admin will shout at you and make you have detention after school)
Point 2) is a matter for Matrix and at the very least warrant a separate post.
I will try and help the best I can and reply in your original post
Perhaps ask admin to bump it from V5 to V7 as you now have upgraded
Matt
Point 1) Is a continuation of your original question - you are effectively doubling posting (forum admin will shout at you and make you have detention after school)
Point 2) is a matter for Matrix and at the very least warrant a separate post.
I will try and help the best I can and reply in your original post
Perhaps ask admin to bump it from V5 to V7 as you now have upgraded
Matt
-
- Posts: 444
- Joined: Tue Apr 15, 2014 4:19 pm
- Location: Kajaani, Finland
- Has thanked: 345 times
- Been thanked: 227 times
- Contact:
Re: LDR (Light Dependent Resistor
Hi!
I merged your posts as this is continuation to the old topic in context.
For the PWM, as you said its a new thing to you, you could take a look at the Sparkfun tutorials, theyre bit arduino specific, but still they usually explain things pretty clearly. To use pwm with Flowcode V7 (as you stated you had purchased it) you can use the V7 wiki to see some examples about PWM.
https://learn.sparkfun.com/tutorials/pu ... modulation
https://www.matrixtsl.com/wikiv7/index. ... :_General)
Examples are great learning point, and i understand the frustration, as with the v5 flowcode i was sometimes stuck at thinking to myself, how this thing works (there were no examples provided on those days).
I personally struggled with CAN bus boards for couple of weeks, then found someone else had asked about them in this forum, and used information from that topic to get around, the "AH-HAA, so this is how it works " was best feeling ever.
I merged your posts as this is continuation to the old topic in context.
For the PWM, as you said its a new thing to you, you could take a look at the Sparkfun tutorials, theyre bit arduino specific, but still they usually explain things pretty clearly. To use pwm with Flowcode V7 (as you stated you had purchased it) you can use the V7 wiki to see some examples about PWM.
https://learn.sparkfun.com/tutorials/pu ... modulation
https://www.matrixtsl.com/wikiv7/index. ... :_General)
Examples are great learning point, and i understand the frustration, as with the v5 flowcode i was sometimes stuck at thinking to myself, how this thing works (there were no examples provided on those days).
I personally struggled with CAN bus boards for couple of weeks, then found someone else had asked about them in this forum, and used information from that topic to get around, the "AH-HAA, so this is how it works " was best feeling ever.
Ill just keep the good work up!
-
- Posts: 192
- Joined: Mon Mar 04, 2013 8:07 pm
- Has thanked: 29 times
- Been thanked: 15 times
- Contact:
Re: LDR (Light Dependent Resistor
Hi Docara and EtsDriver,
I’m sorry for reposting a forum link.
Thanks for the attention and I have opened a “support ticket “
I’m sorry for reposting a forum link.
Thanks for the attention and I have opened a “support ticket “
-
- Posts: 315
- Joined: Sun Jun 23, 2013 1:29 pm
- Has thanked: 28 times
- Been thanked: 61 times
- Contact:
Re: LDR (Light Dependent Resistor
Thanks ETS
I have more fully answer Franks question on his original post
Matt
I have more fully answer Franks question on his original post
Matt
-
- Posts: 315
- Joined: Sun Jun 23, 2013 1:29 pm
- Has thanked: 28 times
- Been thanked: 61 times
- Contact:
Re: LDR (Light Dependent Resistor
Clearly my post has disappeared!!
ETSDriver do you nor agree it would have been a good idea to leave the original post intact and not merge it - especially as I said I was posting to the original V5 forum. It took more nearly an hour writing something in a manner for Frank to follow which was simple enough for both complete his project and learn by. YOU have erased it by deleting the V5 post whilst I was in the process of replying to. When I hit submit there was no location for my message to go.
I'm not impressed and quite P****d off about it.
My I suggest as you clearly have forum access rights you find my post and reinstate it
M
ETSDriver do you nor agree it would have been a good idea to leave the original post intact and not merge it - especially as I said I was posting to the original V5 forum. It took more nearly an hour writing something in a manner for Frank to follow which was simple enough for both complete his project and learn by. YOU have erased it by deleting the V5 post whilst I was in the process of replying to. When I hit submit there was no location for my message to go.
I'm not impressed and quite P****d off about it.
My I suggest as you clearly have forum access rights you find my post and reinstate it
M
-
- Posts: 444
- Joined: Tue Apr 15, 2014 4:19 pm
- Location: Kajaani, Finland
- Has thanked: 345 times
- Been thanked: 227 times
- Contact:
Re: LDR (Light Dependent Resistor
Hi!Docara wrote:Clearly my post has disappeared!!
ETSDriver do you nor agree it would have been a good idea to leave the original post intact and not merge it - especially as I said I was posting to the original V5 forum. It took more nearly an hour writing something in a manner for Frank to follow which was simple enough for both complete his project and learn by. YOU have erased it by deleting the V5 post whilst I was in the process of replying to. When I hit submit there was no location for my message to go.
I'm not impressed and quite P****d off about it.
My I suggest as you clearly have forum access rights you find my post and reinstate it
M
I sent you a pm apologizing for this inconvience. The thing is, im not a fortuneteller, and i cant see that someone is typing there a message.
I noticed your other message sent at 6.7.17 9:23pm:
but i sent earlier a message that notifies about the merge at 8:40pm:Docara wrote:Thanks ETS
I have more fully answer Franks question on his original post
Matt
when the merge had allready happened. I have not deleted the V5 post, it was just moved to V7 forums, and the forum software gives the topic a new id, and lets moderators choose whether to leave shadow topic in place. The shadow topic would not had prevented your post disappear, as it just is a redirect to the new topic id, as it seems the forum software failed to give you a nag that the topic you are answering doesn't exist anymore. Usually there is warning if topic has got new replies when you were writing, but not in this case.EtsDriver wrote:Hi!
I merged your posts as this is continuation to the old topic in context.
Im pretty much powerless to see if the message you sent is sitting alone somewhere in the database, but you have to realise that it might be next to impossible for some database ninja to find that. I cant guarantee your post to be restored, but i will do everything to try!
Ill just keep the good work up!
-
- Posts: 192
- Joined: Mon Mar 04, 2013 8:07 pm
- Has thanked: 29 times
- Been thanked: 15 times
- Contact:
Re: LDR (Light Dependent Resistor
The licensing problem what I had is fixed. I had added the key to my account and saw what license (modules) I had. So I think that this was all. But… I had click the button ADD KEY while I was thinking that this button was for adding a NEW key.
@Docara,
I was searching for this topic but I couldn’t find it anymore.
@Docara,
I was searching for this topic but I couldn’t find it anymore.
Last edited by Frank607 on Fri Jul 07, 2017 9:25 am, edited 1 time in total.
-
- Posts: 192
- Joined: Mon Mar 04, 2013 8:07 pm
- Has thanked: 29 times
- Been thanked: 15 times
- Contact:
Re: LDR (Light Dependent Resistor
You are right. I have find many base examples in this forum what I could use to build on further. Only in this case (and maybe more in the future) I couldn’t find a specific example for my question.EtsDriver wrote:Hi!
... Examples are great learning point, and i understand the frustration, as with the v5 flowcode i was sometimes stuck at thinking to myself, how this thing works (there were no examples provided on those days).
I personally struggled with CAN bus boards for couple of weeks, then found someone else had asked about them in this forum, and used information from that topic to get around, the "AH-HAA, so this is how it works " was best feeling ever.
Last edited by Frank607 on Fri Jul 07, 2017 9:57 am, edited 1 time in total.
-
- Posts: 315
- Joined: Sun Jun 23, 2013 1:29 pm
- Has thanked: 28 times
- Been thanked: 61 times
- Contact:
Re: LDR (Light Dependent Resistor
EtsDriver
Thank you for the apology - I appreciate you were only trying to help but for I don't think merge is the answer to issues like this. I feel you should have just moved the post and maintain the links.
At the bottom of the page we are able to see who is online, and depending on the browser it also shows up as a banner in the corner on a posting box and I did state I was replying to the original message additionally, you stated you hade merged the message how then was I able to click on it and start my response - very strange.
I will rewrite my answer but as the forum SW is SQL based I'm sure my post is lurking somewhere because it posted successfully. The normal standard post successful message appeared.
So anyway handbags at dawn at your place or mine LOL
Regards
Matt
Thank you for the apology - I appreciate you were only trying to help but for I don't think merge is the answer to issues like this. I feel you should have just moved the post and maintain the links.
At the bottom of the page we are able to see who is online, and depending on the browser it also shows up as a banner in the corner on a posting box and I did state I was replying to the original message additionally, you stated you hade merged the message how then was I able to click on it and start my response - very strange.
I will rewrite my answer but as the forum SW is SQL based I'm sure my post is lurking somewhere because it posted successfully. The normal standard post successful message appeared.
So anyway handbags at dawn at your place or mine LOL
Regards
Matt
Last edited by Docara on Fri Jul 07, 2017 2:45 pm, edited 1 time in total.
- DavidA
- Matrix Staff
- Posts: 1076
- Joined: Fri Apr 23, 2010 2:18 pm
- Location: Matrix Multimedia Ltd
- Has thanked: 58 times
- Been thanked: 258 times
- Contact:
Re: LDR (Light Dependent Resistor
Hi, I can search the database if i can get some indication as to what the post said, PM me and ill have a quick search.
-
- Posts: 315
- Joined: Sun Jun 23, 2013 1:29 pm
- Has thanked: 28 times
- Been thanked: 61 times
- Contact:
Re: LDR (Light Dependent Resistor
Hi Frank,
I've just quickly gone over your post and if I understand you correctly you wish to have a variable rate PWM output based on the light level via an LDR.
Whilst this is an easy task especially with Flowcode it is easy to get caught up in the details of your project and come unstuck. So I propose to help you by nudging you into a position to sort the problem out yourself.
First off don't worry about the electrical characteristics of the LDR, PWM frequency, mark to space ratios 40% brightness levels (this will come later) just think about the logical steps needed to achieve what you want using the tools available. So, mentally break down your project into easy to understand manageable blocks.
Input
Analysis/decision
Output
With your project the INPUT is to do with the LDR and feeding the processor with a correctly proportioned signal. The Analysis is what the processor does with the information once it 'inside' the processor and the OUTPUT is the PWM signal timed based on the decision the processor has made based on the INPUT. Now, remember FC is a very good simulation tool as well as a programming tool so use it.
Right, before I buy any component I would try and model (and start to program) what I was intending to build within FC to make sure my logic and design was sound, and I had enough pins on my chosen processor. So with this in mind choose start by choosing your preferred processor in FC -
An LDR is a variable resistor, a potentiometer - a device which is able to have it's resistance changed (albeit by light) and you know that to read these analogue devices in FC they must be connected to the Analogue to Digital Converter (ADC) pin, so choose any (generic) potentiometer and drag it to the 2D panel there are properties which you need to complete associated with this component to tell FC where it is connected. Secondly, you will need some way to indicate various values. So lets use LEDs which will correspond to 25%, 50%, 75% and 100%. (you could use a LCD display to see the numbers actual produced by the potentiometer) Set these up on, say, Port C bits 0 to 3 (bit0=25% - bit3=100%)
So we now have a basic setup that, in principle, will accept an input and be able to output something and have it show up on LEDs.
The beauty of simulating the circuit above in FC is that you can make sure the code is correct and working before you move over to the real world and have a project sitting on your bench laughing at you and giving you the finger, at least you can eliminate an area of frustration and head scratching (your code) and concentrate on the electrical connections to see why it doesn't work. The next step is to code something.
The procedure will be
Read (from ADC)
Store the value (from ADC)
Do something with the value
Repeat
First thing we need to do is setup a variable. It could be anything Say ADCvalue and it will be a byte (255) long. (I chose this variable type because of the link Benj posted here about PWM and 8bit processors)
Next, we need to setup a continuous loop so drag the While loop icon to your chart
Next, Inside this loop we need to read from the ADC (component macro) and store it in the variable we set up previously (ADCvalue)
The next section pertains to you setting up the PWM frequency in the future
Next, Drag four decision boxes over into your chart. The decision is based on the value in the ADCvalue variable. Set these four decisions boxes to 25%, 50%, 75% and 100% (100%=255, 75%=192, 50%=128, 25%=64)
Next, In the YES branch of output a 1 to the first LED (IF ADCvalue=64 then light the first LED on Port C bit 0
Next, In the YES branch of output a 1 to the first LED (IF ADCvalue=128 then light the first LED on Port C bit 1
Next, In the YES branch of output a 1 to the first LED (IF ADCvalue=192 then light the first LED on Port C bit 2
Next, In the YES branch of output a 1 to the first LED (IF ADCvalue=255 then light the first LED on Port C bit 3
Next, you will need to have a delay so you can actually see the LED being lit 0.25 Sec (250mS)
Next, Clear the ADCvariable (ADCvalue=0) or Output a 0 to Port C (try both)
If you run this and twiddle the knob on screen you will see each LED light up when the value reaches the threshold levels above. If we use less than or equal too (<=) instead of just = in the above decisions what would you expect to happen? (try it and see)
OK. By quickly knocking up the above (if I've done it right) you have proven that you can read a value from an analogue pin, analyse the value and an arbitrary pin can be controlled based on that value. The next step is to use the variable ADCvalue as the controlling value in the PWM Component macro. You probably will need to do away with the delay and clearing of the ADCvalue when dealing with the following PWM.
You stated in your original post that you wanted "In this situation the LEDs must be about 30% to 40% less brighten when it is totally dark. In daylight they must be 100% brighten." this equates to 70% 60% and 100% 70%=180, 60%=154, 100%=255. Therefore, remove one of the decision boxes above and change the values to 154, 180 & 255. Where you previously had an OUTPUT macro controlling the LED's via Port C insert the PWM Component Macro using the ADCvalue variable when prompted.
Remember the PWM module will run continuously at a given rate unless you change it, so you don't need to continuously output the value read from the potentiometer (LDR) unless it changes. This is where you need to think about your program logic and where interrupts come in.I think there is an interrupts on ANchange or similar but you have to code in C to get at it.
Let me know how you get on (and if I've missed something LOL) - you might need some help when it comes time to connecting up in the real world.
Regards
Matt
I've just quickly gone over your post and if I understand you correctly you wish to have a variable rate PWM output based on the light level via an LDR.
Whilst this is an easy task especially with Flowcode it is easy to get caught up in the details of your project and come unstuck. So I propose to help you by nudging you into a position to sort the problem out yourself.
First off don't worry about the electrical characteristics of the LDR, PWM frequency, mark to space ratios 40% brightness levels (this will come later) just think about the logical steps needed to achieve what you want using the tools available. So, mentally break down your project into easy to understand manageable blocks.
Input
Analysis/decision
Output
With your project the INPUT is to do with the LDR and feeding the processor with a correctly proportioned signal. The Analysis is what the processor does with the information once it 'inside' the processor and the OUTPUT is the PWM signal timed based on the decision the processor has made based on the INPUT. Now, remember FC is a very good simulation tool as well as a programming tool so use it.
Right, before I buy any component I would try and model (and start to program) what I was intending to build within FC to make sure my logic and design was sound, and I had enough pins on my chosen processor. So with this in mind choose start by choosing your preferred processor in FC -
An LDR is a variable resistor, a potentiometer - a device which is able to have it's resistance changed (albeit by light) and you know that to read these analogue devices in FC they must be connected to the Analogue to Digital Converter (ADC) pin, so choose any (generic) potentiometer and drag it to the 2D panel there are properties which you need to complete associated with this component to tell FC where it is connected. Secondly, you will need some way to indicate various values. So lets use LEDs which will correspond to 25%, 50%, 75% and 100%. (you could use a LCD display to see the numbers actual produced by the potentiometer) Set these up on, say, Port C bits 0 to 3 (bit0=25% - bit3=100%)
So we now have a basic setup that, in principle, will accept an input and be able to output something and have it show up on LEDs.
The beauty of simulating the circuit above in FC is that you can make sure the code is correct and working before you move over to the real world and have a project sitting on your bench laughing at you and giving you the finger, at least you can eliminate an area of frustration and head scratching (your code) and concentrate on the electrical connections to see why it doesn't work. The next step is to code something.
The procedure will be
Read (from ADC)
Store the value (from ADC)
Do something with the value
Repeat
First thing we need to do is setup a variable. It could be anything Say ADCvalue and it will be a byte (255) long. (I chose this variable type because of the link Benj posted here about PWM and 8bit processors)
Next, we need to setup a continuous loop so drag the While loop icon to your chart
Next, Inside this loop we need to read from the ADC (component macro) and store it in the variable we set up previously (ADCvalue)
The next section pertains to you setting up the PWM frequency in the future
Next, Drag four decision boxes over into your chart. The decision is based on the value in the ADCvalue variable. Set these four decisions boxes to 25%, 50%, 75% and 100% (100%=255, 75%=192, 50%=128, 25%=64)
Next, In the YES branch of output a 1 to the first LED (IF ADCvalue=64 then light the first LED on Port C bit 0
Next, In the YES branch of output a 1 to the first LED (IF ADCvalue=128 then light the first LED on Port C bit 1
Next, In the YES branch of output a 1 to the first LED (IF ADCvalue=192 then light the first LED on Port C bit 2
Next, In the YES branch of output a 1 to the first LED (IF ADCvalue=255 then light the first LED on Port C bit 3
Next, you will need to have a delay so you can actually see the LED being lit 0.25 Sec (250mS)
Next, Clear the ADCvariable (ADCvalue=0) or Output a 0 to Port C (try both)
If you run this and twiddle the knob on screen you will see each LED light up when the value reaches the threshold levels above. If we use less than or equal too (<=) instead of just = in the above decisions what would you expect to happen? (try it and see)
OK. By quickly knocking up the above (if I've done it right) you have proven that you can read a value from an analogue pin, analyse the value and an arbitrary pin can be controlled based on that value. The next step is to use the variable ADCvalue as the controlling value in the PWM Component macro. You probably will need to do away with the delay and clearing of the ADCvalue when dealing with the following PWM.
You stated in your original post that you wanted "In this situation the LEDs must be about 30% to 40% less brighten when it is totally dark. In daylight they must be 100% brighten." this equates to 70% 60% and 100% 70%=180, 60%=154, 100%=255. Therefore, remove one of the decision boxes above and change the values to 154, 180 & 255. Where you previously had an OUTPUT macro controlling the LED's via Port C insert the PWM Component Macro using the ADCvalue variable when prompted.
Remember the PWM module will run continuously at a given rate unless you change it, so you don't need to continuously output the value read from the potentiometer (LDR) unless it changes. This is where you need to think about your program logic and where interrupts come in.I think there is an interrupts on ANchange or similar but you have to code in C to get at it.
Let me know how you get on (and if I've missed something LOL) - you might need some help when it comes time to connecting up in the real world.
Regards
Matt
-
- Posts: 192
- Joined: Mon Mar 04, 2013 8:07 pm
- Has thanked: 29 times
- Been thanked: 15 times
- Contact:
Re: LDR (Light Dependent Resistor
Hi Matt,
Thanks for this great answer and the background information. I appreciate this at a high level (Dutch thinking to English writing, but I hope you understand it )
This evening I have to go to my social live in the city but somewhere in this weekend I will work on it.
Have a nice weekend and regards,
Frank
Thanks for this great answer and the background information. I appreciate this at a high level (Dutch thinking to English writing, but I hope you understand it )
This evening I have to go to my social live in the city but somewhere in this weekend I will work on it.
Have a nice weekend and regards,
Frank
-
- Posts: 315
- Joined: Sun Jun 23, 2013 1:29 pm
- Has thanked: 28 times
- Been thanked: 61 times
- Contact:
Re: LDR (Light Dependent Resistor
Hi Bud,
I remember when I had a social life in the city ha ha
I'm will be around here this weekend
Have fun
Matt
I remember when I had a social life in the city ha ha
I'm will be around here this weekend
Have fun
Matt
-
- Posts: 192
- Joined: Mon Mar 04, 2013 8:07 pm
- Has thanked: 29 times
- Been thanked: 15 times
- Contact:
Re: LDR (Light Dependent Resistor
Hi all,
It is long time ago that I have ask the above question. I couldn’t get to work on this by vary reasons.
But now I have time and I can work on this. I have read the full answer from Docara and I have made two simple flowcharts.
To make it more clear.
I have 8 power LEDs which are flashing in different patterns. When it is daylight they must be flashing at a brightness of 100%. When it get darker till totally dark they must flashing at a brightness from 100% to 70% or 60%.
I have made a test flowchart for only one LED to see if it works. My LDR is a NORPS12 with a 10K resistor to GND. (I don’t know if the resistor value is good)
The two attached flowcharts is what I have made.
This flowchart works fine with the LDR in hardware.
This flowchart will not flash the LED in hardware. In Flowcode simulation the LED is flashing.
I don’t know how to get this smooth to work.
Thanks,
Frank
It is long time ago that I have ask the above question. I couldn’t get to work on this by vary reasons.
But now I have time and I can work on this. I have read the full answer from Docara and I have made two simple flowcharts.
To make it more clear.
I have 8 power LEDs which are flashing in different patterns. When it is daylight they must be flashing at a brightness of 100%. When it get darker till totally dark they must flashing at a brightness from 100% to 70% or 60%.
I have made a test flowchart for only one LED to see if it works. My LDR is a NORPS12 with a 10K resistor to GND. (I don’t know if the resistor value is good)
The two attached flowcharts is what I have made.
Code: Select all
LDR Test - pwm plus led 01 - LDR WORKS.fcfx
Code: Select all
LDR Test - pwm plus led 01 - NOT FLASHING.fcfx
I don’t know how to get this smooth to work.
Thanks,
Frank
Last edited by Frank607 on Fri Feb 28, 2020 6:30 pm, edited 1 time in total.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: LDR (Light Dependent Resistor
Hi Frank,
Here is how I might do your two programs, I've hopefully removed everything you don't need to make it more obvious what you do need.
This one simply outputs the ADC LDR value onto the PWM duty.
This one will check if the LDR is below the threshold and if so will start flashing the brightness by varying the PWM duty. I may have got the yes/no branches wrong for night and day.
Your ADC slider in the simulation was tiny for me, sorry if it's now massive on your version.
I may also have got the wrong end of the stick but hopefully my programs will help to guide you.
Here is how I might do your two programs, I've hopefully removed everything you don't need to make it more obvious what you do need.
This one simply outputs the ADC LDR value onto the PWM duty.
This one will check if the LDR is below the threshold and if so will start flashing the brightness by varying the PWM duty. I may have got the yes/no branches wrong for night and day.
Your ADC slider in the simulation was tiny for me, sorry if it's now massive on your version.
I may also have got the wrong end of the stick but hopefully my programs will help to guide you.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 192
- Joined: Mon Mar 04, 2013 8:07 pm
- Has thanked: 29 times
- Been thanked: 15 times
- Contact:
Re: LDR (Light Dependent Resistor
Hi Ben,
Thanks for your input. But I think we misunderstand it.
Attached you find a simple program from a bigger program. I have made two flashing Macro’s (Pattern 01 and 02)
It would be nice to have an “LDR Macro” that every Pattern Macro will read. (or something like that)
I hope this program makes it more clear.
Thanks,
Frank
Thanks for your input. But I think we misunderstand it.
Attached you find a simple program from a bigger program. I have made two flashing Macro’s (Pattern 01 and 02)
It would be nice to have an “LDR Macro” that every Pattern Macro will read. (or something like that)
I hope this program makes it more clear.
Thanks,
Frank
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: LDR (Light Dependent Resistor
Hi Frank,
I believe I know what you are after.
I will modify your flowchart for you and upload it when finished.
I believe I know what you are after.
I will modify your flowchart for you and upload it when finished.
Martin
-
- Posts: 192
- Joined: Mon Mar 04, 2013 8:07 pm
- Has thanked: 29 times
- Been thanked: 15 times
- Contact:
Re: LDR (Light Dependent Resistor
Thanks Martin,
But take your time, this evening I don't have time.
Frank
But take your time, this evening I don't have time.
Frank
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: LDR (Light Dependent Resistor
No problem,
Can you let me know about input switch or switches.
E.g how many and the connections?
Using external or internal pull-ups etc?
Can you let me know about input switch or switches.
E.g how many and the connections?
Using external or internal pull-ups etc?
Martin
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: LDR (Light Dependent Resistor
Attached is first version.
You will need to connect LDR to +5V and ADC in (Pin 3 = AN1).
Connect a 22k to 100k resistor (or use 100k pot to deturmine a suitable value) from pin 3 to 0V.
For the switch connection, I have not used the internal pull-up resistor, so connect a 10K resistor from A0 (pin 2) to 0V.
Connect a SPST switch from pin 2 to +5V.
The pattern is selected by the single switch connected to pin 2 and the brightness is determined by the voltage that is at pin 3.
As the LDR gets brighter, the voltage across pin3 increases which in turn increases brightness.
The timer 2 interrupt is chosen to trigger every 0.1ms
So if you want to flash at 1 second then the interrupt will trigger 10000 times
Interrupt speed is chosen so the LEDs look like permanently on but dim due to persistence of vision.
Let me know if there is anything you don't understand and i will help you further.
Of course I can't confirm all is working as I don't have the same hardware as you.
You will need to connect LDR to +5V and ADC in (Pin 3 = AN1).
Connect a 22k to 100k resistor (or use 100k pot to deturmine a suitable value) from pin 3 to 0V.
For the switch connection, I have not used the internal pull-up resistor, so connect a 10K resistor from A0 (pin 2) to 0V.
Connect a SPST switch from pin 2 to +5V.
The pattern is selected by the single switch connected to pin 2 and the brightness is determined by the voltage that is at pin 3.
As the LDR gets brighter, the voltage across pin3 increases which in turn increases brightness.
The timer 2 interrupt is chosen to trigger every 0.1ms
So if you want to flash at 1 second then the interrupt will trigger 10000 times
Interrupt speed is chosen so the LEDs look like permanently on but dim due to persistence of vision.
Let me know if there is anything you don't understand and i will help you further.
Of course I can't confirm all is working as I don't have the same hardware as you.
- Attachments
-
- LDR TEST - 02.fcfx
- (14.12 KiB) Downloaded 197 times
Martin