Model Boat Mayhem - Forum

Please login or register.

Login with username, password and session length.
Pages: [1]   Go Down

Author Topic: Power Meter  (Read 7060 times)

More Coffee

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 127
  • Location: In a Igloo
Power Meter
« on: January 25, 2014, 06:03:26 PM »

I took a look around.
I have the parts to build a power meter,borrowing code complied by Steve Spence.Using an instructable a various web sources.
I'll try and put it in plain terms with lots of picture's.
Im not a tech head , just a crane operator with a college diploma in Diesel Engineering. what people don't know is like the Jedi Force the ability to pick something up and learn it is in all of us ,we merely have to tap into it. Patience and perseverance, no fear of making mistake's, of which you will make many..and that's a good thing. The world we live in is the result of a thousand of years of making mistakes. Its how we learn most day's.
The technology is out there,and whether we like it or not it is integrating itself into our hobbies in the form of brushless motor's, user programable ESC's, radio systems, batteries. Its happening rather quickly ,especially now with open source technology.

Hopefully in the future this forum could have a repository of sorts to gather technology that is relevant and useful ,tried and proven in regards to the model boating world.It would be kind of neat to have a barge set out bouys on a course  with some simple code unattended. I do feel there is room for  technology in the hobby and it can add to the realism of project.

So hang on I'll clear a spot on my work bench and try to enlighten the mass's.
Logged

More Coffee

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 127
  • Location: In a Igloo
Re: Power Meter
« Reply #1 on: January 25, 2014, 06:21:05 PM »

The first thing we are going to need is an interface to start compliling code into a language understood by an Arduino board.
I'll be using the Arduino 1.0.5 IDE interface for Windows
http://arduino.cc/en/Main/Software#toc2

The second thing your going to need is an Arduino board. The go to board of choice is the Arduino UNO R3 and the Arduino Mega 2650.
I'll be using the UNO R3 board.
http://arduino.cc/en/Main/ArduinoBoardUno


It depends on what you want to do . Myself I'll be loading this code onto a singular Atmel 328 micro processor, for a stand alone application..meaning I wont have the Arduino Uno board in my finished project. Just the needed components to allow the processor to operate.


 I have two options, I can use a blank chip and load the Arduino UNO bootloader (the software that allows the chip to accept programming) or I can buy a chip preloaded with the Arduino Bootloader.
I'll be using a blank chip.In my case I have a couple laying around.
If you decide to use a preloaded Atmega 328p processor ,simply program it with code and stick it in your circuit. .
If you don't ,The Uno board has function to load a virgin processor with the applicable bootloader. a few extra bits , few jumper wires




Logged

More Coffee

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 127
  • Location: In a Igloo
Re: Power Meter
« Reply #2 on: January 25, 2014, 06:32:43 PM »

 The code by Steve Spence. May a well get this on the table.
(It dosent seem like a lot until a guy starts writing it out)


Code: [Select]
#include <LiquidCrystal.h>

 /* This sketch describes how to connect a ACS715 Current Sense Carrier
 (http://www.hacktronics.com/Sensors/Current-Sensor-30-to-30-Amp/flypage.tpl.html) to the Arduino,
 and read current flowing through the sensor.

 */

 LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

 /*

 Vcc on carrier board to Arduino +5v
 GND on carrier board to Arduino GND
 OUT on carrier board to Arduino A0

 Insert the power lugs into the loads positive lead circuit,
 arrow on carrier board points to load, other lug connects to
 power supply positive

 Voltage Divider

 11.66 from + to A4
 4.62k from A4 to Gnd
 Ratio 2.5238

 */
 int batMonPin = A4;    // input pin for the voltage divider
 int batVal = 0;       // variable for the A/D value
 float pinVoltage = 0; // variable to hold the calculated voltage
 float batteryVoltage = 0;

 int analogInPin = A0;  // Analog input pin that the carrier board OUT is connected to
 int sensorValue = 0;        // value read from the carrier board
 int outputValue = 0;        // output in milliamps
 unsigned long msec = 0;
 float time = 0.0;
 int sample = 0;
 float totalCharge = 0.0;
 float averageAmps = 0.0;
 float ampSeconds = 0.0;
 float ampHours = 0.0;
 float wattHours = 0.0;
 float amps = 0.0;

 int R1 = 11660; // Resistance of R1 in ohms
 int R2 = 4620; // Resistance of R2 in ohms

 float ratio = 0;  // Calculated from R1 / R2

 void setup() {
   // initialize serial communications at 9600 bps:
   Serial.begin(9600);
   lcd.begin(20, 4);
 }

 void loop() {
 
 int sampleBVal = 0;
 int avgBVal = 0;
 int sampleAmpVal = 0;
 int avgSAV = 0;
 
 for (int x = 0; x < 10; x++){ // run through loop 10x

   // read the analog in value:
   sensorValue = analogRead(analogInPin); 
   sampleAmpVal = sampleAmpVal + sensorValue; // add samples together

   batVal = analogRead(batMonPin);    // read the voltage on the divider
   sampleBVal = sampleBVal + batVal; // add samples together
 
   delay (10); // let ADC settle before next sample
 }

 avgSAV = sampleAmpVal / 10;

   // convert to milli amps
   outputValue = (((long)avgSAV * 5000 / 1024) - 500 ) * 1000 / 133;
 
 /* sensor outputs about 100 at rest.
 Analog read produces a value of 0-1023, equating to 0v to 5v.
 "((long)sensorValue * 5000 / 1024)" is the voltage on the sensor's output in millivolts.
 There's a 500mv offset to subtract.
 The unit produces 133mv per amp of current, so
 divide by 0.133 to convert mv to ma
         
 */

 avgBVal = sampleBVal / 10; //divide by 10 (number of samples) to get a steady reading

   pinVoltage = avgBVal * 0.00610;       //  Calculate the voltage on the A/D pin
                                 /*  A reading of 1 for the A/D = 0.0048mV
                                     if we multiply the A/D reading by 0.00488 then
                                     we get the voltage on the pin.
                                   
                                     NOTE! .00488 is ideal. I had to adjust
                                     to .00610 to match fluke meter.
                                   
                                     Also, depending on wiring and
                                     where voltage is being read, under
                                     heavy loads voltage displayed can be
                                     well under voltage at supply. monitor
                                     at load or supply and decide.
 */

   ratio = (float)R1 / (float)R2;
   batteryVoltage = pinVoltage * ratio;    //  Use the ratio calculated for the voltage divider
                                           //  to calculate the battery voltage
                                         
                                           
   amps = (float) outputValue / 1000;
   float watts = amps * batteryVoltage;
   
   Serial.print("Volts = " );                     
   Serial.print(batteryVoltage);     
   Serial.print("\t Current (amps) = ");     
   Serial.print(amps);
   Serial.print("\t Power (Watts) = "); 
   Serial.print(watts); 
 
   
   sample = sample + 1;
 
  msec = millis();
 
  time = (float) msec / 1000.0;
 
  totalCharge = totalCharge + amps;
 
  averageAmps = totalCharge / sample;

  ampSeconds = averageAmps*time;
 
  ampHours = ampSeconds/3600;
 
  wattHours = batteryVoltage * ampHours;
 
   Serial.print("\t Time (hours) = ");
   Serial.print(time/3600);
 
   Serial.print("\t Amp Hours (ah) = ");
   Serial.print(ampHours);
   Serial.print("\t Watt Hours (wh) = ");
   Serial.println(wattHours);
 
     lcd.setCursor(0,0);
     lcd.print(batteryVoltage);
     lcd.print(" V ");
     lcd.print(amps);
     lcd.print(" A ");
 
   lcd.setCursor(0,1);
   lcd.print(watts);
   lcd.print(" W ");
   lcd.print(time/3600);
   lcd.print(" H ");
 
   lcd.setCursor(0,2);
   lcd.print(ampHours);
   lcd.print(" Ah ");
   lcd.print(wattHours);
   lcd.print(" Wh ");
 
   lcd.setCursor(0,3);
   lcd.print(ratio, 5);
   lcd.print("   ");
   lcd.print(avgBVal);
 
   // wait 10 milliseconds before the next loop
   // for the analog-to-digital converter to settle
   // after the last reading:
   delay(10);                   
 }
Logged

Capt Podge

  • Full Mayhemer
  • *****
  • Online Online
  • Posts: 3,227
  • Location: Blyth, Northumberland
Re: Power Meter
« Reply #3 on: January 25, 2014, 06:34:46 PM »

WOW  %% %% %%
 
You've raised my curiosity - what is the power meter going to be used for ? (in model boat terms)  :-)
 
Regards,
 
Ray.
 
Logged
Pop top campervan needed

More Coffee

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 127
  • Location: In a Igloo
Re: Power Meter
« Reply #4 on: January 25, 2014, 06:43:04 PM »

It will be an in line power meter, using supplied power from your battery to determine how much power your system is using.
This is a particularly usefull tool. With this tool a guy can determine if a battery is bad, or if your system is demanding more current than you battery can provide.
I have a unit I bought ,and it helped determine that one of my lawn tractor batteries was causing me a pile of grief . It charged ,but put a 4amp load on it and the voltage sunk to 8volt .Took about 5 min to find the problem ,diagnose it ,and correct it. Handy at the pond.
I'll note that this power meter im building will consume less than 50ma.. barely enough current to power 3 single leds.
Logged

Capt Podge

  • Full Mayhemer
  • *****
  • Online Online
  • Posts: 3,227
  • Location: Blyth, Northumberland
Re: Power Meter
« Reply #5 on: January 25, 2014, 06:55:06 PM »

Thanks for that MC, a very interesting project O0
 
Regards,
 
Ray.
 
Logged
Pop top campervan needed

More Coffee

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 127
  • Location: In a Igloo
Re: Power Meter
« Reply #6 on: January 25, 2014, 11:38:00 PM »

So.Now you have the jest of what the goal is, the next thing is to tool up and define what electronics gear we need. This list will change as the project move's forward. I know I will miss some small item(s).

Tools:
Computer..*if you just read this...chance's are your good :-))
Side cutter's
solding iron 30watt *may need a 60-80 watt iron to attach 10-14 gauge wire to the current sensor.
rosin core solder *what ever you use make sure its electronics grade. acid flux will eat this project this alive.
volt meter/ohm meter * just about any multimeter will suffice.
drill
drill index
razor knife
wire strippers
A bread board preferably two
telephone hook up wire or Cat 5 wire * this can be used on your bread board as jumpers and to wire up anything else.
9 volt battery and connector *for stand-alone testing ,any 9volt supply.
heavy duty connectors
Depending on the capacity of your particular unit, you may require 10-12-14 guage wire(because my unit is quite large ,150amp, I'll be using 10guage wire. Ignorant to work with .but needed.
please note that any system drawing more than 20amps ,Tamiya connectors are out of the question. MHO only.
look for  XT60, Anderson Power Pole , Deans , type connectors.


Electronics:

Arduino Uno R3
USB cord
16x2 LCD display
current sensor *in this case the ACS758 sensor.
solder breadboard to mount everything to
28 pin IC socket
pin headers *2.54mm spacing

Discrete components and semi-conductors:

L7805 or L78L05 voltage regulator *these can easily be used on any system up to 30volt DC
Atmega 328pu microprocessor
16mhz crystal
2x LEDs
2x 220 Ohm resistors
2x 10k Ohm resistor
1x 5K1 ohm resistor
1x 22K ohm resistor

1x 10k potentiometer


1x 50v 10 uF capacitor
1x 50v 1uF capacitor
2x 50v 22 pF capacitors

small momentary normally open ("off") button *any tact switch



More info   

http://arduino.cc/en/Main/Standalone
http://playground.arduino.cc/Learning/Standalone

Pay attention to the links on the left of the page's. they will take you to just about every aspect that is covered here.








Logged

More Coffee

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 127
  • Location: In a Igloo
Re: Power Meter
« Reply #7 on: January 26, 2014, 12:24:01 AM »

One of the first things we have to do is insure our voltmeter is reading proper voltage.
This project will handle any system up to 24v. With that we have keep in mind that our systems are rarely ever at a set voltage. So we'll gear up for a 27volt , a little overhead never hurts.

To do this and not blow up the Arduino , we will need a potential divider/voltage divider

http://en.wikipedia.org/wiki/Voltage_divider

With 27volt in with the proper resistors we can reduce the voltage to a maximum of 5 volt .
You will have to measure and record the resistance of each resistor you use here , it will only make your voltage readings more accurate, typical resistor can swing 5% of the indicated resistance.. this will translate into a voltage reading that's out by 5% or more when the calculations are done..

The wire indicated as yellow will supply your Arduino with a reference voltage to do the proper math.
Logged

More Coffee

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 127
  • Location: In a Igloo
Re: Power Meter
« Reply #8 on: January 26, 2014, 03:13:50 AM »

Getting acquainted with the bits.
Any time a guy builds a tool ,it can be as pretty as you want ,but if it dosent have "user confidence" its not worth much. Especially a measuring tool. You would expect the same results under the same conditions each and every time. A ruler isn't much good if every time you laid it on the same line ,it gave you a different measurement >>:-(




The Arduino UNO R3 board has on it both a 5v and 3.3v regulator. So while its plugged into your computer  you can use the Arduino to power your project.
If your LCD has a backlight indicated by A and K on the LCD pinout or pins 15 and 16 , its a LED backlight and you can connect it to the Arduino 3.3v output. When in stand alone ..this LED will require a resistor to run on the 5v output. The LCDs these days are pretty much generic with the same chipset's and firm ware , try to get the data sheet for yours , if not , generally a 150-100ohm resistor wont let you down on 5volt.

Try and get as much info at the time of purchase as possible , there have been instance's of reversed pin out on the LCD's .Ive only read of it, never had it happen to me yet, just something to keep in mind.

The Atmega 328pa has a internal oscillator ,we really don't need the 16mhz crystal , but like anything built in it has to fit the foot print often at some sacrifice, the internal oscillator can vary under certain conditions , Im looking for  smooth reliable performance , which is why the 16mhz crystal is included in this build.

The Current sensor,and some sample code.This is whats going to make the whole works jive ,from amp - watt to amp hrs ..read ,read somemore and read it again. that the best I can tell you.

http://www.dfrobot.com/image/data/SEN0098/ACS758%20datasheet.pdf
http://www.dfrobot.com/image/data/SEN0098/Current%20Sensor%20SCH.pdf
http://www.dfrobot.com/wiki/index.php?title=50A_Current_Sensor(SKU:SEN0098)
http://www.allegromicro.com/Design-Center/Technical-Documents/Hall-Effect-Sensor-IC-Publications/Current-Sensor-ICs-In-Current-Divider-Configurations.aspx
http://www.allegromicro.com/en/Products/Current-Sensor-ICs/Fifty-To-Two-Hundred-Amp-Integrated-Conductor-Sensor-ICs.aspx


Code: [Select]
/*
50A Current Sensor(AC/DC)(SKU:SEN0098) Sample Code
This code shows you how to get raw datas from the sensor through Arduino and convert the raw datas to the value of the current according to the datasheet;
Smoothing algorithm (http://www.arduino.cc/en/Tutorial/Smoothing) is used to make the outputting current value more reliable;
Created 27 December 2011
By Barry Machine
www.dfrobot.com
Version:0.2
*/


const int numReadings = 30;
float readings[numReadings];      // the readings from the analog input
int index = 0;                  // the index of the current reading
float total = 0;                  // the running total
float average = 0;                // the average

float currentValue = 0;

void setup()
{
  Serial.begin(57600);
  for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;       
}
void loop()
{   
    total= total - readings[index];         
    readings[index] = analogRead(0); //Raw data reading
    readings[index] = (readings[index]-510)*5/1024/0.04-0.04;//Data processing:510-raw data from analogRead when the input is 0; 5-5v; the first 0.04-0.04V/A(sensitivity); the second 0.04-offset val;
    total= total + readings[index];       
    index = index + 1;                   
    if (index >= numReadings)             
      index = 0;                           
    average = total/numReadings;   //Smoothing algorithm (http://www.arduino.cc/en/Tutorial/Smoothing)   
    currentValue= average;
    Serial.println(currentValue);
    delay(30);
}







Logged

More Coffee

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 127
  • Location: In a Igloo
Re: Power Meter
« Reply #9 on: January 26, 2014, 04:25:24 AM »

while your reading this download and install the Arduino IDE software
The LCD Display
Right of the hop I gave the wrong LCD
Its a 20x4 LCD I'll be using.
20x4 means the  LCD can display 20 characters per line , and has 4 lines ..room to display 80 characters.
http://www.hd44780.com/Specs/DM2004A_dwg.pdf

Each character has a line address.

http://web.alfredstate.edu/weimandn/lcd/lcd_addressing/lcd_addressing_index.html

You'll notice how the address is kinda split up , this is because there are two chips on the LCD, each controlling 2 lines  and half of the display.

In the Arduino IDE the lcd requires a "driver" to interact with the Arduino processor (Atmega328pa). In Arduino these "drivers" are known as  "libraries" .  Keep that word in your head , The Arduino software will only recognise a library in the proper folder .
For this LCD we need the LiquidCrystal library .
http://playground.arduino.cc/Main/LiquidCrystal
http://playground.arduino.cc/uploads/Main/LiquidCrystal_1.zip

Once you unzip that ,
You will have the file LiquidCrystal folder. In you documents folder you well see a Arduino file ,in that file there's a library , right click/ copy/paste or drag and drop the LCD library into the Documents/Arduino/libraries  folder
Now open the Arduino IDE , your new library  should be waiting for you to find it
click
File --- Sketchbook ----libraries--- LiquidCrystal--example's

or

File--- Examples ----LiquidCrystal
then you will also see examples to play with .

Attaching the LCD to the Arduino.At this point solder your pin header to the 0-16 pins on the LCD.This will enable you to "plug" the LCD directly into the bread board.
 This goes into detail ..Its not hard just connect the dots.
http://arduino.cc/en/Tutorial/LiquidCrystalTextDirection


The 10k potentiometer is there to set the contrast of your display. If you don't want it in there , set your contrast ,measure the resistance of the potentiometer ,and replace it with the corresponding resistor.





Logged

More Coffee

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 127
  • Location: In a Igloo
Re: Power Meter
« Reply #10 on: January 26, 2014, 03:00:00 PM »

This is a handy little gadget to answer a lot of your questions.

http://www.electronics2000.co.uk/download.php#assistant

That software , its what I use a lot , power divider, resistor codes , regulator calculator ,

It handy to have around
Logged

derekwarner

  • Full Mayhemer
  • *****
  • Online Online
  • Posts: 7,992
  • Location: Wollongong Australia
Re: Power Meter
« Reply #11 on: January 27, 2014, 02:43:16 AM »

No disrespect MC....... %) ...I reckon you would be a good sort of person to have around if the power went out & we all wanted a cup of coffee    {-)
I have been told I am very trying  <*<......but seriously    :-X am attempting to keep up with this thread...keep up the good work.......Derek
Logged
Derek Warner

Honorary Secretary [Retired]
Illawarra Live Steamers Co-op
Australia
www.ils.org.au

More Coffee

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 127
  • Location: In a Igloo
Re: Power Meter
« Reply #13 on: February 07, 2014, 04:49:21 PM »

Revised Schematic to show Temp Sensor and IR sensor for the tach.

Logged

Peter Fitness

  • Global Moderator
  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 6,821
  • Location: Wyrallah, near Lismore NSW Australia
Re: Power Meter
« Reply #14 on: February 08, 2014, 04:41:00 AM »

Some of the original poster's relies deleted at his request.

Peter Fitness
Moderator
Logged

More Coffee

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 127
  • Location: In a Igloo
Re: Power Meter
« Reply #15 on: February 08, 2014, 07:15:03 PM »

Thank You Peter. :-))


One last revision to the schematic, The impedance of the voltage divider was pointed out to me as being to high to allow a stable reading. The Atmega328pa  functions better with an impedance of less than 10K ohm.
Im still working my head around that :o



Logged

More Coffee

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 127
  • Location: In a Igloo
Re: Power Meter
« Reply #16 on: February 08, 2014, 11:56:38 PM »

Ya Try that again.
Logged
Pages: [1]   Go Up