element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
The World in Motion
  • Challenges & Projects
  • Project14
  • The World in Motion
  • More
  • Cancel
The World in Motion
Blog Pulse Width Modulation a Speed Equalizer(6): The locomotive has arrived in the final post
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join The World in Motion to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: colporteur
  • Date Created: 8 Aug 2022 9:34 PM Date Created
  • Views 35230 views
  • Likes 7 likes
  • Comments 5 comments
  • worldinmotionch
  • pwm
  • motors
Related
Recommended

Pulse Width Modulation a Speed Equalizer(6): The locomotive has arrived in the final post

colporteur
colporteur
8 Aug 2022

Two videos to demonstrate success.

The first video shows the locomotive powered by the L298N module driven using PWM set to a constant speed.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

The second video shows the locomotive increasing and decreasing speed using PWM.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

imageimage

If you are joining this blog post late, here is a summary of my entry for Project 14 Electronics & Design Projects, World in Motion.

My hobby is creating animation in model railroad layouts. My passion is writing. I was successful in controlling the direction and speed of a HO scale model locomotive using PWM. Pulse width modulation (PWM) is a modulation technique that generates variable-width pulses that can be used to control the amplitude of an analog signal. The average value of the analog signal fed to the load can be controlled by adjusting the pulse width of the signal being delivered to a controller. The controller output is on more of the time for longer pulse width and off more of the time for short pulse width.

The project uses an Arduino Nano (knock-off), an L298N power module and the Andrea Lombardo/L298N Arduino Library in Arduino code. The setup uses a DC system power supply feeding the L298N. The Arduino codes deliver PWM pulses to the L289N module to control the speed of the motor. The exercise is part of a bigger project I am involved in to automate a full-scale model layout.

I wrote two sketches to control the motor for this entry. One sketch drives the motor at a constant speed depending on the PWM variable setting. The other sketch ramps up the motor speed and ramps down the motor speed. 

The L296 Library supports a range of values from 0-255. A value of 160-180 was the minimum value to get a locomotive to move. A number of different manufactured locomotives were tested. The initial test revealed a motor whine problem using the default PWM signals. The default frequency for PWM is 490Hz or 980Hz depending on the Arduino pin used. Trying to resolve the problem I ran into an issue with pin functionality from using incorrect documentation I found in a google search. Suggestions for the E14 community put me on track to solve the problem.

The final test for this project was running scale speed tests. A device used to measure scale speed was used to determine values that would provide the correct speeds for particular functions. Train guys/girls don't take kindly to whipping a locomotive down the track at max speed. Derailments and damage are usually the results. Their layouts are about realism. A value of 200 provided a scale speed of 51MPH sufficient to have the wind flowing through your hair.

I have to confess the speed measuring device became a squirrel moment for me.  With a few IR diodes and Arduino and some code, you should be able to determine speed, don't you think? At $250 for the commercial unit I thought it was pricey! Me thinks, I might be working on another World in Motion entry in a scaled speed measurement device. We'll see.

If you are looking for more details on this entry have a look at the blog posts. They are numbered so I could keep them in sequence. Thanks for the opportunity to participate.

  • Sign in to reply
  • colporteur
    colporteur over 2 years ago in reply to robogary

    If the truth be told I've got two working prototypes. One using an Arduino Nano and the other using a Raspberry Pi, The Arduino project displays data on the serial monitor and the Pi at the command prompt. 

    I used two IR sensors. One for start timer and the other for stop timer. With the distance between the sensors a constant, I was able to calculate speed. Weel my calculation match a scale calculator found on a model railroad site.

    The missus had me tear the patio up because she didn't like the grass growing up between the block. The fool I am, I should have used a chemical. No, I have to do it manually. Now I putting down stones instead of code to display values.

    The railroad guys would like me to build it into the track so they can take it to a train show and display the results on a giant screen. They don't bug me when I suggest go talk to my wife and get out of the patio project:)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • colporteur
    colporteur over 2 years ago in reply to Jan Cumps

    I tried from a different computer JC and I get a working link. If CS is monitoring he might be able to shed some light.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 2 years ago

    One immage is missing:
    image

    This is the error the forum returns: Bad Request

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • BigG
    BigG over 2 years ago

    Wow this is impressive. Well done on the work you've done so far. I worked on Automated Train Operation systems project back in the 1990's. Getting trains to stop in the right place accurately and consistently was quite a challenge. Then it was how to incorporate the train operation with the new moving block signalling system.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • robogary
    robogary over 2 years ago

    You are right. A single IR diode or hall effect sensor at a specific place could give you an easy display for travel time for one loop around the track, and calculate that as a real or scaled trip time. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube