#8 Night and Day Project With micro:bit
How about playing the Day and Night game electronically, a game often played in schools? In this game, when the teacher says "night," we bend our heads, and when the teacher says "day," we raise our heads. It's a game that involves using your attention and reflexes. In this project, we will use a 0.96" 128x64 pixel I2C OLED screen. Since OLED screens can be used as an artificial light source, you can reflect the characters on the screen onto any desired plane using a lens or a mirror. Systems that can project information, road, and traffic data onto smart glasses and car windows can be created using OLED screens.
Light sensors are devices that can measure the light levels in the environment, also known as photodiodes. The electrical conductivity of the sensor changes when exposed to light. By coding, we will control the light sensor and develop electronic systems affected by the amount of light.
First, we will provide the player to press the button to start the game. Then, on PicoBricks' OLED screen, we will randomly display the expressions NIGHT and DAY for 2 seconds each. If the word NIGHT is displayed on the OLED screen, the player must cover the LDR sensor with their hand within 2 seconds. If the word DAY is displayed on the OLED screen, the player must remove their hand from the LDR sensor within 2 seconds. Each correct response from the player will earn them 10 points and create a checkmark (✓) icon on the Micro:Bit Matrix LEDs. When the player gives an incorrect response, the game will end, and the screen will display a written message indicating the end of the game along with a cross (X) icon on the Matrix LEDs. The buzzer will play a sound in a different tone, and the OLED screen will show the score information. If the player achieves a total of 10 correct responses and earns 100 points, the message "Congrats!!!" will be displayed on the OLED screen at the designated positions.
Connection Diagram:
You can prepare this project without making any cable connections.

Project Images:
![]() |
![]() |
![]() |
MakeCode Code of The Project
Python Code of The Project:
#Night and Day Projects
from microbit import *
from picobricks import *
import neopixel
import random
import music
# Pin Initialization
LDR_Pin = pin0
Button_Pin = pin2
RGB_Pin = pin8
Num_Leds = 3
# Function Initialization
oled = SSD1306()
oled.init()
oled.clear()
np = neopixel.NeoPixel(RGB_Pin, Num_Leds)
counter=0
falseValue=0
button = Button_Pin.read_digital()
while Button_Pin.read_digital()==0:
oled.add_text(0,1,"Press BUTTON")
oled.add_text(2,2,"to START!")
oled.clear()
while counter!=100 and falseValue==0:
light = LDR_Pin.read_analog()
rand=random.randint(1, 2)
if rand==1:
oled.add_text(0,0,"NIGHT")
else:
oled.add_text(0,0,"DAY")
sleep(3000)
light = LDR_Pin.read_analog()
if light<60 and rand==1:
display.show(Image.YES)
counter=counter+10
elif light>60 and rand==1:
display.show(Image.NO)
falseValue=1
elif light>60 and rand==2:
display.show(Image.YES)
counter=counter+10
else:
display.show(Image.NO)
falseValue=1
oled.clear()
if counter==100:
oled.add_text(0,0,"Congrats!!!")
oled.add_text(0,1,"Top Score:")
oled.add_text(5,2,str(counter))
music.play(music.WEDDING)
else:
oled.add_text(0,0,"Game Over")
oled.add_text(0,1,"Score:")
oled.add_text(5,2,str(counter))
MicroBlocks Code of The Project