Introduction: Control Motorcars With Ameba

It's always interesting to start a smart car project and make some simple movements about the car. it's fun to assemble the car and attach the needed wiring. It will all worth the effort when you see the car is moving as you desired.

Step 1: Needed Devices

The following devices are needed in this project:

  • Ameba Arduino - This Arduino compatible board can be found in eBay if you search for "Ameba Arduino"
  • L298N H-Bridge - The LN298 is a high voltage, high current, dual full-bridge motor driver which allows you to control the speed and direction of two motors.
  • 4-wheel motorcar - This motorcar can be found in Amazon or eBay. Just search for "Arduino 4wd robot car with speed encoder". This package should come with: 4 DC motors with speed encoders, 4 wheels, and car body. Assembly is required.

  • Battery - This is used to power up Ameba board & the driving motors

Step 2: Device Descriptions

We will have some simple descriptions about the devices used in this project.
1. L298N H-Bridge: Typical L298N modules in market contains the pins as shown in the above picture.

  • +12V: Power supply for L298N. Common acceptable voltage range: +6V~+12V, +5V~+12V, +7V~+12V, >=+12V
  • GND: Connect to GND of power.
  • +5V: If connected power supply of L298N is larger than +7V, the +5V pin can supply power to other components (EX. Ameba). There is a jumper above +12V, connect the Jumper to provide +5V.
  • OUT1, OUT2: The output pins to control the first motors set (control at most 2 motors at a time).
  • OUT3, OUT4: The output pins to control the second motors set.
  • ENA, IN1, IN2: Input pins to control the output to OUT1 and OUT2. ENA is used to control the rotation speed of the first set of motors (usually via PWM). IN1&IN2 are used to control the rotation direction of the first motors set. The is same to ENB, IN3 and IN4e

2. DC motors: Ordinary DC motors uses two wires to control the rotation. As shown in the figure above, when we connect L to GND, R to 3V3, the motor starts to rotate. If we connect L to 3V3, R to GND, the motor starts to rotate in the opposite direction. If we change 3V3 to 5V, the motor would rotate in a higher speed. Please refer to spec to find the maximum acceptable current of the motor.

Step 3: Wiring

The detail wiring is shown in the above picture:

ENA:8, IN1:9, IN2:10, IN3:11, IN4:12, ENB:13

As indicated in the second picture, you can also jump connect ENA & ENB pins with 5V pins and make them always on so you can save two wiring (8 & 13). Please note:

  • We connect Ameba 5V to L298N +12V to supply power. However, not every L298N accepts 5V power supply, if this does not work, please connect L298N +12V to other power supply (e.g., +12V) and use L298N +5V to supply power to Ameba.
  • The correct wiring of the motor depend on each model (may be opposite). Please first run some test program mentioned in the next section, make sure it runs correctly before assembling the motorcar.

Step 4: Code Reference

Please download AmebaMotors library version 1.0.3: https://github.com/Ameba8195/Arduino/raw/master/l...

And follow the tutorial to install the library to Ameba: https://www.arduino.cc/en/Guide/Libraries#toc4

In this example, we use Ameba to control the basic move of a motorcar. Open the example, “Files” -> “Examples” -> “AmebaMotors” -> “car2wd_digit_control”.

Compile and upload the “car2wd_digital_control” example to Ameba. In this program, we make the motorcar to perform following moves: Move forward 2s => Stop 1s => Move backward 2s => Stop 1s => Rotate in clockwise direction 2s => Stop 1s => Rotate in counterclockwise direction 2s => Stop 1s => Move forward and turn right then turn left => Stop 1s => Move forward and turn left then turn right => Stop 1s.

Everytime you modify your program, please remember to unplug the power of L298N to avoid the motor running unexpectedly. Connect Ameba to power, upload the program, and then connect L298N to power when you are going to test the proram.

Now we will describe the control of the motorcar in the following:

  • Speed: We control ENA and ENB via PWM, frequency is fixed at 200 (resolution=256).
  • Move Forward: IN1: High, IN2: Low, IN3: High, IN4: Low
  • Move Backward: IN1: Low, IN2: High, IN3: Low, IN4: High
  • Clockwise Rotation IN1: High, IN2: Low, IN3: Low, IN4: High
  • Counterclockwise Rotation IN1: Low, IN2: High, IN3: High, IN4: Low

Please refer to the demo video for the final result.

Comments

About This Instructable

321views

10favorites

License:

More by joeyzh:Use MQTT to Upload and Listen to AmebaUsing Amazon Alexa to control Ameba ArduinoAmeba Arduino Getting Information From Internet
Add instructable to: