Microcontrollers > Microcontrollers/General

Getting started with UNO

<< < (2/4) > >>

MattM:
Thanks for sharing!  Very good information.

OperaHouse:
                       MAKING A VOLTAGE DIVIDER FOR THE A/D

Measuring voltages with a micro is complicated by the voltages we want to monitor
are generally higher than the A/D limit of 5V. Voltages can be scaled down by use
of a resistive voltage divider.  This can be complicated because it involves some
math and standard values may not be in your junkbox. I've racked my brain for a
simple way to come up with these values. What are we cavemen? The internet always
has someone that will do the work for free. I came up with this website, there are
many others:

http://www.raltron.com/cust/tools/voltage_divider.asp

For any voltage divider you have to know three items to calculate the fourth.  R1
is the upper resistor connected to the battery to be monitored.  R2 is the lower
resistor.  We start with the output voltage going to the A/D.  That can't be more
than 5V.  I choose the voltage of 3.3V for two reasons. (1) That gives a reasonable
count of about 750 for your calculations with some headroom. (2) On the UNO board
there is a 3.3V pin that can be jumpered to. This will allow testing of the software
without connecting the micro into the final circuit.

The input voltage is the normal battery voltage.  Use 13V for a 12V system, close
enough for this example. Now a value for R2 has to be decided.  That usually depends
on what can be found in the junkbox.  A value between 10K and 22K is a good start.
My circuits always have a pot in the middle of the voltage divider with the wiper
going to the A/D.  I use integer math for speed and it is difficult to get the exact
multiplier to get the numbers to come out right.  The value of that pot is usually
between 10% aqnd 25% of R2.  The lower the better for fine adjustment. I have a box
of 5K pots so I use them. 4.7K is the new standard now. Whatever pot you use, take
about 1/2 of that value and add it to your selected R2 resistor.  A 5K pot would give
you 2.5K.  Add the 20K of the lower R2 resistor and the value for R2 in the calculator
is 22500 ohms. Follow the instructions on the web site to find the missing resistance
of R1.

To compute R1 enter Input Voltage, R2 and Output Voltage and then click Compute button.

The computation comes up with 66K.  Now subtract that same 2.5K and that is 63.5K.
Closest standard R1 resistor value is are 62K. Resistors in series will add. Don't
have a 62K, just put a 36K and 27K in series for 63K. Add as many resistances in series
that will add up to a close value. I always want to see a R1 value of at least 50K to
prevent excessive current to the input pin.  The value of R1 is less critical than
the lower value R2.  Always add at least a .1uF to ground from this pin to filter out
noise and provide a low source impedance for the A/D.  Measuring the 18V power point
of a solar panel, R1 is increased to 100K.

As tested with a 13V input and the above values, the pot voltage adjusts from 2.94
to 3.58 volts.

I believe in using what you have.  In this application a pot is used as a proportional
device. A 50K or 100K could be used just as easily by paralleling in a resistor across
the two outside contacts of the pot.  Standard resistor values of 5.1K or 5.6K would
likely work.  This is commonly used in industry since pot resistances can easily vary
20%. Using a high resistance pot with a parallel low resistance makes these dividers
more repeatable from one device another. This web site also has a calculator for paralell
resistance.  These are much faster than entering them on a calculator.


There are two pitfalls that can happen with the A/D converter. The A/D converter uses
the 5V of the on board regulator as the reference voltage. If you develop software using
the USB connector power, the numbers will change slightly when the on board regulator is
used to power the board. Even if the onboard regulator is powered, the source with the
higher voltage will dominate.  With my refrigerator those few counts changed it a couple
degrees. I ended up cutting the +5V wire on a USB cable so calibrations would not be
affected.

My camp system turns completely off at night and runs directly off panel power. The 328
micro in the UNO can run with only a few volts of power. At early dawn it will start
running with less than 3V on the 5V power supply.  This can cause all your voltage based
calculations that use A/D data to be way off.  This condition doesn't last a long time.
I use a 15 minute timer to delay any critical decisions till the sun is higher. That
delay ends long before the solar panels can put out any meaningful power. There are
other ways to accomplish this, but a time delay is simple to implement.

We often forget that this micro chip costs less than a buck. The A/D is ten bits with
some noise thrown in for free. You can count on any reading varying by about 5 counts.
Order emerges out of chaos.  Average a number of readings and that becomes a fairly
stable number.  Quite a few readings can be taken in a fraction of a second and the
world won't change much in that time.

DamonHD:
As a side note it is also possible to work out what the supply voltage is completely within the chip in the UNO (no external components, I do it for my boards) and that's another way you could put off taking critical measurements until the supply is stable.  I can share the code if that helps.

Rgds

Damon

george65:

Wrote out a descriptive message about the boards I bought arriving today and my dissapointment in not being able to get the LED blink function to work.
These were what I got.  http://www.ebay.com.au/itm/162279989265?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

I did finally work out I had to upload the CH 340 driver which I did and got the board to recognise in the ports.  Felt frustrated I couldn't get the damn LED to blink though. Checked out the board with a high powered magnifier and see the only LED is an ON  indicator and nothing else in place although proviso for it.

Didn't have any LED's in the box so I finally got the bright Idea of testing pin 13 with a multimeter.
Yep, can see that it is "blinking" voltage on and off and when I hold the reset button it stops till I let go then resumes. Now I'm a happy man.

I have bought a kit I'm waiting on with wires and shields etc to get me started but I have taken the most baby steps so far.
The blink I loaded was the one above so now double chuffed I got that to work.  I saved it in my library and am now getting messages about that but it does seem to be working none the less.

I have bought some Arduino compatible small relays and some SSR's today so waiting for it all to arrive as my Christmas Gift to self.
Guess the wife will be happier about me playing with these than Diesel engines in the back yard.  :0)

OperaHouse:
I needed another guinea pig.  This is the kind of information getting started needs.  What board did you select in tools.  Try all the ones with 16mhz and 328 in the name.  I had the same problem with my NANO boards.  Think they worked with MINI PRO 328 16M. The CH340 screws up the chart as it is not an actual copy of the uno, just in board dimensions.  If that works you will be all set to use the cheap NANO.  It could be that the driver was not actually loaded so it could be accessed.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version