Este projeto, é um projeto testador de pilhas. Ele mostra a tensão da pilha, Watt hora da pilha, temperatura do ambiente, Joules usados da pilha e tempo.

Neste projeto foi utilizado:

  • Arduino
  • LCD 16x2
  • sensor de temperatura LM35
  • 4x resistores de 22 ohm
  • 1x resistor de 1Kohm
  • 1x potenciômetro para o LCD 16x2

Abaixo está a ligação a ser feita:

Para demonstrar a ligação da pilha, foi colocado o soquete com duas, mas coloque apenas uma de cada vez para fazer o teste!

A programação para este projeto está mostrado abaixo:

#include <Time.h>
#include <LiquidCrystal.h>
#include <Wire.h>

#define V_LOAD_PIN A0
#define R_LOAD 5.5
#define FINAL_VOLTAGE 0.2

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

float joules = 0;
float voltage = 0;
float temp = 0;
uint8_t hours = 0;
uint8_t mins = 0;
uint8_t lastSecond;
bool batteryAttached = false;
bool testComplete = false;
time_t startTime = 0;

void setup() {
Serial.begin(9600);
pinMode(V_LOAD_PIN, INPUT);
lcd.begin(16, 2);
lcd.print(" Attach Battery");
lcd.setCursor(0, 1);
lcd.print(" to begin test");
time_t t = now();
lastSecond = second(t);
}

void loop() {
if (batteryAttached) {
if (testComplete) {
updateDisplay();
} else {
time_t t = now()-startTime;
uint8_t sec = second(t);
if (sec != lastSecond) {
lastSecond = sec;
hours = hour(t);
mins = minute(t);
voltage = 5.0 * ((float) analogRead(V_LOAD_PIN)) / 1023.0;
float current = voltage / R_LOAD;
joules += voltage * current;
int val = analogRead(A1);
float voltagetemp = (val) * 5;
voltagetemp /= 1024.0;
temp = (voltagetemp - 0.5) * 10 ;
updateDisplay();
Serial.print(t);
Serial.print(",");
Serial.print(voltage);
Serial.print(",");
Serial.print(current);
Serial.print(",");
Serial.print(joules);
Serial.print(",");
Serial.print(temp);
Serial.println();
if (voltage < FINAL_VOLTAGE) {
testComplete = true;
}
}
}
} else {
voltage = 5.0 * ((float) analogRead(V_LOAD_PIN)) / 1024.0;
if (voltage > 0.02) {
startTime = now();
batteryAttached = true;
Serial.println("time,voltage,current,joules,temp");
}
}
}

// Update the LCD with the following format:
//
// +----------------+
// |99999.9J 99.99Wh|
// |9.99V 99^C 59:59|
// +----------------+

void updateDisplay() {
char row[32];
memset(row, 0, 17);

float wattHours = joules / 3600;
if (joules < 9999)
fmtDouble(joules, 2, &row[0], 8);
else
fmtDouble(joules, 1, &row[0], 8);
strcat(row, "J");
char whStr[9];
fmtDouble(wattHours, 2, whStr, sizeof(whStr));
sprintf(&row[9], "%5sWh", whStr);
for (int i=0;i<16;i++)
if (row[i] == 0)
row[i] = ' ';
lcd.setCursor(0, 0);
lcd.print(row);

if (testComplete) {
lcd.setCursor(0, 1);
lcd.print(" Test Complete! ");
} else {
memset(row, 0, 17);
fmtDouble(voltage, 2, &row[0], 8);
strcat(row, "V");
fmtDouble(temp, 0, &row[6], 8);
strcat(&row[6], "\xDF");
strcat(&row[6], "C");
uint8_t degree = 0xEF;
sprintf(&row[11], "%02d:%02d", hours, mins);
for (int i=0;i<16;i++)
if (row[i] == 0)
row[i] = ' ';
lcd.setCursor(0, 1);
lcd.print(row);
}
}

void fmtDouble(double val, byte precision, char *buf, unsigned bufLen = 0xffff);
unsigned fmtUnsigned(unsigned long val, char *buf, unsigned bufLen = 0xffff, byte width = 0);

unsigned fmtUnsigned(unsigned long val, char *buf, unsigned bufLen, byte width) {
if (!buf || !bufLen)
return(0);

// produce the digit string (backwards in the digit buffer)
char dbuf[10];
unsigned idx = 0;
while (idx < sizeof(dbuf)) {
dbuf[idx++] = (val % 10) + '0';
if ((val /= 10) == 0)
break;
}

// copy the optional leading zeroes and digits to the target buffer
unsigned len = 0;
byte padding = (width > idx) ? width - idx : 0;
char c = '0';
while ((--bufLen > 0) && (idx || padding)) {
if (padding)
padding--;
else
c = dbuf[--idx];
*buf++ = c;
len++;
}

// add the null termination
*buf = '\0';
return(len);
}

void fmtDouble(double val, byte precision, char *buf, unsigned bufLen) {
if (!buf || !bufLen)
return;

const byte maxPrecision = 6;
if (precision > maxPrecision)
precision = maxPrecision;

if (--bufLen > 0) {
// check for a negative value
if (val < 0.0) {
val = -val;
*buf = '-';
bufLen--;
}

// compute the rounding factor and fractional multiplier
double roundingFactor = 1;
unsigned long mult = 1;
for (byte i = 0; i < precision; i++) {
roundingFactor /= 10.0;
mult *= 10;
}

if (bufLen > 0) {
// apply the rounding factor
val += roundingFactor;

// add the integral portion to the buffer
unsigned len = fmtUnsigned((unsigned long)val, buf, bufLen);
buf += len;
bufLen -= len;
}

// handle the fractional portion
if ((precision > 0) && (bufLen > 0)) {
*buf++ = '.';
if (--bufLen > 0)
buf += fmtUnsigned((unsigned long)((val - (unsigned long)val) * mult), buf, bufLen, precision);
}
}

// null-terminate the string
*buf = '\0';
}

Passe a programação acima para a IDE do Arduino e faça o UPLOAD.

Coloque a pilha e ligue o Arduino. Você verá os dados como da foto acima! Caso não tenha nenhuma pilha conectada, o LCD mostrará "Test Complete!" e finalizará o programa. Para utilizar novamente, aperte o botão RESET do Arduino ou ligue e desligue o Arduino com a pilha conectada.

E é isso! Esperamos que tenha gostado! Para sugestões de tutoriais, clique aqui! Para ver outros tutoriais e projetos desenvolvidos pela equipe LdG e por outros garagistas, clique aqui e aqui, respectivamente! Até a próxima!

Referências:

http://labdegaragem.com/profiles/blogs/tutorial-lcd-com-arduino

http://www.electronics-lab.com/blog/?p=18067

http://denishennessy.com/2012/04/08/measuring-battery-capacity-with...

http://labdegaragem.com/profiles/blogs/projeto-medidor-de-temperatu...

Exibições: 24924

Comentar

Você precisa ser um membro de Laboratorio de Garagem (arduino, eletrônica, robotica, hacking) para adicionar comentários!

Entrar em Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)

Comentário de Joao Goedert em 15 junho 2016 às 13:32

Endosso a observação feita pelo Pedro L. Ribeiro. Estamos perdendo a capacidade de pensar em termos genéricos e formando uma geração de hobistas/técnicos que se sentem mais a vontade com as conexões físicas do que com esquemas mais abrangentes.

Comentário de Adriano em 6 maio 2016 às 8:29

Estou fazendo esse projeto e ta me dando um erro na parte da biblioteca do time.h poderia disponibilizar para download, pois ja baixei algumas mas nao esta funcionando.

Comentário de Pedro L Ribeiro em 14 janeiro 2016 às 21:26

Incomoda-me sobremaneira neste forum, a falta de publicação de esquemas eletrônicos tradicionais. Não me apraz tentar ler o que foi feito olhando para um monte de fios coloridos; seria muito mais fácil visualizar as idéias com o esquema em mãos.

Pedro

Comentário de Eduardo em 26 março 2015 às 12:12
E o diagrama elétrico, vocês poderiam me fornecer?
Comentário de Rodney Amancio em 23 setembro 2013 às 22:50

Boa noite.

Como faço para testar uma bateria de 9V?

Comentário de Jose Adriano em 13 junho 2013 às 17:31

 Olá Fillipe Augusthus Pires Souto, verifique se você tem as bibliotecas que são necessárias para este projeto instalada no diretório: C:\Arquivos de programas\arduino-1.0.1\libraries( depende do local onde estar o programa arduino-1.0.1)..

Comentário de Fillipe Augusthus Pires Souto em 6 maio 2013 às 9:18

aqui no meu apareceu o seguinte erro:

sketch_may06b:16: error: 'time_t' does not name a type
sketch_may06b.ino: In function 'void setup()':
sketch_may06b:24: error: 'time_t' was not declared in this scope
sketch_may06b:24: error: expected `;' before 't'
sketch_may06b:25: error: 't' was not declared in this scope
sketch_may06b:25: error: 'second' was not declared in this scope
sketch_may06b.ino: In function 'void loop()':
sketch_may06b:33: error: 'time_t' was not declared in this scope
sketch_may06b:33: error: expected `;' before 't'
sketch_may06b:34: error: 't' was not declared in this scope
sketch_may06b:34: error: 'second' was not declared in this scope
sketch_may06b:37: error: 'hour' was not declared in this scope
sketch_may06b:38: error: 'minute' was not declared in this scope
sketch_may06b:66: error: 'startTime' was not declared in this scope
sketch_may06b:66: error: 'now' was not declared in this scope

Como faço para consertar?

Comentário de Rafael Bovo em 28 janeiro 2013 às 17:45

Gostaria de saber se posso testar bateria de 9V e outras demais voltagens.

Valeu. Abraço,

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço