Hello,
I am working on project of charging battery using AC voltage and I need to display the current voltage on the battery on LCD Liquid Crystal.
please point me to right direction
Thank you
How are you doing this?
You'll probably need to convert the AC to DC, and then charge it using something like this.
If you feed the +V of your battery into an analog pin of your arduino, and the GND into GND. As long as the battery is less than or equal to 5V, you'll be fine.
Good Luck!
baum
Charging a battery using AC will probably be difficult, I suppose you mean charging with a DC power supply connected to main (AC).
As long as the voltage is lower as 5 volt you can wire the plus-pole directly to one of the analog-in pins, the negative to ground and use the analogRead-function to measure the voltage. The output will be a number between 0 and 1023, 0 measuring nothing, 1023 measuring 5 volt. Each unit roughly translates to an increase of .0049 volts.
When it's higher as 5 volt you'll need a voltage divider. That can be made with 2 resistors.
+12V-+
|| R1
+----- Arduino analog-in pin
|| R2
Gnd-- +----- Arduino-GND
By using a 7K-resistor as R1 and a 5K-resistor as R2 in this example, the analog pin won't read a higher voltage as 5 volt.
Units read... now translate to 12v/1024 each, which allows you to calculate the voltage of the battery.
This is just an theoretical example, in practice it's probably best to be able to read a 15%-20% higher voltage. When charging a car battery I'd keep R2 the same, but use a 10K-resistor for R1.
You could also use a 50K for R2 and a 100K for R1, it's just a matter of the right balance.
Current will directly flow through the resistors though. Using smaller resistors will use more power and... might heat up.
Hey Simpson_Jr
Thank you for help, it totally worked fine, and thank you for explaining in detail
just what I was looking for, thank you baum also.
I have another question, now that I can display the voltage of the battery, now I need to display the operating frequency of a circuit,
for testing purpose I can use Frequency Generator and display that frequency on LCD using Arduino,
please guide me
Thank you.
Ha,
Unfortunately I don't know much about frequency counting, when it's digital you could configure a pin as input and use the PulseIn()-function, it counts the time a signal is high (or low). Using that info you could
calculate the frequency.
http://arduino.cc/en/Reference/PulseIn
When it's analogue I'd have a lot of reading to do and probably still give you a wrong answer XD
With some more info on what... signal you'd like to sample, which frequencies you expect etc. I guess the more-experienced folks here may be able to help you further.
When it's analogue I'd have a lot of reading to do and probably still give you a wrong answer
If he doesn't need xtreme precision, he can use an op amp comparator to turn the analog voltage into digital pulses when the analog voltage is above a certain threshold.
Hey,
talking about analog and digital signal, for the voltage display, I tried using 3 different voltage source
DC power supply set to 9V
2nd 9 Volt big batter, and
9v small Panasonic battery. I had to do different setup for all three.
and about the frequency we will be operating around some where in 170 KHz, it could be different but I am guessing it would be aroud tht.
I will try out with PulseIn function.
I will try out with PulseIn function
Just remember that you have to have either a stable and known duty cycle to calc freq from one pulse, OR measure both low and high pulses and add them together.
Rob
zit1343:
and about the frequency we will be operating around some where in 170 KHz, it could be different but I am guessing it would be aroud tht.
I will try out with PulseIn function.
It's probably beyond the capabilities of PulseIin(), it mentions durations of 10 Microsecond to 3 minutes. That translates to 50 KHz as highest measurable frequency. (1sec / (HIGH+LOW))
I'm working on a project which also needs to measure higher frequencies, a capacative moisture sensor.
My idea is using a binary stage counter like the CD4020, 4040 or 4060 as frequency divider. Those can handle several MHz and by choosing the right output pin I should... be able to divide the frequency/increase pulse length by 2,4,8,16,32 up to 16384.
Before you start building, I did pick up this hobby again quite recently after many years though, so I wouldn't mind hearing whether this is a correct approach
Using a 40xx is a good way to go.
You could also use the hardware counting feature of a timer but this will get you out of the Arduino environment.
Rob
I was reading on frequency counting and I found this article, I think it is pretty good
might help someone else who is following this thread
http://tushev.org/articles/electronics/43-measuring-frequency-with-Arduino
but I rather start from scratch and learn, I am still at home, when I get to lab, I will test out what you suggested me, I will try out pulseIn function but at low frequency just to see how it would show on my LCD or serial monitor.
Simpson_jr, sure I will keep it updated, how it works out and thanx for your help again.
Graynomad, could you tell me what is 40xx, I am just using Arduino for displaying and counting stuff, my circuit is main circuit is separate, it is on high voltage around 170 voltage, I wish I know the operating frequency but we are still not at the point to find out the operating frequency for efficiency.
could you tell me what is 40xx,
The CD4020, 4040 or 4060 chips that Simpson_jr mentioned.
If you feed you raw frequency into one of them you can more easily count high frequencies.
Rob
Hey guys
I am making small progress in this frequency display part,
here is what I am working on
I am using Square wave as input and trying to just display that for right now
I am using pulsein function
input as follows
Freq = 100 Khz
Ampl = 1.00 Vpp
Offset = 1.00 Vdc
Duty Cycle = 50 % <<(Won't change in future)
int pin = 5; // digital pin
unsigned long duration;
void setup(){
Serial.begin(9600); // start serial communication
pinMode(pin, INPUT); // init pin
}
void loop(){
Serial.println("Comes here !");
duration = pulseIn(pin, HIGH);
Serial.println(duration);
delay(500);
}
output I get is
4 at 100 KHz
6 at 91
7 at 66
8 at 56
10 at 49
549 at 900 HZ
994 at 500
4970 at 100
49701 at 10
82834 at 6
12425 at 4
0 at 1HZ
I don't know whats going on here, it know it is displaying duration but I don't understand it.
Those numbers make sense.
PulseIn measures the duration of the high or low part of the pulse, not the full iteration of the signal. A 100Khz square wave with a 50% duty cycle will be high or low for 5 microseconds... 4? It rounded down. 4970 at 100 Hz? that's 9940 micro seconds for the full cycle. That's close.
The last 2 are way off, and probably because println() is trying to format it and number is too big.
try:
char text[20];
sprintf(text,"%lu",duration);
Serial.println(text);
At least I think that will work... I haven't used Serial.println() in a while because it's a blocking call.
I tired tht I get this
4 at 100 khz
10 at 50 Khz
499 at 1 Khz
993 at 500 hz
4970 at 100 hz
49701 at 10 hz
0 & 99399 at 5 hz
0 at 1 hz
so this is duration / time, and I am trying to display the frequency itself,
and this duration is for HIGH and it is in microseconds
what should I be doing to display total frequency
I read from what other posted to add both HIGH and LOW and divide by 1
so should I write another code for low duration and add both duration and divide by one?
Thank you
As frequency increases, the time a pulse is low/high decreases.
At 100Hz it's 100 times high and 100 times low each second.Each combination will take 1sec/100 or 0.01 sec.
A single High or low will take half that time, 0.005 sec. 4970 (microseconds) in your example roughly is 0.005 seconds
To calculate the frequency we first need to know the duration of a complete pulse, high and low.
That's roughly.... 0.005 sec + 0.005 seconds = 0.01 second.
Now we have to know how many complete pulses fit in one second to get the frequency.
1 (sec) /0.01 (pulse length) = 100 Hz
You could also use the outcome directly, but have to increase that 1 second to microseconds as well
4970+4970 = 9940 microseconds
1.000.000 (microS) / 9940 = 100,603 Herz.