Skip to content


Energy cost calculator

Avancé | MakeCode, Python | Boutons, Capteur de luminosité, Écran LED | 13 Climat, Capteurs, Entrée / Sortie, Logique booléenne, Variables

Étape 1 : Fais-le

Qu'est-ce que c'est ?

The third of three projects to help you gather data about your energy use. Learn how to work out the cost of energy and make a timer that measures how much electric lights cost to run.

Ce projet s’inscrit dans une série de projets visant à proposer des activités de résolution de problèmes et de prototypage conçues pour explorer la technologie, par exemple des solutions aux défis des Objectifs mondiaux pour le développement durable.


Guide de codage

Ce que vous apprendrez

  • How to use mathematics to convert units: watts to kilowatts and minutes to hours
  • How to calculate energy used in kilowatt hours (kWh) from power measured in watts (W) and time.
  • How variables can be used to store values for a user to configure a system prior to use.

Comment l’utiliser 

The previous project, the Energy light timer, measured how long a light is switched on. This special version of the same project works in a similar way, but it calculates and displays the cost of the energy used by a light bulb rather than the time.
To use it, you need to know 3 numbers:

  • The light reading when the light is switched on. This is the number you found using the first project, the Energy light meter and used in the Energy light timer project
  • What wattage your lighting is. This is usually printed on the lightbulb.
  • And how much you pay for your electricity, the unit cost per kWh

The program stores these three numbers in variables which you need to edit before using this project.

Use the Light meter project as before to get a number to put in to the LIGHT variable.

Look at the light bulb to find out how many watts it uses. Remember light bulbs can get very hot and are usually connected to mains electricity, so ask an adult to do this for you. Put that number in the WATTS variable.

Finally put in the cost per kWh in the COSTPERKWH variable. You may need to ask an adult to find this number for you, or find out who supplies your energy and research their unit cost online.

Flash this program onto a micro:bit and attach a battery pack. Place this timer near a light source, and the micro:bit will use the information you gave it about light intensity, light bulb wattage and the cost of your electricity combined with readings from its built-in light sensor and the processor’s timer to monitor the cost of the electricity used over a period of time.

You can take cost readings at the same time every day or every week by pressing button B. Re-set it by pressing the reset button on the back of the micro:bit and check it’s gone back to zero by pressing button B again.

Remember this is just one lightbulb, so consider the cost across a whole building for a year.
Now you have some data about energy use, how would you go about changing people’s behaviour to save energy and money, and perhaps help combat climate change?

Comment ça marche

  • The program times how long a light is left switched on using the micro:bit's light sensor.
  • The amount of energy you use is calculated by multiplying the power of the lightbulb by the time. This is measured in kilowatt hours (kWh). Because a lightbulb's power is usually measured in watts, not kilowatts, the program converts from watts to kilowatts by dividing by 1000:
    watts ÷ 1000 = kilowatts
    So for example, a 60 watt lightbulb uses 0.06 kilowatts of power:
    60 W ÷ 1000 = 0.06 kW
  • The program also converts the time units. To convert time from seconds to hours divide the time in seconds by 60. So:
    600 minutes ÷ 60 = 10 hours
  • To work out the cost of energy used in a given period of time, the program multiplies the energy use in kilowatt hours by the unit cost per kilowatt hour.
  • If my energy costs £0.16p per kWh, leaving a 60 watt lightbulb on for 10 hours will cost me ten pence:
    0.6 kWh × 16p = 9.6p

Ce dont vous aurez besoin

  • micro:bit
  • MakeCode ou éditeur Python
  • battery pack (recommended)

Étape 2 : Programme-le

Étape 3 : Améliore-le

  • Use multiple micro:bits to measure costs of lighting in different places.
  • Use radio to transmit cost data to another micro:bit and reset the timer remotely.