Mdd10A problem (please help me)

Autonomous Robot, Manual Robot, DC Motor Driver, Stepper Motor Driver, Servo, Multi PWM chip.....

Mdd10A problem (please help me)

Postby mnflife01 » Fri Mar 01, 2019 11:11 am

Hi im a noob in this kind of thing,
all i want to do is replace my kid old rc car controller and receiver with arduino uno and L298 dual bridge + bluetooth .
the setup that I copy from internet is working, however l298 didnt supply enough current for my motor.
so, I ended up buying mdd10a to replace L298 hoping that it would work like l298.
but i was wrong, only going forward and left are working. :(


Here is the code

/*
* Created by Vasilakis Michalis // 12-12-2014 ver.1
* Project: Control RC Car via Bluetooth with Android Smartphone
* http://www.ardumotive.com/arduino-car
* More information at www.ardumotive.com
*/

//mdd10A Connection
const int motorA1 = 3; // pwm_1
const int motorA2 = 4; // dir_1
const int motorB1 = 7; // dir_2
const int motorB2 = 6; // pwm_2
//Leds connected to Arduino UNO Pin 12
const int lights = 12;
//Buzzer / Speaker to Arduino UNO Pin 3
const int buzzer = 3 ;
//Bluetooth (HC-06 JY-MCU) State pin on pin 2 of Arduino
const int BTState = 2;
//Calculate Battery Level
const float maxBattery = 8.0;// Change value to your max battery voltage level!
int perVolt; // Percentage variable
float voltage = 0.0; // Read battery voltage
int level;
// Use it to make a delay... without delay() function!
long previousMillis = -1000*10;// -1000*10=-10sec. to read the first value. If you use 0 then you will take the first value after 10sec.
long interval = 1000*10; // interval at which to read battery voltage, change it if you want! (10*1000=10sec)
unsigned long currentMillis; //unsigned long currentMillis;
//Useful Variables
int i=0;
int j=0;
int state;
int vSpeed=200; // Default speed, from 0 to 255

void setup() {
// Set pins as outputs:
pinMode(motorA1, OUTPUT);
pinMode(motorA2, OUTPUT);
pinMode(motorB1, OUTPUT);
pinMode(motorB2, OUTPUT);
pinMode(lights, OUTPUT);
pinMode(BTState, INPUT);
// Initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

void loop() {
//Stop car when connection lost or bluetooth disconnected
if(digitalRead(BTState)==LOW) { state='S'; }

//Save income data to variable 'state'
if(Serial.available() > 0){
state = Serial.read();
}

//Change speed if state is equal from 0 to 4. Values must be from 0 to 255 (PWM)
if (state == '0'){
vSpeed=0;}
else if (state == '1'){
vSpeed=100;}
else if (state == '2'){
vSpeed=180;}
else if (state == '3'){
vSpeed=200;}
else if (state == '4'){
vSpeed=255;}

/***********************Forward****************************/
//If state is equal with letter 'F', car will go forward!
if (state == 'F') {
digitalWrite(motorA1, vSpeed); analogWrite(motorA2, 0);
analogWrite(motorB1, 0); digitalWrite(motorB2, 0);
}
/**********************Forward Left************************/
//If state is equal with letter 'G', car will go forward left
else if (state == 'G') {
digitalWrite(motorA1, vSpeed); analogWrite(motorA2, 0);
analogWrite(motorB1, 200); digitalWrite(motorB2, 0);
}
/**********************Forward Right************************/
//If state is equal with letter 'I', car will go forward right
else if (state == 'I') {
digitalWrite(motorA1, vSpeed); analogWrite(motorA2, 0);
analogWrite(motorB1, 0); digitalWrite(motorB2, 200);
}
/***********************Backward****************************/
//If state is equal with letter 'B', car will go backward
else if (state == 'B') {
digitalWrite(motorA1, 0); analogWrite(motorA2, vSpeed);
analogWrite(motorB1, 0); digitalWrite(motorB2, 0);
}
/**********************Backward Left************************/
//If state is equal with letter 'H', car will go backward left
else if (state == 'H') {
digitalWrite(motorA1, 0); analogWrite(motorA2, vSpeed);
analogWrite(motorB1, 200); digitalWrite(motorB2, 0);
}
/**********************Backward Right************************/
//If state is equal with letter 'J', car will go backward right
else if (state == 'J') {
digitalWrite(motorA1, 0); analogWrite(motorA2, vSpeed);
analogWrite(motorB1, 0); digitalWrite(motorB2, 200);
}
/***************************Left*****************************/
//If state is equal with letter 'L', wheels will turn left
else if (state == 'L') {
digitalWrite(motorA1, 0); analogWrite(motorA2, 0);
analogWrite(motorB1, 200); digitalWrite(motorB2, 0);
}
/***************************Right*****************************/
//If state is equal with letter 'R', wheels will turn right
else if (state == 'R') {
digitalWrite(motorA1, 0); analogWrite(motorA2, 0);
analogWrite(motorB1, 0); digitalWrite(motorB2, 200);
}
/************************Lights*****************************/
//If state is equal with letter 'W', turn leds on or of off
else if (state == 'W') {
if (i==0){
digitalWrite(lights, HIGH);
i=1;
}
else if (i==1){
digitalWrite(lights, LOW);
i=0;
}
state='n';
}
/**********************Horn sound***************************/
//If state is equal with letter 'V', play (or stop) horn sound
else if (state == 'V'){
if (j==0){
tone(buzzer, 1000);//Speaker on
j=1;
}
else if (j==1){
noTone(buzzer); //Speaker off
j=0;
}
state='n';
}
/************************Stop*****************************/
//If state is equal with letter 'S', stop the car
else if (state == 'S'){
analogWrite(motorA1, 0); analogWrite(motorA2, 0);
analogWrite(motorB1, 0); analogWrite(motorB2, 0);
}
/***********************Battery*****************************/
//Read battery voltage every 10sec.
currentMillis = millis();
if(currentMillis - (previousMillis) > (interval)) {
previousMillis = currentMillis;
//Read voltage from analog pin A0 and make calibration:
voltage = (analogRead(A0)*5.015 / 1024.0)*11.132;
//Calculate percentage...
perVolt = (voltage*100)/ maxBattery;
if (perVolt<=75) { level=0; }
else if (perVolt>75 && perVolt<=80) { level=1; } // Battery level
else if (perVolt>80 && perVolt<=85) { level=2; } //Min ------------------------ Max
else if (perVolt>85 && perVolt<=90) { level=3; } // | 0 | 1 | 2 | 3 | 4 | 5 | >
else if (perVolt>90 && perVolt<=95) { level=4; } // ------------------------
else if (perVolt>95) { level=5; }
Serial.println(level);
}

}
mnflife01
Fledgling
 
Posts: 1
Joined: Fri Mar 01, 2019 11:03 am

Re: Mdd10A problem (please help me)

Postby ober » Sun Mar 03, 2019 11:30 am

I believe it is quite straight forward, but I don think is possible for others to verify the code for you. We are not code compiler :)

Anyway, I did find some error in the code. digitalWrite() should be digital HIGH or LOW, while analogWrite() should be analog value, but in your code is the other way around. Try to change that and check the result.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm


Return to Robot Controller

Who is online

Users browsing this forum: No registered users and 10 guests

cron