{"product_id":"sensor-for-microbit","title":"Sensor for micro:bit","description":"\u003cp\u003eThe MonkMakes Sensor Board for micro:bit allows you to sense sound level, temperature and light level.\u003c\/p\u003e\n\u003ch2\u003eFeatures\u003c\/h2\u003e\n\u003cul\u003e\n\u003cli\u003e3V and GND connections can be made from either side and allow you to power a second board such as the\u003cspan\u003e \u003c\/span\u003eMonkMakes Relay Board\u003cspan\u003e \u003c\/span\u003eor\u003cspan\u003e \u003c\/span\u003eMonkMakes Speaker.\u003c\/li\u003e\n\u003cli\u003eLED ‘power on’ indicator\u003c\/li\u003e\n\u003cli\u003eReverse polarity protection\u003c\/li\u003e\n\u003cli\u003eAll three sensors are analog and can be connected to pins P0, P1 and P2 using alligator clips.\u003c\/li\u003e\n\u003c\/ul\u003e\n\u003ch2\u003eGetting Started\u003c\/h2\u003e\n\u003cp\u003eConnecting to your micro:bit\u003c\/p\u003e\n\u003cp\u003eYou only have to wire up the sensors that you are actually using, but you could wire all the sensors up as shown below. The code examples below assume that pin 0 is used for sound, pin 1 for temperature and pin 2 for light. You can use any pin for any of the sensors, but remember to modify the code to match the pin you are using.\u003c\/p\u003e\n\u003cp\u003e\u003cimg src=\"https:\/\/cdn.shopify.com\/s\/files\/1\/0174\/1800\/files\/sound_sensing-591x1024.png?v=1512400300\u0026amp;width=700\" alt=\"\"\u003e\u003c\/p\u003e\n\u003ch2\u003eSound\u003c\/h2\u003e\n\u003cp\u003eThe Sensor for micro:bit uses a MEMs (microphone on a chip) and a pre-amplifier. The output of the sound sensor is connected to an analog input where it can be sampled. The sound signal varies about the 1.5V level. So, silence will produce an analog output of around 1.5V. When there is sound the analog readings will oscillate above and below the 1.5V level like this:\u003c\/p\u003e\n\u003cp\u003e\u003cimg src=\"https:\/\/cdn.shopify.com\/s\/files\/1\/0174\/1800\/files\/scope_speach-annotated-1024x355.png?v=1512400335\u0026amp;width=700\" alt=\"\"\u003e\u003c\/p\u003e\n\u003cp\u003eThis is why 511 is subtracted from the readings in the code examples below.\u003c\/p\u003e\n\u003cp\u003e\u003cstrong\u003eJavaScript Blocks Editor\u003c\/strong\u003e\u003c\/p\u003e\n\u003cp\u003eHere is an example of using the Sensor Board to display a bargraph to indicate the sound level. Click on the image below to try it out. Making a noise into the microphone will make the LEDs dance.\u003c\/p\u003e\n\u003cp\u003e\u003cimg src=\"https:\/\/cdn.shopify.com\/s\/files\/1\/0174\/1800\/files\/sound_block-1024x184.png?v=1512400386\u0026amp;width=700\" alt=\"\"\u003e\u003c\/p\u003e\n\u003cp\u003e\u003cstrong\u003eMicroPython\u003c\/strong\u003e\u003c\/p\u003e\n\u003cp\u003e\u003ccode\u003efrom microbit import *\u003cbr\u003e\u003cbr\u003edef bargraph(a):\u003cbr\u003edisplay.clear()\u003cbr\u003efor y in range(0, 5):\u003cbr\u003eif a \u0026gt; y:\u003cbr\u003efor x in range(0, 5):\u003cbr\u003edisplay.set_pixel(x, 4-y, 9)\u003cbr\u003e\u003cbr\u003ewhile True:\u003cbr\u003esound_level = (pin0.read_analog() - 511) \/ 100\u003cbr\u003ebargraph(sound_level)\u003c\/code\u003e\u003c\/p\u003e\n\u003ch2\u003eTemperature\u003c\/h2\u003e\n\u003cp\u003eThe Sensor for micro:bit uses a thermistor to measure temperature. The temperature output from the board is a voltage that indicates the temperature. This is then measured using an analog input on the micro:bit.\u003c\/p\u003e\n\u003cp\u003eThe calculations for converting this voltage reading to an actual temperature are quite complicated and so the code examples here will only give a rough idea of temperature.\u003c\/p\u003e\n\u003cp\u003eIf you want your temperatures in Fahrenheit, then multiply the temperature in degrees C by 9, divide the result by 5 and then add 32.\u003c\/p\u003e\n\u003cp\u003e\u003cstrong\u003eJAVASCRIPT BLOCKS EDITOR\u003c\/strong\u003e\u003c\/p\u003e\n\u003cp\u003eThis is an example of using the Sensor Board to display the temperature, try putting your finger on the temperature sensor to warm it up. You can run the example below by clicking on it.\u003c\/p\u003e\n\u003cp\u003e\u003cimg src=\"https:\/\/cdn.shopify.com\/s\/files\/1\/0174\/1800\/files\/thermometer_blocks-1024x310.png?v=1512400524\u0026amp;width=700\" alt=\"\"\u003e\u003c\/p\u003e\n\u003cp\u003e\u003cstrong\u003eMicroPython\u003c\/strong\u003e\u003c\/p\u003e\n\u003cp\u003e\u003ccode\u003efrom microbit import *\u003cbr\u003e\u003cbr\u003ewhile True:\u003cbr\u003ereading = pin1.read_analog()\u003cbr\u003etemp_c = int(reading \/ 13.33 - 14)\u003cbr\u003edisplay.scroll(str(temp_c))\u003cbr\u003esleep(500)\u003c\/code\u003e\u003c\/p\u003e\n\u003ch2\u003eLight\u003c\/h2\u003e\n\u003cp\u003eThe light sensor uses a phototransistor to measure the light level and produces an output voltage that increases as the light level increases. Here is a guide to the kind of light level you might get from the sensor under different conditions (0 to 1023).\u003c\/p\u003e\n\u003cul\u003e\n\u003cli\u003eDark 0 to 3\u003c\/li\u003e\n\u003cli\u003eDimly lit room 6 to 10\u003c\/li\u003e\n\u003cli\u003eIndoors directly under a light 10 to 50\u003c\/li\u003e\n\u003cli\u003eOutdoors (dull day) 100 to 200\u003c\/li\u003e\n\u003cli\u003eOutdoors (sunny day) 800 to 900\u003c\/li\u003e\n\u003c\/ul\u003e\n\u003cp\u003eEven though the maximum analog read value is 1023, the maximum reading from this sensor is around 900.\u003c\/p\u003e\n\u003cp\u003e\u003cstrong\u003eJAVASCRIPT BLOCKS EDITOR\u003c\/strong\u003e\u003c\/p\u003e\n\u003cp\u003eHere is an example of using the Sensor Board to display a bargraph to indicate the light level. Click on the image below to try it out. Put your finger over the light sensor to make it dark or shine a flash-light onto it to make more LEDs light up.\u003c\/p\u003e\n\u003cp\u003e\u003cimg src=\"https:\/\/cdn.shopify.com\/s\/files\/1\/0174\/1800\/files\/microbit-screenshot-sensor-1024x212.png?v=1512400668\u0026amp;width=700\" alt=\"\"\u003e\u003c\/p\u003e\n\u003cp\u003e\u003cstrong\u003eMicroPython\u003c\/strong\u003e\u003c\/p\u003e\n\u003cp\u003e\u003ccode\u003efrom microbit import *\u003cbr\u003e\u003cbr\u003edef bargraph(a):\u003cbr\u003edisplay.clear()\u003cbr\u003efor y in range(0, 5):\u003cbr\u003eif a \u0026gt; y:\u003cbr\u003efor x in range(0, 5):\u003cbr\u003edisplay.set_pixel(x, 4-y, 9)\u003cbr\u003e\u003cbr\u003ewhile True:\u003cbr\u003elight_level = pin2.read_analog() \/ 10\u003cbr\u003ebargraph(light_level)\u003c\/code\u003e\u003c\/p\u003e","brand":"Monk Makes","offers":[{"title":"Default Title","offer_id":46039322427452,"sku":"hbx1787257879267","price":6.35,"currency_code":"USD","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0676\/6985\/2220\/files\/sensor-for-microbit_1.jpg?v=1787257887","url":"https:\/\/luxecladstore.shop\/products\/sensor-for-microbit","provider":"My Store","version":"1.0","type":"link"}