Table of Contents
Acknowledgments xvii
Introduction xix
About This Book xx
Experiments xxi
Projects xxi
Code and Resources xxii
1 Getting Started 1
A Tour of the Micro:bit 2
The Top 2
The Bottom 4
Power and the Micro:bit 4
Connecting Electronics with Input/Output Pins 7
Built-in Peripherals 9
Hardware Essentials 10
Programming the Micro:bit 11
Connecting your Micro:bit 11
Programming with Blocks: Hello World 12
Programming with MicroPython: Hello World 19
Programming Concepts 25
Variables 25
Arithmetic 27
If Blocks 29
Strings 30
Arrays and Lists 32
Programming Wrap-Up 33
Downloading the Code 34
Downloading the Blocks Code 34
Downloading the MicroPython Code 35
Summary 37
2 Super Sonic 39
Connecting a Loudspeaker to a Micro:bit 40
The Quiet Method: Headphones 40
The Ghetto Blaster Method: Speaker 42
Experiment 1 Generating Sounds 43
What You'll Need 43
Construction 43
Code 44
Things to Try 45
How It Works: Frequency and Sound 45
Experiment 2 It Speaks! 47
What You'll Need 47
Construction 47
Code 48
Project: Musical Doorbell 48
What You'll Need 49
Construction 50
Code 51
Things to Try 53
Project: Shout-O-Meter 54
What You'll Need 55
Construction 55
Code 56
How It Works: Microphone Output 58
Summary 59
3 Luminous Light 61
Experiment 3 Sensing Light 62
What You'll Need 62
Construction 62
Code 62
How It Works 63
Project: Automatic Night-Light 63
What You'll Need 64
Construction 64
Code 65
Project: Light Guitar 66
What You'll Need 66
Construction 67
Code 71
Project: Infinity Mirror 73
What You'll Need 73
Construction 75
Code 81
How It Works 83
Summary 84
4 Magical Magnetism 85
Project: Compass 86
What You'll Need 86
Construction 87
Code 89
Things to Try 92
How It Works: The Earth's Magnetic Field 92
Experiment 4 Measuring Magnetic Fields 93
What You'll Need 93
Construction 94
Code 97
Things to Try 98
How It Works: The Strength of Magnets 99
Project: Magnetic Door Alarm 99
What You'll Need 100
Construction 101
Code 102
Things to Try 103
Summary 104
5 Amazing Acceleration 105
Experiment 5 Gestures 106
What You'll Need 106
Construction 107
Code 107
Things to Try 109
How It Works: Force, Acceleration, and Gravity 109
Experiment 6 Real-Time Acceleration Plotting 112
What You'll Need 112
Construction 112
Code 114
How It Works: Calculating Net Acceleration 114
Project: Toothbrushing Monitor 116
What You'll Need 117
Construction 117
Code 118
Things to Try 121
Experiment 7 Logging Acceleration to a File 121
What You'll Need 122
Construction 122
Code 125
Things to Try 126
Project: Acceleration Display 127
What You'll Need 128
Construction 128
Code 129
Summary 130
6 Mad Movement 131
Experiment 8 Making a Servomotor Move 132
What You'll Need 133
Construction 133
Code 135
How It Works: Servomotors and Pulses 137
Project: Animatronic Head (Mike the Micro:bit Robot) 139
What You'll Need 140
Construction 141
Code 151
Things to Try 155
Project: Robot Rover 155
What You'll Need 156
Construction 157
How It Works: Motors and the Flow of Electricity 163
Summary 164
7 Time Travel 165
Experiment 9 Keeping Time 166
What You'll Need 167
Construction 167
Code 168
How It Works: Keeping Time 169
Project: Binary Clock 169
How to Read the Binary Clock 171
What You'll Need 171
Construction 172
Code 172
How It Works: Telling the Time in Binary 176
Project: Talking Clock 178
What You'll Need 178
Construction 179
Code 179
How It Works: Teaching the Micro:bit to Speak 182
Summary 182
8 Mad Scientist Mind Games 183
Experiment 10 How Fast Are Your Nerves? 184
What You'll Need 185
Construction 185
Testing Your Nervous System 186
Code 188
Things to Try 191
How It Works: Measuring Your Reaction Time 191
Project: Lie Detector 193
What You'll Need 194
Construction 194
Code 195
How It Works: Detecting Lies Through Sweat, Voltage, and Resistance 197
Summary 198
9 Environmental Madness 199
Experiment 11 Measuring Temperature 200
What You'll Need 200
Construction 201
Code 202
How It Works: Why Does a Processor Heat Up? 203
Project: Temperature and Light Logger 204
What You'll Need 205
Construction 206
Code 208
How It Works: Sensors 210
Project: Automatic Plant Waterer 212
What You'll Need 213
Construction 215
Code 218
Things to Try 222
How It Works: Measuring Soil Dampness 222
Summary 223
10 Radio Activity 225
Experiment 12 Finding the Radio Range 226
What You'll Need 226
Construction 227
Code 228
How It Works: Radio Signals 231
Project: Wireless Doorbell 231
What You'll Need 232
Construction 233
Code 233
Things to Try 235
How It Works: Sending and Receiving 235
Project: Micro:bit-Controlled Rover 236
What You'll Need 236
Construction 237
Code 238
Things to Try 241
How It Works: Motor Driver Blocks 241
Summary 243
Appendix: Get the Parts 245
Useful Tools 246
Common Parts 247
Powering Your Micro:bit 248
Micro:bit Accessories 249
Miscellaneous 250