Go Down

Topic: Android Bluetooth joystick (Read 378908 times) previous topic - next topic

woodygb

The sensor reads 2.5v center= zero amps .... and swings either side of that depending on motor direction.

So the range is I believe 2500/100= 25 mV per Amp.

Simply read the analog output voltage from the sensor with a spare Arduino pin and apply some programming math.

http://www.arduino.cc/en/Tutorial/ReadAnalogVoltage


woodygb

#707
Mar 28, 2016, 11:57 pm Last Edit: Mar 28, 2016, 11:58 pm by woodygb
I stand corrected...20mV/A :-[


fullspool

#708
Mar 29, 2016, 02:32 am Last Edit: Mar 29, 2016, 04:24 am by fullspool
- the hard way: control a relay from an Arduino output
 - the easy way: power the Arduino from one motor battery, as suggested.
   A depleted battery will still have enough juice for the micro controller

In both ways, a failed connection will still lead to unpredicable results  ;)

EDIT: Also seems there is a Failsafe feature within the Sabertooth device


No!! please do the math, a (rather) easy task
Hint: the +-100A sensor sensitivity is 20mV/amp


How sensitive is the UNO board to voltage? a full 12v battery might see 12.6 to 12.8volts , should I step it down or roll with it?

What I was thinking is pin/flag switch to control power to the board, I would just break the ground with my pin/flag switch. Once connections has been established I would have Button 3 send signal on an digital channel from UNO to a relay . This would make sure connection was established via bluetooth app before any power gets to the motors. I think I have a 25 amp solid state relay I can experiment with.

Thank you for your input regarding the current sensor, let me study this and I will report back my findings.
 

fullspool

Yes, let me have a proposal for the resistors values and the checkBat() formula   ;)


kas , if my source is 24 v could I use a 39k and 10k resister to get my voltage around 4.89v?

so would it read:
 
voltage = analogRead(Vpin) * (5.0/1024) *2 = analogRead(Vpin) * 0.0146484375    ?

woodygb

#710
Mar 29, 2016, 10:28 am Last Edit: Mar 29, 2016, 10:28 am by woodygb
BTW ...The voltage of a lead acid battery... when in use / under load... tells you nothing about it's ACTUAL state of charge.

http://modernsurvivalblog.com/alternative-energy/battery-state-of-charge-chart/


http://www.smartgauge.co.uk/technical1.html#peukert_brief

kas

#711
Mar 29, 2016, 10:53 am Last Edit: Mar 29, 2016, 05:19 pm by kas
Quote
kas , if my source is 24 v could I use a 39k and 10k resister to get my voltage around 4.89v?
With this setup, a fresh battery (12.8V) will generate 5.22V, and will probably fry the Analog Input
Try again  ;)


kas

Quote
How sensitive is the UNO board to voltage? a full 12v battery might see 12.6 to 12.8volts , should I step it down or roll with it?
The Uno will survive to anything below 20 Volts


fullspool

With this setup, a fresh battery (12.8V) will generate 5.22V, and will probably fry the Analog Input
Try again  ;)


What about a 40k and 6.8 k ?

kas

Quote
What about a 40k and 6.8 k ?
OK!
what about the math ??


woodygb

Note that a battery JUST coming off the charger could initially be close to 14v.
I'd err on the side of caution and go with 15v per battery ..it also makes the resistor divider calc easier.

Your voltage divider is unlikely to be precise ...so you will either need to finesse the Arduino voltage measurement formula to get the displayed reading match that of a multi meter attached to the batteries.... OR you could ... if your careful... use a multi turn pot as your resistor divider ....and use that to get the Android display voltage to match the ACTUAL measured voltage of the batteries.

I use trim pots like this ....

http://www.ebay.co.uk/itm/5-Pack-3296-Multiturn-Variable-Resistors-Potentiometer-Preset-Trimmer-Pot-/121694846730?var=420697006427&hash=item1c5593ff0a:m:mc3DUYg7CR3yBagFIcQPjqw

fullspool

#716
Mar 29, 2016, 07:34 pm Last Edit: Mar 29, 2016, 08:03 pm by fullspool
OK!
what about the math ??


Well if I use 30v as woody suggested we could use a 40k resistor and a 6k resistor to give us around 3.9v.  I suppose the formula would read:

 voltage = analogRead(Vpin) * 0.00976525;                     
  // battery voltage:(5.0/1024.0)*((40+6)/23)=0.00976525 V per ADC count


@woody I will look into those pots . I'm going to measure the actual voltage and see how it compares to my fluke meter . If it's out substantially I will make an adjustment, my main concern is a quick reference to avoid damage to the batteries.

fullspool

#717
Mar 30, 2016, 03:59 am Last Edit: Mar 30, 2016, 05:15 am by fullspool
Well I was experimenting with the uno and relays and got the B1 button to turn on the relay which then allows current to flow to the motors .

I need to adjust the code so I have a Button 3 control this as B1 has another purpose . I will probably just reorganize the layout at some point .

I'm using a fan for a demo but the motors will be hooked in line with the relay .

https://youtu.be/EvAueKsMQos

Edit:

I added some coding to the program and now Button 3 should initiate my relay control from pin 12. I haven't tested it yet but it compiled with out any errors so I will test this out to make sure it works as it should .

@ Kas does this look right?

#define    pinServo_A     8            //<<  ServoA pin (AUX)
#define    pinServo_X     9            //<<  ServoX pin
#define    pinServo_Y     10           //<<  ServoY pin
#define    STX            0x02
#define    ETX            0x03
#define    Relay          12                           // used for motor relay
#define    ledPin         13                           // lights up with servo movement
#define    Vpin           A0                            // battery monitoring analog pin
#define    Apin           A1                            // battery monitoring analog pin
#define    MVperAMP       66                            // The 30A module delivers 66mV/A;
#define    VSoffset       2500                          // 2.5V >> 0 Amp
#define    LIMIT_ANGLE    0                            // Max range set to 20 for SCROP XL


Servo myservoA;       
Servo myservoX;                                         // create servo objects
Servo myservoY;

byte cmd[8] = {0, 0, 0, 0, 0, 0, 0, 0};                 // bytes received
byte buttonStatus = 0;                                  // first Byte sent to Android device
long previousMillis = 0;                                // will store last time Buttons status was updated
long sendInterval = 750;                                // interval between Buttons status transmission (milliseconds)
long deadManInterval = 550;                             // interval between Dead Man checks (milliseconds)
boolean deadManTimeout = false;                         // dead man flag
String displayStatus = "xxxx";                          // message to Android device
int servo_L, servo_R = 90;                              // servo's positioning values
float voltage = 0.0;                                    // battery voltage in mV
int milliAmp = 0;                                       // milli Amp
int turbo = 2;                                          // tank max speed (2: slow, 1: fast)

void setup()  {
  Serial.begin(57600);
  myservoA.attach(pinServo_A); 
  myservoX.attach(pinServo_X,1000,2000); 
  myservoY.attach(pinServo_Y,1000,2000);
  pinMode(ledPin, OUTPUT); 
  pinMode(Relay, OUTPUT);     
  while(Serial.available())  Serial.read();          // empty RX buffer
  myservoA.write(90);
}



// -----------------  BUTTON #3  -----------------------
    case 'E':
      buttonStatus |= B000100;        // ON
      displayStatus = "Motors <ON>";
      digitalWrite(Relay, HIGH);
      break;
    case 'F':
      buttonStatus &= B111011;      // OFF
      displayStatus = "Motors <OFF>";
      digitalWrite(Relay, LOW);
      break;
 

kas

Quote
I'm using a fan for a demo but the motors will be hooked in line with the relay .
https://youtu.be/EvAueKsMQos
The relay is LOW level input isn't it ??



Quote
@ Kas does this look right?
So far so good   :)

Although not mandatory, I would personally add
   digitalWrite(Relay, LOW);
after
   pinMode(Relay, OUTPUT);
     

woodygb

#719
Mar 30, 2016, 01:15 pm Last Edit: Mar 30, 2016, 01:15 pm by woodygb
 I think that your going to need 2 relays.
A 5V and a second... worked by the 5v relay ...rated @24v & 60 -100 Amp to supply/cut power to the Sabertooth.

OR ...

You could perhaps consider a 5v double throw relay that cuts the servo signals to the Sabretooth and rely on the built in failsafe ..switch 6...to stop the bot

Go Up