irl540n controlling dc motor

Python code not working: Programming a motor to turn on using a switch (Raspberry Pi)

Ask Question

Asked today

Modified today

Viewed 22 times


HELP! Ideally within the next 24hrs PLEASE!!!!!

We have a simple circuit where we have a button, that when pressed, starts a motor that needs to run at a certain speed for a certain amount of time. (The circuit also involves an infrared sensor that is meant to be counting the wheel spokes as the wheel rotates which will be used to stop the motor after a certain number of spokes however we have given up incorporating this element as we found it too difficult – However, any help on how to do this is greatly appreciated)

Attached are our attempts at coding and the circuit diagram. Any help on coding is massively appreciated. We have an exhibition in a couple of days and can’t get it to work.

From a group of mechanical engineering students with zero coding experience Details: Raspberry Pi used, Python used for programming, 12V NiMH rechargeable battery, 84rpm DC motor.




EditFollowClose 2Flag

edited 12 hours ago

asked 13 hours ago

user avatar


1122 bronze badges

 New contributor

  • 1We need text listings of the code in the question. Not photos. Also explain in your question what is not working as you expect. – joan 13 hours ago
  • group of female mechanical engineering students … female is irrelevant … that should say group of mechanical engineering students – jsotola 12 hours ago 
  • please, no screenshots of text … copy and paste the text itself – jsotola 12 hours ago
  • It is not clear which N-channel power MOSFET you are using. One tip is not to use the very popular NRF540N – Use NRL540N instead. Reference: Power MOSFET Driving Big Motor Problem – Asked 3 years, 3 months ago Modified 1 year, 9 months ago Viewed 928 times raspberrypi.stackexchange.com/questions/94031/…. – tlfong01 3 hours ago  
  • Troubleshooting tip. As you can see in the schematic diagram of my MOSFET driving motor test referred above. I am using a (10k + status LED) for debugging a short python program which just blinks the LED. You can first test if the LED blinks (without connecting the motor). Only after your Blinky program works, then you connect the motor. Good luck and have anive weekend. Cheers. – tlfong01 3 hours ago  
  • (1) I have made public my CircuitLab schematic of IRL540N controlling motor. CircuitLab is the official, free, schematic drawing tool for this Rpi and EE StackExchange. So you can open my public file and edit it, to save some time. But the learning curve of CircuitLab is steep for mechanical enggr students. (2) The URL of my public CircuitLab file is: circuitlab.com/circuit/n7764g3wm5d2/irl540n_motor_2022jun0401. Just click the url and Rpi.SE will start CircuitLab and open the file. (3) I have also cut and pasted a jpg file in Imgur for y

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.