Show Posts
Pages: 1 [2] 3
16  Using Arduino / General Electronics / Vin not the same as input voltage on: January 08, 2013, 09:32:19 am
Shouldn't Vin be directly routed from the input voltage +pin? When I measure the input voltage it varies greatly if I measure using Vin or directly from the input pin on the power connector.

Shouldn't Vin be directly routed from the input pin?

V = 12.37V (actual voltage measured on the power plug)
Vin = 11.57V

This has been measured using an external voltmeter.
17  Using Arduino / Audio / Re: Alarm buzzer, use delay or cycles? on: January 06, 2013, 03:59:41 pm
The timer will be something I wanted to use in order to keep track of mAh used as well as a separate timer to turn on/off and keep track of time in between. maybe even with a sound alert every 5min or so. When using goggles to fly the UAV I might have to use sound alerts for some functions since I won't be able to look at the display.
18  Using Arduino / Audio / Re: Alarm buzzer, use delay or cycles? on: January 06, 2013, 05:51:56 am
Super, that's exactly what I need. I can also make a timer function from this.

How accurate is this ms-counter?
19  Using Arduino / Audio / Re: Alarm buzzer, use delay or cycles? on: January 05, 2013, 04:30:26 pm
Yes I understand. In my project the Arduino will make the same operation over and over so it's not a problem. I'll only set the correct no of cycles for my given application and it will be the same since he tasks are always the same. Small variations in duration doesn't matter. It's more important that the Arduino can keep on doing other stuff in the meantime while the alarm is activated.

For my project the Arduino monitors systems and presents this information and that's basically it, when some values drop outside approved intervals the alarm is activated. And yes this function is called from the loop.

Anyway, is there a way to  base duration from any kind of timer in the Arduino or do I need an external chip for this?
20  Using Arduino / Audio / Re: Alarm buzzer, use delay or cycles? on: January 04, 2013, 05:04:51 pm
I already tried this and the blinking is actually not fast at all, a rough guess is about 500ms for each blink.

Unless the actual tone making isn't too resource demanding I guess it's a quite neat way to solve it without having a clock. Anyway, thanks, I won't use delay then.
21  Using Arduino / Audio / Alarm buzzer, use delay or cycles? on: January 04, 2013, 11:51:44 am
In my project I'll have an alarm buzzer that activates whenever some criterions are true. Me being an Arduino novice I've read that if I use the delay function the processor can't continue with other tasks. Is this true?

In any case I have made two exemples and I would like to know if any of these is preferred if I'd like the Arduino to continue with other tasks while the alarm is activated?

Code example using delay.
Code:
void alarm() {
  tone(5,840);                        
  digitalWrite(screen_backlight, HIGH);
  delay(500);
  noTone(5);
  digitalWrite(screen_backlight, LOW);
  delay(500);
}

Code example using cycles.
Code:
void alarm() {
  if(warning_delay < 25) {                  
    warning_delay = warning_delay + 1;
  } else {
    digitalWrite(screen_backlight, HIGH);
    tone(5,840);
    warning_delay = warning_delay + 1;
  }
  if(warning_delay > 50) {
    digitalWrite(screen_backlight, LOW);
    noTone(5);
    warning_delay = 0;
  }
}
22  Using Arduino / General Electronics / Re: Voltage divider problem on: January 04, 2013, 08:55:19 am
How do you mean? Sorry if I'm a little slow. smiley

I tried testing in just below 0°C and now I just bothered to take notes on method 2 and 3 since 1 was too far off.

Powering using USB:
4.47V (measured using my meter)
4.45V (method 2) diff 0.4%
4.39V (method 3) diff 1.8%

Powering usning 3S:
11.55V (measured using my meter)
11.56V (method 2) diff 0.1%
11.54V (method 3) diff 0.1%

Now if it gets even colder I will try again but for now I pretty happy with method 2, it seems to be very consistent with my meter which was what I strived for in the start.
23  Using Arduino / General Electronics / Re: Voltage divider problem on: January 03, 2013, 06:29:07 pm
Well, now I've tried to try a few things in my code and have some interesting results. However I'm not done and will test this in various temperatures next.

In the following code I use three methods. All of them uses the same voltage divider so changes due to resistor tolerances and temperature change will be the same for all.

Method 1 is using the code from retrolefty.

Method 2 is using the code from Scott Daniels. This one suggests a method of calibrating which I've done: http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/

Method 3 is just using 5V without bothering to know about reference voltage etc.

Powering using USB:
4.52V (measured using my meter)
4.44V (method 1) diff 1.8%
4.51V (method 2) diff 0.2%
4.45V (method 3) diff 1.5%

Powering usning 3S:
11.62V (measured using my meter)
11.46V (method 1) diff 1.5%
11.62V (method 2) diff 0.0%
11.61V (method 3) diff 0.1%

Code:
// Boopidoo Ground Station

#include <LiquidCrystal.h>

//LCD display pinout - YM2004A & OV1604A
//VSS   LCD pin 1     -  Connect to ground
//VDD   LCD pin 2     -  Connect to +5V
//V0    LCD pin 3     -  Connect to potentiometer
//RS    LCD pin 4     -  Arduino pin D07  
//RW    LCD pin 5     -  Connect to ground
//EN    LCD pin 6     -  Arduino pin D08
//DB4   LCD pin 11    -  Arduino pin D09
//DB5   LCD pin 12    -  Arduino pin D10
//DB6   LCD pin 13    -  Arduino pin D11
//DB7   LCD pin 14    -  Arduino pin D12
//ELA   LCD pin 15    -  Arduino pin D13
//ELK   LCD pin 16    -  Connect to ground
//LiquidCrystal lcd(7, NULL, 8, 9, 10, 11, 12);
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int screen_backlight = 13;                       //pin D13 will control the backlight
float voltage_battery1 = 0.0;                    //voltage from pin A0
float voltage_reference1 = 0.0;                  //reference voltage on the arduino 5V-rail
float voltage_battery2 = 0.0;                    //voltage from pin A0
float voltage_reference2 = 0.0;                  //reference voltage on the arduino 5V-rail
float voltage_divider = (6780.0+2720.0)/2720.0;  //((R1+R2)/R2)*voltage for voltage divider before pin A0

void setup() {
  pinMode(screen_backlight, OUTPUT);       //LCD Setup
  digitalWrite(screen_backlight, HIGH);    // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
  lcd.begin(20,4);                         // columns, rows.  use 16,2 for a 16x2 LCD, etc.
  lcd.clear();                             // start with a blank screen
}

//method 1
int getBandgap(void) // Returns actual value of Vcc  (x100)
    {    
      #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
        // For mega boards
        const long InternalReferenceVoltage = 1115L;  // Adjust this value to your boards specific internal BG voltage x1000
        // REFS1 REFS0          --> 0 1, AVcc internal ref. -Selects AVcc reference
        // MUX4 MUX3 MUX2 MUX1 MUX0  --> 11110 1.1V (VBG)         -Selects channel 30, bandgap voltage, to measure
        ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR)| (0<<MUX5) | (1<<MUX4) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);
      #else
        // For 168/328 boards
        const long InternalReferenceVoltage = 1056L;  // Adjust this value to your boards specific internal BG voltage x1000
        // REFS1 REFS0          --> 0 1, AVcc internal ref. -Selects AVcc external reference
        // MUX3 MUX2 MUX1 MUX0  --> 1110 1.1V (VBG)         -Selects channel 14, bandgap voltage, to measure
        ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);
      #endif
      delay(50);  // Let mux settle a little to get a more stable A/D conversion
      // Start a conversion  
      ADCSRA |= _BV( ADSC );
      // Wait for it to complete
      while( ( (ADCSRA & (1<<ADSC)) != 0 ) );
        // Scale the value
        int results = (((InternalReferenceVoltage * 1024L) / ADC) + 5L) / 10L; // calculates for straight line value
        return results;
    }

//method 2
long readVcc() {
  // Read 1.1V reference against AVcc
  // set the reference to Vcc and the measurement to the internal 1.1V reference
  #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
    ADMUX = _BV(MUX5) | _BV(MUX0);
  #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
    ADMUX = _BV(MUX3) | _BV(MUX2);
  #else
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  #endif  
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring
  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
  uint8_t high = ADCH; // unlocks both
  long result = (high<<8) | low;
  result = 1.1 * (5.00/5.13) * 1023 * 1000 / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
  //result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
  return result; // Vcc in millivolts
}

void read_voltage() {
  //method 1 using internal reference voltage
  voltage_reference1=(float)getBandgap();
  voltage_battery1=map(analogRead(0),0,1023.0,0.0,voltage_reference1) * voltage_divider;
  
  //method 2
  voltage_reference2 = readVcc();
  voltage_battery2 = map(analogRead(0),0,1023.0,0.0,voltage_reference2) * voltage_divider;

}

void screen_print() {
  //printing method 1
  lcd.setCursor(0,0);
  lcd.print(voltage_reference1 / 100);
  lcd.setCursor(0,1);
  lcd.print(voltage_battery1 / 100);
  
  //printing method 2
  lcd.setCursor(10,0);
  lcd.print(voltage_reference2 / 1000);
  lcd.setCursor(10,1);
  lcd.print(voltage_battery2 / 1000);
  
  //printing original method not bothering with voltage reference
  lcd.setCursor(0,3);
  lcd.print(analogRead(0)*voltage_divider/1023*5);
}

void loop() {  
  read_voltage();
  screen_print();
}

Also, another issue is that some of the values seem to fluctuate on my LCD screen. This is especially apparent for method 2. Any suggestions on how to reduce this and make the value more stable? I've added a 470n capacitor between A0 and ground.
24  Using Arduino / General Electronics / Re: Voltage divider problem on: January 02, 2013, 06:13:29 pm
Yes, maybe. Do you have some ideas on such chips that I could use with the Arduino?
25  Using Arduino / General Electronics / Re: Voltage divider problem on: January 02, 2013, 04:16:08 pm
Ok, I'll better use the ones I have with lower tolerances then.

Measurement doesn't need to be super exact. I'll use the arduino to measure battery voltage in my UAV ground station. So it's mostly to make sure I don't run out of battery. Because of that I'll try to keep it as simple as possible but also not introduce any unneccessary errors. I'll also measure a bunch of other stuff such a current sensor, clock, timer, signal strength and buzzers and lights to indicate warnings etc. Information will be presented mostly on a 20x4 LCD.

As you probably figured out I'm an arduino newbie and this is my first project, I'm learning as I go along and really appreciate all input.
26  Using Arduino / General Electronics / Re: Voltage divider problem on: January 02, 2013, 03:50:49 pm
Using that code I got the following when powered over the USB:

USB
Battery Vcc volts =  5.03 (serial printer)
Analog pin 0 voltage = 1.09 (serial printer)
Analog pin 0 voltage = 1.11 (using my meter)

3S external power
Battery Vcc volts =  4.94 (serial printer)
Analog pin 0 voltage = 2.84 (serial printer)
Analog pin 0 voltage = 2.89 (using my meter)

That's pretty good, next I'll try to use these values and update my code to see what I'll get. If I get a consistent difference <2% I guess I can live with that.
27  Using Arduino / General Electronics / Re: Voltage divider problem on: January 02, 2013, 03:14:05 pm
Thanks, that code looks very interesting.

Also a question regarding resistor tolerances. These are manufacturing tolerances right? The resistors themselves does not "change" their resistance over time, right? If so then this problem should be overcome by just measuring them and using that exact value in my code. The projects I make is for myself and will not be mass produced hence it's ok for me to measure each resistor manually.

Also I have some 1% and some 5% resistors, the former is much closer to their specified value, of course, but is there any other benefits to use these over the ones with lower tolerances? As I said I do measure them prior to installation.
28  Using Arduino / General Electronics / Re: Voltage divider problem on: January 02, 2013, 01:12:20 pm
@tack
Well I'm almost pleased with the results but since there's more that can be one to improve the results I would like to try them as well.

That seems very interesting however I don't really undertand what that does so I guess I'll have to study it a little more.
29  Using Arduino / General Electronics / Re: Voltage divider problem on: January 02, 2013, 07:45:13 am
Now I've reduced the voltage divider and use R1=2990 and R2=984 and yes I do use my calibrated Fluke to measure everyting (as well as a cheapo but quite accurate meter). This will not need to hold any kind of indistry calibration standard but I need it to be as close to my meters as possible.

Now I get the following results:
Power over USB: 4.32V (arduino), 4.47 (on my meters),  3.35% diff
Power over 3S: 11.52V (arduino), 11.66V (on my meters), 1.2% diff

Of course I'd like it to be even better so I guess I should now start investigating this VREF that I guess is how the arduino close the arduino 5V supply is to 5V. Is that correct? Is there a prefered method of doing this?
30  Using Arduino / General Electronics / Re: Voltage divider problem on: January 01, 2013, 08:15:18 pm
Ok, so to improve the accuracy I could reduce the resistor values or at least the dividing factor so that I get something around 3 or 4 instead of 11. This should make the accuracy a little better right? I want to be able to connect up to 4S-battery (16.8V) safely.

The 5V supply from the arduino seems to be a pretty solid 5V when I connect an external battery. I get 5.00V on my multimeter and when I power it using USB I get 5.06V. Or do you mean another 5V-rail then the 5V-output pin?
Pages: 1 [2] 3