🔬
Wiki.Linhkientot
  • 👋Chào mừng tới Linhkientot's Wiki
  • Hướng dẫn phần mềm
    • Cài đặt Arduino IDE 2.0
    • Cài đặt phần mềm Mixly
    • Cài đặt phần mềm Mind+
    • Cài đặt phần mềm Thonny
  • Arduino Products
    • Hướng dẫn ban đầu Arduino IDE
      • Hướng dẫn nạp chương trình Arduino IDE
      • Thêm thư viện Arduino IDE
      • Cài đặt Driver CH340 trên MAC OS
      • Lập trình Board ESP32 trên Arduino IDE
    • Arduino Starter Kit
      • Lesson 0. Getting Started - install IDE
      • Lesson 2. LEDs
      • Lesson 3. RGB LEDs
      • Lesson 4. Eight LEDs and a Shift Register
      • Lesson 5. The Serial Monitor
      • Lesson 6. Digital Inputs
      • Lesson 7. Make an RGB LED Fader
      • Lesson 8. Analog Inputs
      • Lesson 9. Sensing Light
      • Lesson 10 Making Sounds
      • Lesson 11 LCD Displays Part 1
      • Lesson 12 LCD Displays Part 2
      • Lesson 13 DC Motors
      • Lesson 14 Servo Motors
      • Lesson 15 DC Motor Reversing
      • Lesson 16 Stepper Motors
      • Lesson 17 Email Sending Movement Detector
    • Arm Robot
      • Hướng dẫn lắp ráp Arm-4DoF
      • Hướng dẫn lắp ráp Arm-6DoF
      • Hướng dẫn lắp ráp Arm - 6DoF đế tròn quay
    • Car Robot
      • Hướng dẫn lắp ráp tank TS-100
    • Arm Car Robot
    • Smart home IoT
    • Lập trình cảm biến khí ga/ khói MQ-2 Arduino
  • Micro:bit Products
    • Micro:bit Setup
    • Micro:bit Starter Kit V1
      • Setting up the micro:bit with Makecode
      • Set up Arduino IDE for micro:bit
      • Using the Buttons and LED Matrix on micro:bit
      • Pushbutton with micro:bit
      • Tilt Sensor with micro:bit
      • Temperature Sensor with micro:bit
      • DC Motor with micro:bit
      • Sound Sensor with micro:bit
      • Raindrop Sensor with micro:bit
      • Make an RGB LED Blink with micro:bit
      • Ultrasonic Distance Sensor with micro:bit
      • Analog Inputs and micro:bit
      • Servo with micro:bit
      • Smoke sensor with micro:bit
      • Light-dependent Resistor with micro:bit
      • Infrared Obstacle Avoidance Sensor with micro:bit
      • Using LEDs with micro:bit
    • Micro:bit Starter Kit V2
      • Microbit Introduction
      • Microbit Basic Lessons
      • 1. Lesson: Đèn LED nhấp nháy
      • 2. Lesson: RGB Led
      • 3. Lesson: Đọc giá trị từ triết áp
      • 4. Lesson: Đọc nút nhấn
      • 5. Lesson: Servo Motor
      • 6. Lesson: Passive Buzzer-Còi thụ động
      • 7. Lesson: Active Buzzer-Còi chủ động
      • 8. Lesson: Compass-La bàn
      • 9. Lesson: Accelerometer-Gia tốc kế
      • 10. Lesson: Module phát hiện âm thanh
      • 11. Lesson: Cảm biến ánh sáng (quang trở)
      • 12. Lesson: Cảm biến ngọn lửa
      • 13. Lesson: Cảm biến khói
      • 14. Lesson: Cảm biến siêu âm
      • 15. Lesson: ModuleRelay
      • 16. Lesson: Cảm biến nhiệt độ (DHT11)
      • 17. Lesson: Bộ điều khiển từ xa (IR)
      • 18. Lesson: Hiển thị màn hình LCD i2c 1602
      • 19. Lesson: Hiển thị nhiệt độ, độ ẩm trên màn hình LCD
      • 20. Lesson: Điều khiển quạt bằng Relay
    • Micro:bit Advanced Kit V2
      • Giới thiệu BBC Sensor Shield V2
      • Danh sách linh kiện bộ Kit
    • Micro:bit Car
  • ESP32 PRODUCTS
    • Hướng dẫn lập trình ESP32
  • Raspberry Products
    • Raspberry Pico Kit
    • Raspberry Pico Car
  • Group Robots
    • 🤖Arduino Robots
    • 🐦Micro:bit Robots
    • 🍓Raspberry Robots
Powered by GitBook
On this page
  1. Micro:bit Products
  2. Micro:bit Starter Kit V1

Analog Inputs and micro:bit

PreviousUltrasonic Distance Sensor with micro:bitNextServo with micro:bit

Step 1 What is a potentiometer?

  • You're probably already familiar with using a potentiometer as they are commonly found on many electrical devices, such as in audio equipment where they are used for volume control. After all, potentiometers are sensors! What's a sensor? Simply put, a sensor is a device that receives and responds to a signal.

    Potentiometers are analog input sensors. While digital sensors deal with values that are either ‘1’ or ‘0’, analog sensor values are continuous. Analog sensors are able to tell us not just whether it senses something, but also how much of that something it senses.

  • In the case of the potentiometer, it measures electric potential, also known as voltage.

  • It has three pins.

    Two terminals (labelled 'A' and 'B' in the diagram) are connected to a resistive material, while a third terminal is connected to an adjustable wiper (labelled 'W' in the diagram).

    The resistance between the two outer terminals is fixed; it is the maximum resistance of the potentiometer.

    The resistance between the middle terminal and either one of the outer terminals ranges from 0 Ω to the maximum resistance of the potentiometer as the knob is moved.

Step 2 The potentiometer module

  • Let's take a closer look at the adjustable potentiometer module that will be used in this guide. There are four pins here:

    SIG: Signal pin

    NC: No Connection

    3.3V : 'VCC' stands for Voltage Common Collector. We'll connect the VCC pin to 3.3V on the micro:bit

    GND: In electronics, we define a point in a circuit to be a kind of zero volts or 0V reference point, on which to base all other voltage measurements. This point is called ground or GND.

  • Voltage is the difference in potential between two points. As it is difficult to talk about voltage without a reference point, we need another point to compare it to.

Step 3 Connect module to breadboard

Step 4 Connect GND to GND

Step 5 Connect VCC to 3.3V

Step 6 Connect P0 to SIG

Step 7 Analog pins on micro:bit

  • In this guide, we have connected the potentiometer's signal pin to Pin 0 on the micro:bit But you can also connect it to other pins:

    Pin 0, 1 and 2 each are connected to a shared analog to digital converter or ADC for short. This means it can read a range of values apart from just '1' or '0'. This also means you can connect it to the potentiometer for analog signals.

    Pin 3, 4 and 10 can also be used for analog signals.

Step 8 Get analogue value

basic.forever(function () {
    basic.showNumber(pins.analogReadPin(AnalogPin.P0))
    basic.pause(1000)
})
  • Copy and paste this code into the Javascript interface.

  • By using the 'analog read pin... ' block, the micro:bit takes the analogue voltage from the potentiometer and converts it to a digital value between 0 and 1023.

Step 9 Upload the code to micro:bit

  • To upload the hex file to the micro:bit, first connect the micro:bit to your computer using a microUSB cable

  • Click on the Download button on the bottom left-hand corner of MakeCode editor

  • Find the hex file

  • Open up Finder on the MacOS or Explorer on Windows, and drag the hex file into MICROBIT under 'Devices' on the macOS.

  • The micro:bit will flash for a few seconds while the code uploads

Step 10 Get voltage value

let voltage = 0
let sensorVal = 0
let vcc = 0
vcc = 3.3
basic.forever(function () {
    sensorVal = pins.analogReadPin(AnalogPin.P0)
    voltage = sensorVal * (vcc / 1023)
    basic.showNumber(voltage)
    basic.pause(1000)
})
  • We can also convert this analogue value back to the voltage value.

    Copy and paste this code into the Javascript interface, replacing the existing code.

  • If you would like to use MakeCode blocks:

    Create a new variable and name it 'vcc', give it a value of '3.3' as we have connected the 'VCC' pin on the module to '3.3V' on the micro:bit.

    Then create another variable, 'sensorVal' and place an 'analog read pin P0' block in it.

    The analog value from Pin 0 will be placed in this variable.

    Finally, create a variable and name it 'voltage'. We'll then convert the sensor value to voltage.

    Show the voltage value with a 'show number ...' block.

  • The equivalent code in MakeCode blocks can be found by clicking on the 'Blocks' button up the top in the MakeCode editor.

For more information on the micro:bit and its features and pins, check out our guide, ''.

Meet the micro:bit