Temperature and Light Sensor
To display the intensity of light and temperature and determining if it is a good day to sleep in.
- 1 x Micro:bit
- 1 x Breakout Board
- 1 x Crash Sensor
- 1 x Buzzer
- 1 x LED
Place the micro:bit on top of the breakout board. Then, attach the OLED screen onto the breakout board
Take the LED and place the wire in Pin 16(the last one!) of the Breakout Board. Then take the crash sensor and place the wire in Pin 8 of the Breakout Board
1x Breakout Board
1x Crash Sensor
Take 2 F-F wires and attach it one end to the buzzer and the other end to the G and S pins of the breakout board.
2x F-F Wires
1x Breakout Board
You have finished setting it up! Now, to the coding part. To start, you have to go to the micro:bit website and create a new project. After that, click on ‘Advanced’ and click on ‘Extensions’. Search for the Tinkercademy and download the extension shown in the picture above.
Now to the coding! Using the blocks, write the code shown above. This block of code tells the micro:bit what are the things it has right now.
This part of the code is for the light sensor. The purple blocks are the formula to display light intensity from digits 1-9. If it is less than 4, it says ‘Must be night time’ and if it more than 4, it says ‘Bright day’.
This part is for the temperature. If it is less than or equal to 28, it will say ‘It’s cold’ and shows a happy face. If it is more than 28 it will say ‘It’s hot’ and shows a sad face.
This is the last section. When buttons A and B are pressed, it will display “Looks like a nice day! Want to sleep in?” if temperature is less than 35(you can configure the temperature if you want!). It will proceed on to play a tune(via the buzzer) and switch the LED up. To switch the LED off, the crash sensor must be pressed and this is the function of the if block above the ‘on button A+B pressed’.
Download the file and move it into the micro:bit. And you are done! You can play around with your code to make it more lively. Great job!