Tronixlabs Support Forum
Sign up Latest Topics
 
 
 


Reply
  Author   Comment  
BennyBoyW

Junior Member
Registered:
Posts: 16
Reply with quote  #1 
Hi - It's that time of the week again where I get completely baffled by whatever I am doing on an Arduino. 
I'm on Project 6 this time - Single Cell Battery Tester
I believe that I have followed the schematic, but I am getting random lights lighting up. 
In the attached photo, t   he two wires at the bottom right are what I was hoping to connect to the positive (white wire) and negative (black wire) terminals on the battery.
The array of mad resistors at the bottom are my attempt at creating a 2.2K resistor with 2*1K and 1*200 resistors.
There's no 5V input to the breadboard - as per instructions in the schematic.
I have a wires going between each of the negative sites of the LEDs and then to ground (though these are not clear on the photo).
I have amended the code to bring in a serial monitor, and I am getting seemingly random values with it when I was expecting to get zeroes with no battery connected. As a result of these random values, the lights are lighting up randomly. 
ARGH !  Perhaps I should just admit that I am no good at this [confused]

2018-01-21 14.33.30.jpg 

The code is as follows, but I think the problem is in my wiring

#define newLED 2
#define okLED  4
#define oldLED 6
int analogValue = 0;
float voltage = 0;
int ledDelay = 2000;
void setup() {
  pinMode(newLED, OUTPUT);
  pinMode(okLED, OUTPUT);
  pinMode(oldLED, OUTPUT);
  Serial.begin(9600);
  
}
void loop() {
  analogValue = analogRead(0);
  voltage = 0.0048 * analogValue;
  Serial.println(voltage);
  if (voltage >= 1.6)
  {
    digitalWrite (newLED, HIGH);
    delay (ledDelay);
    digitalWrite(newLED, LOW);
  }
  else if (voltage < 1.6 && voltage > 1.4)
  {
    digitalWrite (okLED, HIGH);
    delay (ledDelay);
    digitalWrite (okLED, LOW);
  }
  else if (voltage <= 1.4)
  {
    digitalWrite (oldLED, HIGH);
    delay (ledDelay);
    digitalWrite (oldLED, LOW);
  }
}

tronixlabs

Avatar / Picture

Moderator
Registered:
Posts: 800
Reply with quote  #2 
if you're not testing battery - the value will be random. When an analoge input is being monitored but not connected to anything, it can be affected by random charge in the air, external devices such as fluorescent tubes etc.
What happens if you test (for example) an AA cell?

__________________

- Support always available for our products - email support@tronixlabs.com

BennyBoyW

Junior Member
Registered:
Posts: 16
Reply with quote  #3 
Thank you for the reply and help. 

If I test an AA battery, it seems to remain random. It certainly doesn't give a consistent reading that you would expect from a battery.

Thanks
Ben
tronixlabs

Avatar / Picture

Moderator
Registered:
Posts: 800
Reply with quote  #4 
Quote:
Originally Posted by BennyBoyW
Thank you for the reply and help. 

If I test an AA battery, it seems to remain random. It certainly doesn't give a consistent reading that you would expect from a battery.

Thanks
Ben


If you short the probes, does it return zero? Or close to it?

__________________

- Support always available for our products - email support@tronixlabs.com

BennyBoyW

Junior Member
Registered:
Posts: 16
Reply with quote  #5 
Hi
I shall check that when I get home from work tonight.
BennyBoyW

Junior Member
Registered:
Posts: 16
Reply with quote  #6 
@tronixlabs 
Apologies for the delay - work went a bit crazy. 
I just tested the shorting of the probes and it reads a consistent zero. 
So I tried it on a battery again and the reading is also consistent. 
I think I assumed I had got it wrong because of the slightly random nature of the lights when nothing is attached. 
Is there any way to force the circuit to read 0 if there's nothing attached ?  Or would it be better to introduce a push button to tell the circuit when I am wanting a reading ?

Thanks so much for the help
Ben
tronixlabs

Avatar / Picture

Moderator
Registered:
Posts: 800
Reply with quote  #7 
Quote:
Originally Posted by BennyBoyW
Apologies for the delay - work went a bit crazy. 
I just tested the shorting of the probes and it reads a consistent zero. 
So I tried it on a battery again and the reading is also consistent. 
I think I assumed I had got it wrong because of the slightly random nature of the lights when nothing is attached. 
Is there any way to force the circuit to read 0 if there's nothing attached ?  Or would it be better to introduce a push button to tell the circuit when I am wanting a reading ?

Thanks so much for the help
Ben


Not via software, adding a button would be the solution. 

__________________

- Support always available for our products - email support@tronixlabs.com

BennyBoyW

Junior Member
Registered:
Posts: 16
Reply with quote  #8 
Cool - thank you again for the assistance
badbunny

Junior Member
Registered:
Posts: 9
Reply with quote  #9 
Hi Ben, when I did this project I ran into the same issue and after reading about it found that the solution is to add a pull-down resistor between the +ve battery wire and ground. Then when there is no battery attached the A0 pin is at definite zero (ie ground) rather than a floating voltage. Also I think a diode should be fitted to prevent reverse polarity which I think (?) will damage the Arduino.

Pete.
BennyBoyW

Junior Member
Registered:
Posts: 16
Reply with quote  #10 
Hello Pete
Interesting that you mention a diode to ensure the current is only flowing one way.
I was under the impression that an LED being a type of diode it would do the same job as a standard diode in ensuring that the current  would only flow one way.
I might be completely wrong with the above, but I would love to know for certain.
badbunny

Junior Member
Registered:
Posts: 9
Reply with quote  #11 
Hi Ben, I think you are right, a LED would do the same. The battery is connected from A0 to GND, whereas the LEDs are connected to other Arduino pins, so won't affect the battery loop. The diode needs to be on the loop between A0 and GND, in series with the battery, to prevent its reverse polarity putting -ve voltage onto A0.

Pete.
BennyBoyW

Junior Member
Registered:
Posts: 16
Reply with quote  #12 
Hi Pete
You're quite right. I forgot the LEDs were on the "other" side of the circuit. That'll teach me for sitting at work trying to remember what the circuit looks like when it's actually at home lol.
So yes, an additional diode would be a very good idea and I will add one into my mix.
It's all becoming more complex every time I look at it - I have already doubled the number of LED indicators, added a voltage divider and am now looking at some form or rotary selection switch to select the type of battery you're testing.
Cheers,
Ben
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.