Introduction: DIY - Control Off-road Lego Car Through Internet (IoT) - Part 2 (Front Wheel/Steering)

About: interest in iot, automation, technology. today still work as sofware engineer in largest Telco Company in Indonesia

Well previous part (part 1) we were discussing about how we control dc motor on Lego off-road car. Of course we wont let lego car move without any direction. So this topic, we are going to steer front wheel using custom servo motor. Let's drive it and have fun :D

Step 1: Parts Required

Hardware parts :

1. Solder, its tin, its iron stand

2. Digital Multimeter

3. Wire and pin header

4. Lego Car 42037 (you may use any lego off-road car as long as it has the similar way to make front-steer turn right or left)

5. Servo Motor S3003

6. Glue

7. Raspberry Pi 3B (you may use any raspberry pi as long as it connects to internet) and its' case

8. Lipoly battery 3S - 11.1 V 2200mAh

9. 2 x UBEC 5V (I suggest to use separate ubec, 1 dedicated ubec for Raspi only, and 1 for servo motor)

10. Half breadboard 400 holes

11. Jumper Wire

12. 2 x 25cm Cable Tie

Software required :

1. AWS EC2

2. AWS IoT

3. NodeJs

Step 2: Make Servo Motor Fit Into Lego Car

Okay, it's a little bit tricky and should be carefully because servo motor is not default set from Lego manufacture. So enjoy the process how make it fit into lego car. I choose to custom the servo motor because it is much cheaper (Lego servo motor is almost IDR 500.000,00 or around 36$ and servo motor S3003 is only around IDR 100.000,00 or 7$) and the most important thing, it works really well. Please see attachment of servo motor S3003 data sheet. Let's jump to the list-to-do (please see the figure) :

1. Pour the glue on the servo motor

2. Attach 12-teeth-lego-gear to the servo motor

3. Plug Lego stick into the lego gear

4. Adjust servo motor on neutral condition (90 degree) and ensure it is on straight wheel (a little bit jump to code, we ensure PWM signal must be 7.5% in range (0-255) so we get around 7.5% * 255 = 19)

5. Make servo motor seat tight so there is no left space around

Step 3: Servo Motor Wiring

On mini breadboard 400 holes :

2 UBEC 3A are connected to main power source (Lipo Battery 3S), one is fully dedicated to power Raspi up and another for other motors (servo motor S3003)

On lego car :

Attach battery on lego car and put on top of it the Raspi with wiring connected to its pin. And then, 3rd layer will be placed by the half breadboard. Lastly please be careful to connect each wire with the correct one, never ever miss position + or - in a opposite way or short circuit will happen (it may burn out your wire or damaged your UBEC, at worst maybe your Raspi.)

On Servo S3003 :

3 wires come up with servo S3003 with the following configuration :

- red = positive (4,8-6v), connect to 5.3V on breadboard

- black = ground, connect to ground on breadboard

- white = signal (to handle its rotating degree), so connect to raspi pin (please see the figure)

Step 4: Write Simple Code and It's Running

Well, finally we are on the easiest part, we just have to continue from previous code so we wont discuss it from the scratch (please take a look previous code here).

-- AWS EC2 NodeJs API --

no additional code since we added it at previous section, just to review please take a look this code. Y could be either up (move forward) or down (move backward), X could be either left (turn left) or right (turn right).

// Motor Direction server.route({ method: 'GET', path: '/api/direction/{x}/{y}', handler: function (request, reply) { var test = {"state":{"desired":{ "x":encodeURIComponent(request.params.x), "y":encodeURIComponent(request.params.y) }}}; thingShadows.update(thingName,test); reply(test); } });

-- RasPI NodeJs Application --

Overall we initiate the servo motor pin (on BCM Mode) and attach the code inside thingShadow on delta function.

<p>// Initiate Front Servo Motor<br>

var Gpio = require('pigpio').Gpio,
  frontmotor = new Gpio(12, {mode: Gpio.OUTPUT}),
  dutyCycle = 0;
</p><p>// Inside delta function for Front Servo Motor<br>    

        frontmotor.pwmWrite(18); // 
    }else if(stateObject.state.x=='left'){
    }else if(stateObject.state.x=='right'){

everything has been set up now let's play with much fun :D :D :D