Writing code to turn power on/off to an Adafruit pin in the Maker App?

I have a student who is trying to connect a motor to the vout pin on his Adafruit Playground Express for a device project. Currently the motor spins whenever it’s connected to the pin, and he wants to put in a line of code that would activate it on command (either a button press on the Adafruit or the keyboard). My Adafruit skills aren’t spectacular, and I can’t figure it out either. Can someone help? Or if it’s not possible to code this in App Lab, suggest a workaround? Thanks!

Hi!
I have a student who is trying to connect a motor to the vout pin on his Adafruit Playground Express for a final device project. Currently the motor spins whenever it’s connected to the pin, and he wants to put in a line of code that would activate it on command (either a button press on the Adafruit or the keyboard). My Adafruit skills aren’t spectacular, and I can’t figure it out either. Can someone help? Or if it’s not possible to code this in App Lab, suggest a workaround? Thanks!

@lkohlert,

Can you possibly have him click on the share button and give us a link to his project so we can look at it? It’s a bit hard to troubleshoot without seeing the code he is using.

thanks!

Mike

1 Like

Hi @lkohlert,

I wanted to add my thoughts as this has come up in my class as well. I tried to research whether you could turn off the Vout or 3.3V pins. I don’t see any documentation in AppLab to that effect. Looking at MakeCode, there is no Vout pin that I can see that you can write to in the PIN section. When I researched the Arduino forums (and with my minimal background knowledge), it looks like the 3.3v and Vout pins put out more electricity than the other pins and can’t really be turned off directly. This has come up in my classes and we inferred you can’t turn them off because we have never found the blocks that point directly to them. Perhaps someone with more Arduino and/or hardware experience can add additional information but thought I would add this to the conversation.

Michelle

1 Like

Hello!

I 100% second everything @melynn said above - there’s no way to turn on or off the electrical current that comes out of the VOUT or 3.3V pins - they’re always on. However, there is a workaround, but it requires an extra component. If you happen to have a DC motor around, then maybe you also have a MOSFET transistor around too. Transistors are like electrical versions of a switch - when they receive an electrical signal, they activate another, usually stronger, electrical signal. This is a really solid, student-friendly video from our friends at Adafruit explaining how these components work. If you have one of these components, here’s how you could use it:

In the video, the MOSFET is being used to power an LED. In your example, you would use it to power the DC motor by connecting the drain pin from the MOSFET to the positive end of your motor.

In the video, a 555 timer is used to “pulse” the LED and is connected to the gate pin of the MOSFET. In your example, you would connect this to one of the output pins on the Circuit Playground (similar to the levels in this lesson). Then you could use a button on the circuit playground to control the current - when the button is pressed down, use a digitalWrite to send electricity to that pin (which will then activate the MOSFET, which will spin the motor). When the button is up, use digitalWrite to stop sending electricity to the pin (which will deactivate the MOSFET, which will stop the motor).

If you wanted to investigate more, try searching for examples or tutorials where students have used a transistor to power a motor. I don’t think you’ll find very many involving App Lab, but you might find some where folks have used other Circuit Playground or Arduino tools and they may inspire you & your student. If you find yourselves in over-your-heads with electrical terminology, you might watch more of the videos in the Adafruit series above - here’s their playlist on Youtube.

Caveat to all of this: the VOUT pin can send out a lot of electricity. This is why it’s good for motors, but it also means it can be kinda dangerous with your Circuit Playground. Make sure you & your students are being careful not to hook up the wires in such a way that they could damage the Circuit Playground, and always disconnect the device from it’s power source before adjusting wires.

Hope that helps!
Dan - Code.org Curriculum Writer
Amateur Electronics Enthusiast

3 Likes