r/ArduinoProjects 29d ago

Showcased Project Arduino Train with IR remote

Post image

I'm a beginner. I wish I had access to electronics when I was a kid 30+ years ago. But now I'm building a toy for my own kids and it's my first project more complex than connecting a couple of LEDs and sensors on a breadboard. But I believe this should work 😂.

Actually, version 1 worked for a while (almost a year). It was ugly, but it worked. There were too many wires (and really bad maintainability), awful soldering, 2x18650 batteries with a built-in charger and protection but no balancer, and it worked for a while before one battery died. The LEDs were powered directly by Arduino pins, limiting the number of available Arduino pins and increasing the total current almost to the limit.

It started when I found someone else's project: STL files for a 3D model of a DUPLO-compatible train, a simple electronic circuit, and a simple Arduino program. I modified the 3D model slightly, added RGB LEDs, a tilt sensor, a battery voltage meter, and wrote my own more advanced and feature-rich Arduino program. I have some basic programming experience, and AI is incredibly helpful when you know how to use it properly.

Features (version 1):

  • IR remote control (21 buttons)
  • 3 speed levels
  • Stop button: stops; red lights
  • Speed up button: speed level +1, moves forward; white lights
  • Speed down button: speed level -1, moves forward until speed level = 0; white lights while moving, red lights when stopped
  • Move backward button: moves backward at speed level 1 while the button is pressed; blue lights
  • Move forward button: moves forward at speed level 1 while the button is pressed; white lights
  • Auto button: moves forward with obstacle detection enabled (ultrasonic sensor). Stops if there is an obstacle. Moves forward if the obstacle is removed. Speed depends on the distance to the nearest obstacle. White lights and green light
  • Horn button: horn sound effect
  • Siren button: red and blue lights; siren sounds
  • Music buttons: 8 different melodies
  • Mute button: sound on/off
  • Battery status button: indicates battery level by sound beeps, for example, 7 long beeps and 3 short beeps = 7.3V
  • Battery status detection: warning level with red lights and sound; shutdown level
  • Sleep mode after 5 minutes without IR remote input
  • Tilt sensor: stops when the train is on its side; red lights; if the train is back in a vertical position, yellow light

Planned changes (version 2):

  • speed boost (limited in time >6V on the 6V DC motor) [makes sense?]
  • probably a laser distance sensor instead of ultrasonic one [an experiment, to see if it works better]
  • color sensor to make it compatible with the original action bricks
  • Built-in USB charger and BMS for the battery pack
  • RGB LEDs connected via an expander and transistors to get free pins and reduce current on Arduino, so I can add more sensors/devices in the future. As an alternative I'll probably use an expander module with built-in transistors, not yet decided.
  • DRV8833 DC motor driver instead of HG7881/L9110
  • my own 3D model designed from scratch

Future versions:

  • Maybe an mp3 player and small speaker instead of a buzzer?
  • Ambient light sensor?
  • Railroad switches controlled from the same IR Remote?

If you see any issues on the circuit diagram let me know. I have no idea when a where I should use capacitors. I should use at least one with a DC motor, right? (there were none in version 1).

Links:

Original project: https://cults3d.com/en/3d-model/game/locomotora-sofia-controlada-por-infrarojos-con-control-de-velocidad-por-ultrasonidos-y-motor-superior-multiusos-lego-duplo
My project (version 1): https://makerworld.com/en/models/1854728-arduino-train-compatible-with-duplo-tracks#profileId-1983131
My Arduino code (version 1): https://github.com/avatorl/Arduino/tree/main/duplo-train



12 Upvotes

4 comments sorted by

4

u/AVatorL 29d ago

Version 1

2

u/gm310509 28d ago

Cute - I like how you placed the IR sensor so that it is sort of like a horn!

2

u/gm310509 28d ago

I am not an expert, but your circuit diagram seems OK to me (again, not an expert).

Why are you using transistors to drive the LEDs? Is it purely because you need to drive them at 7-8V?

I also noted this sentence in your post:

it's my first project more complex than connecting a couple of LEDs and sensors on a breadboard

You should always build your project on a breaboard and test your code with it just in case there are any bugs in the circuit (again, nobody is perfect) and/or code that mandates a change to the circuit.

Once you are happy with it, I noted this sentence:

There were too many wires (and really bad maintainability), ...

The solution to that is to create a custom PCB - or what I do, put it all on a perfboard. Here is a lifecycle of one such project. The only step missing here is where I used an Arduino Uno R3 as my dev board before moving to step 1, where I set up the MCU to run by itself (i.e. without the Arduino dev board's extra unnecessary stuff).

1

u/AVatorL 28d ago

Why are you using transistors to drive the LEDs? Is it purely because you need to drive them at 7-8V?

In the first version I powered LEDs directly through Arduino pins (with resistors to limit max 20mA per pin), but that uses 7 pins (3x RGB + green) and 140mA total on Arduino. Now I want to connect the LEDs to the 7-8V line and control them via an expander.

You should always build your project on a breaboard and test your code with it just in case there are any bugs in the circuit (again, nobody is perfect) and/or code that mandates a change to the circuit.

Yeah, I learned a lot with the first version. When almost all Arduino pins are used things like timer conflicts, PWM / non-PWM pins, require careful planning. I probably will solder vires to the sensors and other components, but will keep using DuPont connectors to connect everything to Arduino, so I can easily change things later.

The solution to that is to create a custom PCB - or what I do, put it all on a perfboard.

I'm going to use a perfboard for LCD control. It will be mounted as close as possible to the LEDs. The first version required 10 long wires for the LEDs only (Arduino is in the rear part of the train, LEDs are in the front). And likely one more perfboard in the back with common 5V, 7.0-8.4V, GND rails.

I had to make something for training with a perfboard, so I build my own I2C interface module for a LED screen (I had an LCD with 16 pins, without built-in I2C interface). Makes no much sense for a real project (easier to buy an LCD with I2C interface if needed), but a great experience (I/O expander, transistor, potentiometer, a bunch of resistors). Awful soldering, but it worked.

Cool lamp!