# Micro:Bit light sensor help needed

**URL:** <https://forum.makecode.com/t/micro-bit-light-sensor-help-needed/23699>\
**Category:** micro:bit\
**Created:** [October 27, 2023, 6:08pm UTC](https://forum.makecode.com/t/micro-bit-light-sensor-help-needed/23699 "2023-10-27T18:08:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![efty404](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/efty404/32/10931_2.png) [@efty404](https://forum.makecode.com/u/efty404)\
**Post date:** [October 27, 2023, 6:08pm UTC](https://forum.makecode.com/t/micro-bit-light-sensor-help-needed/23699/1 "2023-10-27T18:08:28Z")

</div>

very simple code not working properly. when in light it just flashes and doesn’t stay on. i just want it to stay on when in darkness and off when not.  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/3/3631b82216483088293865bf13df292020ade444.png)

---

<div class="post-metadata">

**Author:** ![dsssssssss9](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dsssssssss9/32/861_2.png) [@dsssssssss9](https://forum.makecode.com/u/dsssssssss9)\
**Post date:** [October 27, 2023, 8:59pm UTC](https://forum.makecode.com/t/micro-bit-light-sensor-help-needed/23699/2 "2023-10-27T20:59:07Z")

</div>

Hi

Is this more like what you wanted?

 ![microbit-screenshot](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/8/818a94e8c7e5bf27709262c3934c69fe26408454.png)

---

<div class="post-metadata">

**Author:** ![urassari](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/urassari/32/9535_2.png) [@urassari](https://forum.makecode.com/u/urassari)\
**Post date:** [October 27, 2023, 8:59pm UTC](https://forum.makecode.com/t/micro-bit-light-sensor-help-needed/23699/3 "2023-10-27T20:59:50Z")

</div>

the “light level” block can be u from 1 to 255.so putting in ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/4c6c4866002dc193c596e566e593798d61687903.png) wouldn’t make sense.

---

<div class="post-metadata">

**Author:** ![dsssssssss9](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dsssssssss9/32/861_2.png) [@dsssssssss9](https://forum.makecode.com/u/dsssssssss9)\
**Post date:** [October 27, 2023, 11:00pm UTC](https://forum.makecode.com/t/micro-bit-light-sensor-help-needed/23699/4 "2023-10-27T23:00:14Z")

</div>

Hi

My mistake i apologise for misreading your original question

The problem lies . i think with the way that the Micro:Bit uses the actual LED display to measure the light level?

1. As soon as the LED panel turns on, the Micro:Bit will detect the light from the LEDs & turn off the panel,

2)But as soon as this happens the micro:Bit will detect darkness & so turn on the Panel … so back to step 1

At the moment the only way i can think of solving this easily is to use either a separate light sensor ( shielded from the Micro:Bit Panel so it does not detect this being turned on ) OR as separate LED output ( which you will need to shield the Micro:Bit from)

Alternatively you could use 2 Micro:Bits ( 1 to detect light level in the room , 1 to output light) . The 1st Micro:Bit can send command via Radio to 2nd to turn on or off. Again you would have to shield the 1st micro:Bit so that the light from the 2nd does not cause it to send a turn off command

Again please accept my apologies

---

<div class="post-metadata">

**Author:** ![efty404](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/efty404/32/10931_2.png) [@efty404](https://forum.makecode.com/u/efty404)\
**Post date:** [November 6, 2023, 7:35pm UTC](https://forum.makecode.com/t/micro-bit-light-sensor-help-needed/23699/5 "2023-11-06T19:35:28Z")

</div>

thank you, this helped a lot!

---

<div class="post-metadata">

**Author:** ![dsssssssss9](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dsssssssss9/32/861_2.png) [@dsssssssss9](https://forum.makecode.com/u/dsssssssss9)\
**Post date:** [November 6, 2023, 7:59pm UTC](https://forum.makecode.com/t/micro-bit-light-sensor-help-needed/23699/6 "2023-11-06T19:59:31Z")

</div>

Hi  
Glad to have been of some help .

How are you / did you solve the problem in the end …

Always good to share solutions as others are probably having the same difficulty.

TTFN
