I’m trying to control a DC motor thru a mobile app with a range slider, but I cannot get it to work. I’m wondering if someone could look over the code below and tell me if it should work or not. The main.ino verifies correctly, so I’m guessing it’s in the mobile app?..
BTW, I didn’t write this code, it’s an open source project. I can’t write code, therefore I can’t find the problem.
I could only find 2 references to the motor in the mobile app. One is in ‘device.html’ and the other is in file ‘Controller.js’. Perhaps the problem is with the range slider itself?
I’m thinking it would most likely be in the Controller.js. I’ve got my breadboard set up exactly as the schematic in the project shows. I’d love some expert opinions so I could get on with my project.
Thanks!
What does that mean? Did you try using the console (or the CLI if you have that installed) to send a value to your function? If so, what was the result.
BTW, you should be returning an int from your setPower function.
You could do with some filtering on your Photon supply as I’d suspect the motor to introduce a considerable amount of noise on the power rails.
With inductive loads - like a motor - you should also add a flyback diode to prevent damaging the Photon via the kickback on the supply rails.
With this in general, what does the Photon do when you start up first and then when you send the first control command (e.g. 128 = 50% duty cycle)?
Thanks for the suggestion. I do remember reading somewhere about using a flyback diode. I don’t have one on hand right now, but I’m gonna order some.
If I’m using your example the right way (you’re dealing with a real newbie at this IoT stuff), this is what it says:
but the motor isn’t responding to nothing.
Maybe your transistor doesn’t switch properly.
To see whether your pin switches correctly or not you could add an LED (with a current limiting resistor) from D0 to GND.
Or even better if you’ve got an oscilloscope.
Well, I think I’m finally starting to make some progress. I now believe the problem is in the hardware. I was using a photon soldered to a Neopixel ring for the light shows in the sketch. Then I ordered another photon & Neopixel ring, this time not soldering them together, and I can get the pump to work. It’s not working exactly as it should; I can only start and stop it, I can’t adjust the speed. Any thoughts on that?
[quote=“slarja, post:13, topic:32984, full:true”]I can only start and stop it, I can’t adjust the speed. Any thoughts on that?
[/quote]
Are you certain your transistor is switching fast enough? I’ve ditched all trannies for Powermosfets in most of my applications. Also, you really do want that fly back diode, you may have damaged the tranny already.