arduino code nedded
HI, MY NAME IS THIAGO IKEDA AND HERE IS MY FIRST "ASK"
my english is VERY bad. well sorry anyway
FIRST i made this arduino tank (named ardutank) with ladyada motor shield
and i used library and worked
then i like WOW I SUPER GENIUS
so i buy an HC-SR04(ULTRASONIC SENSOR) to put with ARDUTANK, and i used the library too
but when i upload the code the ARDUTANK START make some wild noises.
i dont know what to do to ARDUTANK work with the sensor
obs: in first mode (with out ultrasonic sensor) one motor spins more fast than other, WHY?
the bouth motors are the same motor. but when i put to HIM to RUN HE make lil curve.
here is code WITH SENSOR
PLEASE IGNORE THE RELE AND BUZER NEXT TO SENSOR
// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!
#include
#include
#define TRIGGER_PIN 12
#define ECHO_PIN 13
int distance;
Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
// turn on motor
delay(10);
motor1.setSpeed(20);
motor2.setSpeed(20);
motor2.run(RELEASE);
motor1.run(RELEASE);
}
void loop() {
uint8_t i;
float cmMsec, inMsec;
long microsec = ultrasonic.timing();
cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);
inMsec = ultrasonic.convert(microsec, Ultrasonic::IN);
Serial.print("tick");
motor1.run(FORWARD);
motor2.run(FORWARD);
if(distance<10)
{
motor1.run(RELEASE);
motor2.run(RELEASE);
}
else
{
motor1.run(FORWARD);
motor2.run(FORWARD);
}
}
Comments
7 years ago
Are you using a separate power source to power the motors? I'm not too familiar with the ladyada motor shield but typically the motor power needs to be supplied from a separate source other than the one you use to power the other electronics such as the controller and sensors.
Answer 7 years ago
no, i'm using only one power supply,
when i make fist ARDUTANK *with out sensor* i use only one power supply to, has no ploblem and worked good,
Answer 7 years ago
I think you need two separate power supplies. One for your arduino/sensor, and one power supply for your motors. The motors can draw a lot of current and can sometimes cause a "brown out" that in turn can cause your electronics to do some funny stuff. Check out this user guide on how to use separate power supplies: http://www.ladyada.net/make/mshield/use.html (I think it involves removing that little yellow jumper and some other things).
Another thing that I noticed is that ladyada's motor controller shield is designed to power motors at 4.5-25 Volts DC. Those little Tamiya motors are made to run at 3V. Just something else to look into. Good luck, be careful, be safe.