Coding in the Classroom – Automated Night Light

Coding in the Classroom – Automated Night Light

By: Gina Silva

About the light sensor and light dimmer micro:bit activity

This activity is specifically designed as an introductory activity for students and teachers who may be new to the micro:bit. I was inspired to create this resource after completing the Computational Modeling in Mathematics and Science Education course, taught by Lisa Anne Floyd at Western University’s Faculty of Education. Teacher candidates in the program who have chosen STEM as their specialty have the wonderful opportunity to explore the vast world of coding through introductory activities such as this. After trying out Lisa’s activities in class, I felt encouraged to try making my own, and I quickly realised that coding can very easily be interwoven with curriculum to make engaging, hands-on lessons.

Before making this activity, I knew I would be teaching several sections of grade 9 Science students who may have little prior coding experience and were at different spots in the curriculum. The majority of the sections however, had explored at least a bit of Strand D, so I decided to make this a cross-curricular activity, which utilizes the following specific SNC 1W expectations:

  • A1.3 apply an engineering design process and associated skills to design, build, and test devices, models, structures, and/or systems
  • A1.4 apply coding skills to investigate and to model scientific concepts and relationships
  • D1.3 develop a plan of action to address a local or global electrical energy production or consumption issue, including strategies for energy conservation

This activity can be easily implemented at any point in the semester, as it does not require any prerequisite lessons to understand.

To introduce the activity, I used a short slide deck which highlighted key features of the micro:bit and its functions, and asked the students what actions people do in their homes that waste electrical energy. Many students answered: “keeping lights on unnecessarily”, which served as a great transition into the overview and goal of the activity. I showed the students samples of how the micro:bit would function after we make our program, and then we moved to the MakeCode editor to get started.

The most valuable resources you can use during the lesson are colour-printed handouts and/or a digital version of the handout on your Virtual Learning Environment for the students to readily access. I printed enough handouts so that the students would work from the handout in pairs (promoted collaboration), but each student had their own micro:bit and Chromebook so that they could individually experience the activity.

Most of the teacher’s time will likely be spent circulating around the classroom troubleshooting rather than instructing at the front of the class. Because the students have full access to the instructions and materials from the start, they have the freedom to move at a pace they are comfortable with during the lesson.

A link to the resource which can be downloaded can be found at the bottom of this page. Feel free to adapt the resources for your own students.


Gina Silva is an intermediate/senior preservice teacher from Western University with a passion for science and coding. In addition to her regular Biology/General Science teaching, she has taught coding as a guest instructor in grade 9 Science and Math classrooms in the London District Catholic School Board and the Thames Valley District School Board.

Her main goal through these lessons is to make coding more accessible and intuitive for students and teachers alike. Specifically, Gina aims to use Python, micro:bit and Scratch to provide students with more real-life connections and tangible applications of SNC 1W curriculum content.   

Scroll to Top