Thanks..
I'll try the 1Megohm resistor in series with the analog input pin. Anyway, first, I'm attaching a photo of the monitor mounted onto the dash of my 4wd car.. I'm also attaching the schematic of the input for the battery monitoring..
I've worked out that a 16v voltage across the 22k/10k resistors generate around 0.0005 amp current.. Given that the 10k resistor drops 4.12v the extra resistance is in parallel to that. I've worked out that you need a 47k resistor in parallel with the 10k one to drop the voltage down to 4.12v instead of 5v. So the analog input appears to have a 47k DC impedance.
The code to set up and initialise is as follows:
/*
4WD Car Battery Voltage, Temperature and Charging monitoring.
The circuit uses two analogoue inputs to monitor the Main Battery and Aux Battery
The circuit uses one analogoue input to measure the current in/out of the Aux Battery via a CS-200A
Hall-Effect Current sensor board.
The circuit also implements a one wire protocol to read the temperature from three Dallas
DS18B20 Temperature Sensor and display the temperature in degrees celcius. Two sensors
monitor the two batteries(Main and Aux), whereas one monitors the outside temperature.
The code also uses the EEPROM memroy to store the Highest/Lowest temperature read from the outside
temperature sensor.
The circuit:
A0 - Main Battery
A2 - Aux Battery
A3 - Anaologue Current In
8 - Digital Pin for resetting Min/Max Outside Temperature
6 - Digital Pin for One Wire Protocol
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground */
// include the library code:
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <EEPROM.h>
// One Wire Bus is plugged into digital pin 6 on the Arduino
#define ONE_WIRE_BUS 6
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of Dallas Temp sensors.
// In LC DeviceAddress mainThermometer = { 0x28, 0x45, 0xF6, 0x9A, 0x03, 0x00, 0x00, 0xA4 };
// In LC DeviceAddress outsideThermometer = { 0x28, 0x6F, 0xF5, 0x9A, 0x03, 0x00, 0x00, 0x93 };
// In LC DeviceAddress auxThermometer = { 0x28, 0xA2, 0xDC, 0x9A, 0x03, 0x00, 0x00, 0x4D };
DeviceAddress mainThermometer = { 0x28, 0x08, 0xC0, 0x9A, 0x03, 0x00, 0x00, 0x83 };
DeviceAddress outsideThermometer = { 0x28, 0x03, 0xEB, 0x9A, 0x03, 0x00, 0x00, 0xF3 };
DeviceAddress auxThermometer = { 0x28, 0x37, 0x8E, 0x82, 0x03, 0x00, 0x00, 0x25 };
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int numMainReadings = 10;
const int numAuxReadings = 10;
const int numAuxAreadings = 10;
int readingsMain[numMainReadings];
int readingsAux[numAuxReadings];
int readingsAuxA[numAuxAreadings];
int indexMain = 0;
int indexAux = 0;
int indexAuxA = 0;
int mainTotal = 0;
int auxTotal = 0;
int auxAtotal = 0;
int mainAverage = 0;
int auxAverage = 0;
int auxAaverage = 0;
int MainBattSensor = A0;
int AuxBattSensor = A2;
int AuxCurrentSensor = A3;
int AuxCurrentRawValue = 0;
int AuxCurrentValue = 0;
int MainBattValue = 0;
int AuxBattValue = 0;
float mainBattVolt = 0;
float auxBattVolt = 0;
float tempC;
// Ratio is 16v/1024
float Ratio = 0.015625;
long previousMillis = 0;
long interval = 1000;
char buf[20]="";
char tempS[20]="";
char tempT[20]="";
float maxTemp = -100;
float minTemp = 150;
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
//Define new custom LCD characters
#define UPARROW_CHAR 4
#define DOWNARROW_CHAR 5
#define DEGREE_CHAR 6
// EEPROM Addresses
#define MIN_TEMP_ADDRESS 0x00
#define MAX_TEMP_ADDRESS 0x01
#define RESET_MINMAX_PIN 8 // button to reset the stored values in EEPROM
//Matrix for new customer charactes
byte uparrow[8] = {
B10100,
B11100,
B10100,
B00001,
B00001,
B00001,
B00000,
};
byte downarrow[8] = {
B10000,
B10000,
B11000,
B00010,
B00101,
B00101,
B00010,
};
byte degree[8] = {
B00000,
B00000,
B10011,
B00100,
B00100,
B00100,
B00011,
B00000
};
void setup(void)
{
Serial.begin(9600);
setupLCD();
lcd.createChar(UPARROW_CHAR, uparrow);
lcd.createChar(DOWNARROW_CHAR, downarrow);
lcd.createChar(DEGREE_CHAR, degree);
analogReference(DEFAULT);
pinMode( RESET_MINMAX_PIN, INPUT );
digitalWrite( RESET_MINMAX_PIN, HIGH ); // internal pull-up - switch will pull low to indicate reset
minTemp = EEPROM.read( MIN_TEMP_ADDRESS );
maxTemp = EEPROM.read( MAX_TEMP_ADDRESS );
// Start up the One Wire library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(mainThermometer, 10);
sensors.setResolution(outsideThermometer, 10);
sensors.setResolution(auxThermometer, 10);
// initialize all the array readings to 0 for the Main and Aux battery arrays
for (int thisMainReading = 0; thisMainReading < numMainReadings; thisMainReading++)
readingsMain[thisMainReading] = 0;
for (int thisAuxReading = 0; thisAuxReading < numAuxReadings; thisAuxReading++)
readingsAux[thisAuxReading] = 0;
for (int thisAuxAreading = 0; thisAuxAreading < numAuxAreadings; thisAuxAreading++)
readingsAuxA[thisAuxAreading] = 0;
digitalWrite(MainBattSensor, LOW);
}
void loop()
I'll post my results once I've tried the 1 Megohm resistor, but I find it still strange that the analog pin does this..
Rgds,
Simmi
