Three Wheeled Cart

by CobramCat in Circuits > Arduino

214 Views, 5 Favorites, 0 Comments

Three Wheeled Cart

DSCF0981.JPG

From my teens I’ve always had an interest in electronics and computers. While I have written a range of programs at a low-level in various Basics, Pascal, and built an Excel Workbook supported by Visual Basic, this project is the outcome of attempting to meet the interests of two granddaughters.

The younger girl was introduced to “Scratch” in Primary School whilst the elder was captivated by a Robotic arm seen as a demo at a PT evening at Secondary School.

Attempting to follow their interests I tried to stay in front of them by researching Arduino, “Scratch” and then App Inventor. They have possibly lost interest now, at least one.

I must acknowledge two persons whose coding has been of significant assistance. I have taken from Martyn Currey’s Bluetooth app (http://www.martyncurrey.com/android-mit-app-inventor-auto-connect-to-bluetooth/) at App Inventor what I needed. Then too, I redesigned my Arduino sketch using Marcelo Moraes’ sketch as a guide (I regret that I don’t recall his project and I cannot be confident if this Brazilian: https://github.com/Arduinobymyself/ is that person; my apologies).

Before beginning to explain this project, I want to draw attention to the AFMotor.h library with reference to DC motors. Although I can find no support my understanding is that you must declare the type of motor and the parameters to be accepted. What appears below as bold is necessary to match the library while the default is user defined.

In this first instance the motor is defined by its number [1 to 4] to match the Shield. In the void loop() or further functions, the motor can only obey a run command of one of ‘FORWARD/BACKWARD/RELEASE’ when passed to the program. There is no parameter to accept setSpeed and so such commands are ignored.

#include <AFMotor.h>

AF_DCMotor motorRight(1);

AF_DCMotor motorLeft(2);

motorRight.setSpeed(80); //Ignored

motorLeft.setSpeed(80); //Ignored

motorRight.run(FORWARD/BACKWARD/RELEASE);

motorLeft.run(FORWARD/BACKWARD/RELEASE);

In this second case the motor has its position declared as well as a PWM_Rate. When that is defined the library contains a function where “setSpeed” is recognised – note the very exact spelling of “setSpeed”, capital ‘S’ in the middle! Here the integers within the () may be programmed with variables, eg supposing spd=255 and you want a quarter, the () may appear as (spd/4) instead of 255, 100 or 0. I’ll leave that for anyone wanting to follow that further but the following has been used in my sketch.

#include <AFMotor.h>

AF_DCMotor motorRight(1,MOTOR12_64KHZ); // The last parameter may differ, check the library documentation

AF_DCMotor motorLeft(2,MOTOR12_64KHZ);

motorRight.setSpeed(255);

motorLeft.setSpeed(50);

motorRight.run(FORWARD/BACKWARD/RELEASE);

motorLeft.run(FORWARD/BACKWARD/RELEASE);

The above awareness has been important to me so I’ve included it should it assist others.

This project is very much a toy.

Supplies

Hardware:

1 UNO/Geniuno Arduino or generic board (mine is Geekcreit)

1 Motorshield DK Electronics

1 HC-06 Bluetooth module

2 DC motors

2 wheels (match the motor axles)

1 castor wheel

1 9v battery

1 9v battery clip

A set of pin headers

A range of connective wires

c. 12-15cm x 2mm x 10mm strap of aluminium

Plastic container (14cm x 10cm x 7cm)

Cost: I bought everything on-line as multiples (except for the castor, container, aluminium strap and ancillary screws). I expect that I’d have outlaid about $30-$40 AU without battery.

Software Requirements:

Arduino IDE software https://www.arduino.cc/en/software

Arduino sketch ThreeWheels.ino

A Bluetooth control App Direction_Control.apk

[You can find it at https://gallery.appinventor.mit.edu/ ]

Potential software patch (My Geekcreit board initially needed that for UNO compatibility)

http://www.wch.cn/download/CH341SER_EXE.html Patch

https://www.instructables.com/How-to-fix-bad-Chin... Instructions to use patch

Chassis and Electrical Preparations

DSCF0976.JPG
DSCF0977.JPG
DSCF0975.JPG

The Project:

A base philosophy of the Arduino technology is to avoid the need to solder. Unfortunately that must happen on two counts.

As the motors came without leads, I had to solder them.

Then too, when the motor shield is mounted on the main board one cannot access its pins. The HC-06 needs connection to the RX and TX pins (0 and 1). There are holes adjacent the pinouts on my Geekcreit board (I have another that doesn’t have them). As I needed a VCC (5V) and GND connection for the HC-06 a 4-pin header strip was solder to the 5V-GND-GND-9V connections on the other side of the board. [Ignore the pin headers attached to 2-7 on that board – I have plans for them later; they were added after I soldered my RX-TX connections on the board below].

The Vehicle:

For the wheels and motors, determine and mark on both sides of your container where the axle of the motor will protrude. Then too the holes to secure the motor to the container. Drill those appropriately giving the axle clearance of the container for unimpeded rotation.

The aluminium needs a hole at one end to mount the castor wheel and two at the other end to secure it to the base of the container. Bend the aluminium into a ‘gooseneck’ so that the castor axle is as vertical as possible for quick response when turning.

Assemble the motors, castors and wheels.

Electricals

Cart_Layout.gif
DSCF0964.JPG

Lock the motor shield into the main board.

On the Motor shield, connect the leads of the right-side motor to the M1 bank pair of terminals and the left side pair to M2; not that the middle connection of that bank of 5 is GND. Don’t worry at this point if either motor is connected correctly, that can be easily fixed later.

Connect the RX lead from the main board to the TX terminal of the HC-06 and the TX lead to the RX of the HC-06. Make the VCC and GND connections also (my 4-pin header bank).

Connect the 9V battery clip to the dual terminal blue bank of the motor shield ensuring that the black lead is connected to the right, GND.

That completes the circuit.

At this point open the Arduino IDE and load the sketch. Connect your computer to the microcontroller board with your USB cable. Now … before you upload the sketch to the board disconnect the RX and TX from the Bluetooth module to avoid an upload error!!!

Once uploaded that connection can be restored.

Downloads

The App

Arduino_App.gif
DSCF0970.JPG

Now before install the App to your phone or tablet please note carefully ... I could not upload the App as an 'apk' file so I renamed it as 'txt'. Before installing the App rename it as Direction_Control.apk. I cannot find how to advise in finding this in the Gallery at AppInventor - sorry.

Add a 9V battery to your circuit and open the App. Open the App and seek to make a connection. It will look for any available Bluetooth devices. You are looking for one that has HC-06 in the list. (I can’t recall if I had to add a code – 1234 or 0000 – when I initially set this up).

With the Bluetooth connection made enjoy the toy.

Explanation of the arrows:

The Fwd, Bwd and Stop are self-explanatory. The other forward and backward arrows set a smooth curved path. The Left and Right arrows however create a sharp turn, which unchecked, allowing the vehicle to rotate closely around a spot.

Missing: I would like to have added an ON/OFF switch, external to the 9V battery line, so that I did would not have to keep opening my container case to disconnect; that will come later.

As to the header pins mentioned much earlier, it is my intention to later add in an HR_SR04 ultrasound module at some point so that forward motion, at least, is halted should there be an obstacle immediately ahead.