ELECFREAKS Sensor:bit (IO Extension Board For micro:bit) Documentation
The ELECFREAKS Sensor:bit is an IO extension board designed for the micro:bit, a popular microcontroller board used in educational and prototyping applications. This board provides an easy-to-use interface for connecting various sensors and modules, allowing users to explore the world of IoT and robotics with ease.
Compatible with micro:bit v1.5 and v2.0
12 digital IO pins and 6 analog IO pins
Supports various sensor modules, including temperature, humidity, light, sound, and motion sensors
Onboard buzzer and LED indicators
Power supply: 3V - 5V (via micro:bit USB or battery)
The Sensor:bit board has the following pinout:
| Pin | Function |
| --- | --- |
| P0 - P12 | Digital IO pins |
| A0 - A5 | Analog IO pins |
| BUZZER | Onboard buzzer |
| LED | Onboard LED indicator |
| VCC | Power supply (3V - 5V) |
| GND | Ground |
### Example 1: Reading Temperature with a DS18B20 Sensor
In this example, we'll use the Sensor:bit to read temperature data from a DS18B20 temperature sensor.
```python
from microbit import
import sensorbit
# Initialize the Sensor:bit
sensorbit.init()
# Define the DS18B20 sensor pin
temp_sensor = sensorbit.Pin(P0, sensorbit.Pin.IN)
while True:
# Read temperature data from the sensor
temp_c = temp_sensor.read_analog()
temp_f = (temp_c 9/5) + 32
# Display temperature on the micro:bit screen
display.scroll("Temp: {:.1f}C {:.1f}F".format(temp_c, temp_f))
sleep(1000)
```
### Example 2: Controlling a Servo Motor
In this example, we'll use the Sensor:bit to control a servo motor using the micro:bit's PWM output.
```python
from microbit import
import sensorbit
# Initialize the Sensor:bit
sensorbit.init()
# Define the servo motor pin
servo_pin = sensorbit.Pin(P1, sensorbit.Pin.OUT)
while True:
# Set the servo motor to 0 degrees
servo_pin.write_analog(0)
sleep(1000)
# Set the servo motor to 90 degrees
servo_pin.write_analog(90)
sleep(1000)
# Set the servo motor to 180 degrees
servo_pin.write_analog(180)
sleep(1000)
```
### Example 3: Sound Detection with a Microphone
In this example, we'll use the Sensor:bit to detect sound levels using a microphone module.
```python
from microbit import
import sensorbit
# Initialize the Sensor:bit
sensorbit.init()
# Define the microphone pin
mic_pin = sensorbit.Pin(P2, sensorbit.Pin.IN)
while True:
# Read sound level data from the microphone
sound_level = mic_pin.read_analog()
# If sound level is above a certain threshold, trigger an action
if sound_level > 500:
display.show(Image.HAPPY)
buzzer.play("C4", 500)
else:
display.show(Image.SAD)
```
These examples demonstrate the versatility of the ELECFREAKS Sensor:bit and its ability to interface with various sensors and modules. By using the micro:bit's built-in functionality and the Sensor:bit's IO pins, users can create a wide range of IoT and robotics projects.