Toy Train and Android

Published

Introduction: Toy Train and Android

About: Hello. Main name is Steve. I'm designer and former engineer from Moscow.

Children are difficult to tear from their tablets. I propose to combine their passion for games and real toys. Most likely, you already have a box with the children's railway, and this instruction will allow him to drive the locomotive from his favorite tablet. For this, only three details are needed for Arduino or Arduino Starter Kit. The idea is simple, this is the classic robot Arduino placed in a toy train. For this, I wrote a fun application for Android.

Step 1: How Paste Arduino Modules to the Train

It is difficult to place the parts directly into the locomotive, and replacing the batteries is also a problem. I propose such a solution. I repeat, the scheme can be any. Other variants on kids.arduinorailwaycontrol.com

Step 2: Sketch and Application

The principle is the same as in my other project. The application sends simple commands of two characters, the sketch converts them into physical signals on the I/O pins of Arduino. You can change it to your own design.

#define L9110S_AIA 10
#define L9110S_AIB 9 #define LED 3

String inputString = ""; boolean stringComplete = false; boolean directionForward, directionCurrent; int locoSpeed; void setup() { pinMode(L9110S_AIA, OUTPUT); pinMode(L9110S_AIB, OUTPUT); pinMode(LED, OUTPUT);

digitalWrite(L9110S_AIA, LOW); digitalWrite(L9110S_AIB, LOW);

Serial.begin(9600); inputString.reserve(16); Serial.println("Connected"); }

void loop() { if (stringComplete) { // TROTTLE if (inputString.charAt(0) =='t') { if (inputString.charAt(1) =='0') locoSpeed = 0; // Stop if (inputString.charAt(1) =='1') locoSpeed = 80; if (inputString.charAt(1) =='2') locoSpeed = 120; if (inputString.charAt(1) =='3') locoSpeed = 160; if (inputString.charAt(1) =='4') locoSpeed = 200; if (inputString.charAt(1) =='5') locoSpeed = 250; } // MOVE DIRECTION if (inputString.charAt(0) =='d') { if (inputString.charAt(1) =='f') directionForward = true; if (inputString.charAt(1) =='r') directionForward = false; if (inputString.charAt(1) =='s') { digitalWrite(L9110S_AIA, LOW); digitalWrite(L9110S_AIB, LOW); locoSpeed = 0; delay(200); } } // LIGHT if (inputString.charAt(0) =='J') { if (inputString.charAt(1) =='a') digitalWrite(LED, HIGH); if (inputString.charAt(1) =='b') digitalWrite(LED, LOW); }

inputString = ""; stringComplete = false; }

// OPERATION // CHECK SHOCKING CHANGE DIRECTION if (directionForward != directionCurrent) { digitalWrite(L9110S_AIA, LOW); digitalWrite(L9110S_AIB, LOW); locoSpeed = 0; delay(500); }

// SPEED PWM else { if (directionForward == true) { analogWrite(L9110S_AIA, 0); analogWrite(L9110S_AIB, locoSpeed); } else { analogWrite(L9110S_AIA, locoSpeed); analogWrite(L9110S_AIB, 0); } }

// DIRECTION ASSIGNED directionCurrent = directionForward; }

void serialEvent() { while (Serial.available()) { char inChar = (char)Serial.read(); inputString += inChar; if (inChar == 'z') { stringComplete = true; } } }

Step 3: Play

Share

    Recommendations

    • Woodworking Contest

      Woodworking Contest
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest
    • Casting Contest

      Casting Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    Comments