Adafruit Motor Shield & Funduino
by ALP Electronic Innovation in Circuits > Microcontrollers
24579 Views, 28 Favorites, 0 Comments
Adafruit Motor Shield & Funduino



Download our FREE Arduino Project Code
Attach Funduino and Motor Shield together.
IDE

Open the Arduino IDE then click Tools / Board / Arduino Duemilanove w/ AT328
Upload the Sketch
/*
Upload the code below, make sure that you plug the USB cable and choose the right Serial Port.
Test the (2) DC motors to move Forward and Backward.
*/
#include
int i;
// DC motor on M1
AF_DCMotor motor(1);
// DC motor on M2
AF_DCMotor motor2(2);
void setup() {
// Turn ON DC MOTOR #1
motor.setSpeed(200);
motor.run(RELEASE);
// TURN ON DC MOTOR #2
motor2.setSpeed(200);
motor2.run(RELEASE);
}
void loop() {
motor.run(FORWARD);
motor2.run(FORWARD);
for (i=0; i<255; i++) {
motor.setSpeed(i);
motor2.setSpeed(i);
delay(10);
}
motor.run(BACKWARD);
motor2.run(BACKWARD);
for (i=0; i<255; i++) {
motor.setSpeed(i);
motor2.setSpeed(i);
delay(10);
}
}
// code ends here
Bluetooth Module

You can also attach a Bluetooth module to control the motor using your Android phone.
Upload Sketch for Bluetooth

/* Use your Android phone to control your motor FORWARD / REVERSE / LEFT / RIGHT
Upload code below.
*/
#include
char val; // Variable to receive data from the serial port
// DC motor on M1
AF_DCMotor motor(1);
// DC motor on M2
AF_DCMotor motor2(2);
int i;
void setup() {
Serial.begin(115200);
// turn on motor #1
motor.setSpeed(200);
motor.run(RELEASE);
// turn on motor #2
motor2.setSpeed(200);
motor2.run(RELEASE);
}
// Move FORWARD
void go_forward(){
motor.run(FORWARD);
motor2.run(FORWARD);
for (i=0; i<255; i++) {
motor.setSpeed(i);
motor2.setSpeed(i);
}
}
// Move REVERSE
void go_reverse(){
motor.run(BACKWARD);
motor2.run(BACKWARD);
for (i=0; i<255; i++) {
motor.setSpeed(i);
motor2.setSpeed(i);
}
}
// Move LEFT
void go_left(){
motor.run(FORWARD);
for (i=0; i<255; i++) {
motor.setSpeed(i);
}
}
// Move RIGHT
void go_right(){
motor2.run(FORWARD);
for (i=0; i<255; i++) {
motor2.setSpeed(i);
}
}
// Read serial port and perform command
void performCommand() {
if (Serial.available()) {
val = Serial.read();
}
if (val == 'f') { // Forward
go_forward();
// } else if (val == 'z') { // Stop Forward
// stop_go_forward();
} else if (val == 'b') { // Reverse
go_reverse();
} else if (val == 'y') { // Stop Reverse
// stop_go_reverse();
} else if (val == 'l') { // Right
go_right();
} else if (val == 'r') { // Left
go_left();
// } else if (val == 't') { // Stop Car using Turbo function
// stop_car();
}
}
void loop() {
performCommand();
}
// code ends here
Android App

Use the "Smart Home with Voice command" app to test your Bluetooth module.
Google PlayStore.
WarBot
You may also want to build