Hi
I am using BL0011 progammer and trying to switch an output on and off depending on light conditions. The programme downloads and switches on the LED but does not switch off if I cover the sensor to simulate darkness. I have attached the file
Can you please help
Nev
Light Sensor
-
- Posts: 6
- http://meble-kuchenne.info.pl
- Joined: Fri Nov 19, 2021 12:09 pm
-
- Matrix Staff
- Posts: 1921
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 623 times
- Been thanked: 645 times
Re: Light Sensor
Hello.
Can you explain what hardware you have got, e.g the grove light sensor or an LDR with a resistor or a - BL0114 - Combo board etc.
I have attached an example for you to play with.
First, you need a continuous look otherwise your code will run one from top to bottom then end.
Nothing else will happen on your hardware
The groove component on Flwocde is just an analogue to digital converter (ADC)
As you are using byte , the value will be 0 to 255
The brighter the light the higher the value.
For example dim light, byte could = 50
Bright light, byte could = 220.
What your flowchart needs to do is have a forever loop, Read the light intensity, and then act on the result of the light intensity.
You will need to check the sensor and LED properties are connected to the correct pins of your hardware.
When you run the simulation, when the slider is below 0.5 the LED will light & when the slider is above 0.50 the LED will go out.
What you recommend you do is to go to here, and select Introduction to Microcontroller Programming
Download and work your way through the course.
Can you explain what hardware you have got, e.g the grove light sensor or an LDR with a resistor or a - BL0114 - Combo board etc.
I have attached an example for you to play with.
First, you need a continuous look otherwise your code will run one from top to bottom then end.
Nothing else will happen on your hardware
The groove component on Flwocde is just an analogue to digital converter (ADC)
As you are using byte , the value will be 0 to 255
The brighter the light the higher the value.
For example dim light, byte could = 50
Bright light, byte could = 220.
What your flowchart needs to do is have a forever loop, Read the light intensity, and then act on the result of the light intensity.
You will need to check the sensor and LED properties are connected to the correct pins of your hardware.
When you run the simulation, when the slider is below 0.5 the LED will light & when the slider is above 0.50 the LED will go out.
What you recommend you do is to go to here, and select Introduction to Microcontroller Programming
Download and work your way through the course.
- Attachments
-
- Flowcode LDR v2.fcfx
- (11.54 KiB) Downloaded 479 times
Martin
-
- Posts: 6
- Joined: Fri Nov 19, 2021 12:09 pm
Re: Light Sensor
Hi
Thanks for your help, Whilst the simulation operates ok I have the same issue in that the output D0 is always on regardless of light condition. I have the following set up. EBLOCKS 2 Grove board BL0129-1 connected to a grove light sensor. I have set the channel input to An0 as the grove board is connected to port 1. Can you please help I have attached a file and a photo of the set up
Thanks for your help, Whilst the simulation operates ok I have the same issue in that the output D0 is always on regardless of light condition. I have the following set up. EBLOCKS 2 Grove board BL0129-1 connected to a grove light sensor. I have set the channel input to An0 as the grove board is connected to port 1. Can you please help I have attached a file and a photo of the set up
- Attachments
-
- IMG20220509102714.jpg (50.04 KiB) Viewed 6344 times
-
- IMG20220509102657.jpg (142.61 KiB) Viewed 6344 times
-
- Flowcode LDR v2.fcfx
- (13.14 KiB) Downloaded 475 times
-
- Matrix Staff
- Posts: 1921
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 623 times
- Been thanked: 645 times
Re: Light Sensor
What I would recommend is testing that the sensor is working as expected.
If you load the attached flowchart onto your hardware you expose and shade the light going to the sensor and observe the value via the LEDs.
Each LED from 0 to 7 increases by the power of 2 ,i.e doubles in value.
Therefore LED 0 = 1, LED1 = 2, LED2 = 4, LED3 = 8, LED4 = 16 ........LED7 = 128
First partly shade the sensor so it's at the level at which you want the threshold of the LED to light
You will need to look at what LEDs are on and then add together all the values.
E.g LED1, LED3, LED5 & LED6 are the only ones on the the value =
If you want the LED to go on when the sensor is partly shaded, set the value for
If the LEDs don't change with brightness then there could be a hardware issue.
You can measure the voltage across the signal of the sensor and ground.
The signal voltage should be Supply voltage/256 * value derived from lit LEDs
Using 106 as the example and the supply voltage is 5V
Then the voltage across the signal pin (A0 id the micro) should be 5 / 256 * 106 = 2.07V
If I was you and the LEDs 0 to 7 do change value with brightness, it will be worth noting the full light and fall dark values.
If you load the attached flowchart onto your hardware you expose and shade the light going to the sensor and observe the value via the LEDs.
Each LED from 0 to 7 increases by the power of 2 ,i.e doubles in value.
Therefore LED 0 = 1, LED1 = 2, LED2 = 4, LED3 = 8, LED4 = 16 ........LED7 = 128
First partly shade the sensor so it's at the level at which you want the threshold of the LED to light
You will need to look at what LEDs are on and then add together all the values.
E.g LED1, LED3, LED5 & LED6 are the only ones on the the value =
Code: Select all
2 + 8 + 32 + 64 = 106
Code: Select all
LightIntensity > 106
You can measure the voltage across the signal of the sensor and ground.
The signal voltage should be Supply voltage/256 * value derived from lit LEDs
Using 106 as the example and the supply voltage is 5V
Then the voltage across the signal pin (A0 id the micro) should be 5 / 256 * 106 = 2.07V
If I was you and the LEDs 0 to 7 do change value with brightness, it will be worth noting the full light and fall dark values.
- Attachments
-
- Flowcode LDR test.fcfx
- (10.24 KiB) Downloaded 401 times
Martin
-
- Posts: 6
- Joined: Fri Nov 19, 2021 12:09 pm
Re: Light Sensor
Hi
Thanks for your recent post I have resolved the issue I had it is now working as I need it.
Thanks for your help

Thanks for your recent post I have resolved the issue I had it is now working as I need it.
Thanks for your help

-
- Matrix Staff
- Posts: 1921
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 623 times
- Been thanked: 645 times
Re: Light Sensor
Can you explain what you mean in more detail?
For beginners, there is a great free course to follow called Introduction to Microcontroller Programming.
If you don't have the hardware, just use the simulation capabilities.
Alternatively, there is a get starting guide.
It's still great, but does not cover as much or does not have teaching exercises as the above course.
For beginners, there is a great free course to follow called Introduction to Microcontroller Programming.
If you don't have the hardware, just use the simulation capabilities.
Alternatively, there is a get starting guide.
It's still great, but does not cover as much or does not have teaching exercises as the above course.
Martin
Re: Light Sensor
so ive got the code you have given is it supposed to be noticable what is happening on debug or is it just on the hardware