View Single Post
Old 09-14-2016, 09:25 AM   #1 (permalink)
Registered Users
Posts: 3,212

Join Date: Mar 2012
Location: Wauwatosa, WI
Default Arduino current sensor - How To

There is another thread about this, but I thought that since I asked a bunch of questions and worked through it that I'd put a step by step set of instructions on how to do this.

I'm assuming the following
  • You know how to program OpenTX
  • You understand how to load software and drivers using Windows.
  • That you understand that this is build at your own risk and learn about some of this stuff before blindly following things

First of all, thank you to the help that I received from Trebb & Raleighcopter

What you need
  • Arduino Nano Get the Atmega 328 16MHz processor. I got mine from Amazon.
  • ACS758 100U current sensor. I got mine from eBay. There are 50, 100, 150 and 200A sizes, so select what you want for your application. Unidirectional ones will work and are more accurate than bidirectional sensors.
  • .1uF Capacitor Had one laying around or you can get them from eBay
Download Arduino tools
Download OpenXSensor library -
Do not use OpenXSensor Config

Note that the following wiring needs to match the configuration setup in oXs_config.h
Here is a diagram of what my wiring is. The example oXs_config.h file excerpts below match it.

Note that you will want to unplug from the receiver when you plug in the USB. The power on the board is not isolated and you will power up your FBL and servos from Arduino board which is not really setup to supply that much power.

Editing oXs_config.h
Open the OpenXSensor project in the Arduino software.

In the oXs_config.h file near the middle. You will need to set the pin that is the input from the current sensor. I used A6. See below. You will also need to adjust how many mvolts are being output from the sensor for both at 0 amps and per amp. The per amp voltage is in the data sheet for the 758. To measure at 0 amps, I simply measured the voltage across VIOUT and GND on the 758 when the Arduino was being powered by the USB. This way the flight pack is not hooked up and 0 current is flowing across the 758.
The 758 data sheet can be found here.
This site also has information as well as starting points for offsets at 0 current in case you have no way of measuring.
Here are the parameters I set for my 758 100A unidirectional current sensor wired to Pin A6 on the Arduino. I did not use any resistors, so I set those value to 0.
// ***** 6.4 - Current parameters *****
#define MVOLT_AT_ZERO_AMP 589 // in millivolt
#define MVOLT_PER_AMP 36 // in milliVolt per Amp
#define RESISTOR_TO_GROUND_FOR_CURRENT 0 // put as comment or set to 0 if no divider is used
#define RESISTOR_TO_CURRENT_SENSOR 0 // put as comment or set to 0 if no divider is used
If you want to change the pin that outputs to the S.Port, then you will need to change the following line to what you want.
// --------- 2 - Serial data pin choice ---------
#define PIN_SERIALTX 4 // The pin which transmits the serial data to the telemetry receiver, Usually pin 4
Connecting Arduino to PC
Warning Do not plug Arduino into a BEC and USB at the same time. It will not end well for your board.
When you install the Arduino IDE (Integrated Design Environment) it should give you the option of installing the drivers. Do this.

Plug in the Arduino to the USB and then look in Device Manager to see where it connected. If it does not show up, then your driver did not install properly and you need to fix that. Otherwise, note the COM port used. The Arduino tools do not automatically find it.

Setting up Arduino Studio
First you need to set up the type and processor being used. There are several options. I used a Nano 16MHz with the built in USB port.

Your config should look similar to the following.

Before you go with OpenXSensor, you might want to try the sample project called Blink to make sure that everything works. The Arduino tools have it under the example projects. It's a bit counter intuitive, but you upload a project to your Arduino. Just make sure the LED blinks when you upload that example file. If it does, then you have just run your first project. Congratulations.

Once you've done that, open the OpenXSensor project in the Arduino tools and upload it to the Nano.

Configuring the Taranis
Once you plug in everything, power up the model and scan for new telemetry sensors. Curr should show up. You can then create a new telemetry variable for mAh that is calculated.

Finally, you need to calibrate your sensor. My method was to fully charge a battery on the charger. Fly your model for a couple of minutes. Write down the mAh from the telemetry screen on the transmitter, then compare it to how many mAh need to be put back into the battery to fully charge it. Then calculate what percentage you are off by. Once you have that, then adjust the value of MVOLT_PER_AMP in oXs_config.h accordingly.

As an example, I was reading about 10% lower in the TX than what my charger was telling me. I have MVOLT_PER_AMP set to 40, so I lowered it by 10% to 36 so that it would calculate a higher usage of current per mV. I saved the file and then uploaded the project into the Arduino again and I was within 1% of the charger reading. I'm sure that's within the tolerances of my measuring equipment and close enough that I won't overdischarge my pack if I fly it to 25% left.

Here is my first ugly setup. The next one I build will have custom wire lengths for model I'm building it on and I'll heat shrink the components to avoid shorting things.

More information:
Attached Thumbnails
Click image for larger version

Name:	oXs Current Wiring.jpg
Views:	6261
Size:	62.2 KB
ID:	671562   Click image for larger version

Name:	Arduino type.jpg
Views:	2700
Size:	71.2 KB
ID:	671563  
P Max v2, G570, N556, S516, P380x2, XK K110, Open-TX
JWeber is offline        Reply With Quote