2

I use a Flame sensor (connect to pin0) to detect the fire and turn the pin1 to 1 when the sensor is nearby a candle, pin1 is connected to a LED, when sensor nearby a candle, the voltage from pin1 is 3.298V and the LED light up. I replace the LED with a small motor, the motor cannot be turned on and voltage is only 0.026V, the small motor can be turned on with 3V.

Below please find the code

basic.forever(() => {
if (pins.analogReadPin(AnalogPin.P0) < 20) {
    pins.digitalWritePin(DigitalPin.P1, 1)
} else {
    pins.digitalWritePin(DigitalPin.P1, 0)
}
})

How can I turn on a motor when a flame sensor is closed to a fire?

Best regards,

Kelvin

Kelvin
  • 577
  • 7
  • 25
  • 1
    It is not a software problem - a motor typically needs more current than a microcontroller can supply directly. https://electronics.stackexchange.com/ might be able to help you design one yourself (or understand the issues,) but there are several commercial products readily available. – gwaigh Feb 17 '18 at 16:45

1 Answers1

4

I read that the current limit on a micro:bit GPIO line is only 5mA and that the combined output for the GPIOs is 15mA. While this is just enough current to light an LED, this is not enough to power a motor. Power is current x voltage. One standard way to turn a motor or other device using a microcontroller is to connect the GPIO to the base (or the gate if using a field effect transistor, called a FET for short) of a transistor. A transistor can be thought of as a current amplifier. Applying a little current to the base allows a much larger current to then flow through the other two pins. The motor is powered through the transistor, not directly from the micro:bit. This allows a little current from the micro:bit to indirectly source a large current to the motor. The transistor will be connected to a power source, so the current to power the motor comes from the power source through the transistor, not through the micro:bit.

You should be able to find a suitable design with a little searching through your favorite search engine. It is against SO recommendations to embed links in answers, as links can change or disappear, but the words 'arduino motor controller circuit' came up with some images and links that should help you.

Good luck!

Oppy
  • 2,662
  • 16
  • 22
  • 1
    There are probably also specific motor driver extension boards made for the micro:bit, since this is a fairly common use-case (for example making a simple robot). – Sean Houlihane Feb 18 '18 at 15:05
  • Many thanks, oppy, I get your meaning but no idea to the FET, I heard from some engineer to use a relay, does FET do the same purpose as the relay? – Kelvin Feb 18 '18 at 15:30
  • A relay is another way to switch a device on or off with a microcontroller. Check the current required to operate the relay as some relays need a higher current than the microbit can supply. Using transistors is a standard way to turn a small motor on or off. Transistors are cheaper than relays and have no moving parts. Learning the basics of using transistors in this way is a useful skill. – Oppy Feb 18 '18 at 15:56