Archive for the i make things Category

Beehive scale build details. finally

Posted in attiny, avr, electronics, i make things on September 15, 2011 by makingthingswork

I’ve put this off for a while, but here’s all the details!

Summary: I made (and you probably can too!) a scale that is readable via USB with better than 1lb resolution for less than $50. I have been using it to track the weight of my beehive, and year-to-date, they have produced over 150lb of honey!

Long version (pictures/schematics/code near the bottom):
A while back, I hacked together a bathroom scale, instrumentation amp, and attiny85 to make a device that could weigh my beehive and report how much it weighed. It taught me a lot about electronics and bees, so i thought i’d share the details with everyone.

Surprisingly it was very inexpensive ($40-$50 US) for the parts, and has been working well for 9 months or so.

The project works as follows:

* An attiny85 (8 pin) is the brains of the operation, and uses the V-usb project to emulate USB. This is the interface to the computer. ~$3
* A standard bathroom scale is taken apart and wired up to the electronics, and placed under the hive. ~$25
* A 15′ usb cable has the end cut off of it, and is wired to the attiny. ~$5 (this is connected to the PC, for power and scale readings)
* A small fet used as a low-side switch turns the scale/amp on and off, to prevent it from warming up (probably not necessary), but also saves power ~$1
* an instrumentation amp (INA136 or INA138 i believe) amplifies the signal from the scale to the level where it can be read by the 10 bit ADC on the attiny. ~$6
* a fixed voltage divider (potentiometer) provides a reference for error compensation, and feeds into a different ADC channel ~$1
* when a read is requested, the attiny turns the fet on, waits a few seconds, then reads the scale and the voltage reference 32 times, and stores that data
* later, the results are read by the PC and graphed.

Weighing setup:
The scale is just a standard bathroom scale, which i removed the brains from and am using only the analog electronics… basically just the strain gauges and their attached wires.

The scale has a wiring harness which connects all the strain gauges, and terminates in 4 wires: E+, E-, S+, S-. E stands for ‘excitation’, and S stands for ‘sense’.

Apply a voltage difference across E+ and E- (eg 3V, 5V, or 10V), then read the voltage difference between S+ and S-. It’s very basic and quite simple. The main problem to solves is that the maximum difference between S+ and S- is about 6 mV, and needs to be amplified several hundred times to be usable on a 10-bit adc. The scale I got (cheapie on eBay) happened to report 6mV at the maximum reading, and go all the way down to 0mV as weight was added. I happened to get a little more resolution out of the scale by turning the gain up on the amp so that it read max ADC voltage at around 60lbs. Since the beehive will always weigh over 60lbs, this won’t impact my data at all and i get better resolution out of it.

Read some my other, older blog posts for more info, but i had to spend a long time calibrating the scale. the system has a /very/ strong temperature coefficient. I probably spend 5 weeks with the scale in the garage with between 45 and 90 lbs on it, trying to figure out how to get it to produce a flat reading.

In the end, I determined that the voltage swings were primarily due to the attiny, and by setting up a voltage divider to produce a fixed voltage, i was able to compensate for the fluctuations. With the current setup, i am able to get readings at about +/- .5 lb of accuracy, even though the resolution is much better than that. For the purposes of beekeeping, this is just fine. My next version will be much better, I hope :)

There are a few critical things i will do differently for my next scale (currently under design)
* get a really clean voltage source. The current model uses the 5v signal from the USB bus for power. This is a noisy signal, and may fluctuate with temperature (or it may be the voltage reference on the attiny). Any voltage fluctuation will alter the reading on the scale somewhat.
* I am also using the internal voltage reference on the attiny. This does not seem to be a good idea.
* don’t use the voltage reference or ADC on the attiny. It’s not good enough for precision work, at least in my experience. It also seems to have an affinity for even-numbered readings (eg binary numbers ending in 0).. so call it a 9bit ADC :)
* use an ADC with a low thermal coefficient, and/or built in voltage reference. I have been experimenting with a purpose-built chip from TI which is made to be a strain gauge ADC. It is 24bit and costs about the same as the instrumentation amp i used. So far it is working very well. This simplifies things somewhat.

Eagle files:
scale-no-vreg-2.sch
scale-no-vreg-2.brd

Code
hostcode.tar.gz libusb interface
tinycode.tar.gz attiny code

Some pictures:
Raw scale, showing strain gauges. Why yes, that is an old macbook power supply case

Ready for outdoor use

Scale is the yellow thing at the bottom of the hive.. sorry the picture is sideways

.. and some graphs:

Nice day in spring.. 5lb of weight (nectar/honey) gained
They made about 5lb of Honey that day

They swarmed.. 7lb of bees went out, 5lb of which were later recaptured

As of may, here’s a cleaned up graph of overall honey production

Single pin relay control

Posted in electronics, i make things on January 16, 2011 by makingthingswork

EDIT: The below schematic and circuit description are slightly incorrect – the PNP and NPN transistors should be reversed.

I am cheap when it comes to micro-controller pins. I don’t like using them if i don’t have to. I also don’t like throwing current around unnecessarily.

I was working on a project which i wanted to control a bunch of relays with my micro-controller, but didn’t want to dedicate 2 pins or an h-bridge to each relay driver. My relays were fairly small, and i came up with the following way to control them with a single (tri-state) pin, and some external components.

If you have a strong-ish pin driver or a low-current relay coil, you don’t even need the totem pole arrangement.

Background:

Relays work by putting a certain amount of current through an inductor, setting up a magnetic field that pushes a switch. A normal relay requires that current to be always on. Once you stop feeding it, it goes back to ‘off’ (or on, whatever the default is).  A Latching relay doesn’t have the spring or whatever to force the switch back once current is released. It acts more like a light-switch.

So, for a latching relay you need to supply a certain amount of current to get it to switch, then another amount in reverse to get it to switch back.

Relays usually specify the current needed to switch them, and the internal resistance of the coils.

The idea:

Use a latching relay with a capacitor behind it, sized such that it can store enough current to switch the relay back:

control-pin -> relay coil -> capacitor -> GND

you send 5v or whatever though the coil and the capacitor will start to charge up. That current is enough to switch the relay, so it turns on. As you leave the pin high, the cap will charge up and the current will drop off to zero. Once you are ready to unswitch the relay, connect the pin to ground, and the cap will discharge across the coil and switch the relay back.

If you have a big relay, small pin driver, etc you can add a NPN and PNP transistor pair in a ‘totem pole’ configuration to switch a larger amount of current.

Bingo! one pin, no excess current loss, and 1 (or 3) extra components.

Here’s a picture:

The switch at left simulates the microcontroller pin. The resistor and inductor simulate the coil of the relay.

Want to try it? here’s the falstad simulator code (See this link for how)

$ 1 5.0E-6 31.41906602856942 54 5.0 50
c 304 208 304 256 0 9.999999999999999E-5 4.4916891133897625
g 304 256 304 288 0
w 240 112 304 112 0
t 208 96 240 96 0 1 0.0 0.5013938559564375 100.0
S 176 112 128 112 0 1 false 0
t 176 128 240 128 0 -1 5.0 0.5013938559564375 100.0
R 128 96 96 96 0 0 40.0 5.0 0.0 0.0 0.5
w 176 128 176 112 0
w 176 112 176 96 0
w 176 96 208 96 0
R 240 80 240 48 0 0 40.0 5.0 0.0 0.0 0.5
g 240 144 240 176 0
r 304 112 304 160 0 135.0
l 304 160 304 208 0 0.01 5.129834965258037E-5
g 112 128 112 144 0
w 112 128 128 128 0
x 61 75 155 79 0 18 control pin
x 251 77 360 81 0 18 “totem pole”
x 347 190 424 194 0 18 relay coil
o 12 64 0 291 2.5 0.025 0 -1

Depending on the control voltage, you may need to add more resistance inline with the coil.

low-fi circuit simulation

Posted in electronics, i make things on January 16, 2011 by makingthingswork

I often want to play with some circuit or other, and am not sure if it will work.

For those of us who aren’t super strong on electronics theory, this means either we buy a bunch of parts and test it out, possibly frying them, etc OR do some sort of simulator. Unfortunately most simulators are somewhat complex (spice, etc)

I was pointed to a really nice java simulator that is online for free:
http://www.falstad.com/circuit/e-index.html

He has lots of examples, and you can edit the circuits yourself, add parts etc. I have learned a lot there.

For example, here’s how to simulate my DC motor speed control circuit:
1) go to http://www.falstad.com/circuit/e-ohms.html
2) right click in the black after java loads, and select file->import
3) paste in the following:

$ 1 5.0E-6 3.9121283998153213 53 5.0 50
R 112 224 64 224 0 2 400.0 2.5 2.5 0.0 0.5
g 320 256 320 272 0
d 208 128 208 192 1 0.3
t 176 112 208 112 0 1 -11.855891688647894 -0.016674669651078056 100.0
w 176 160 176 112 0
w 176 112 176 96 0
r 176 96 176 48 0 1200.0
R 176 48 128 48 0 0 40.0 12.0 0.0 0.0 0.5
w 176 48 208 48 0
w 208 48 208 96 0
w 208 128 272 128 0
f 272 128 320 128 0 1.5
w 320 144 320 256 0
w 208 48 320 48 0
f 176 224 208 224 0 1.5
l 320 112 320 48 0 4.0E-5 7.833859394512643E-8
w 320 48 384 48 0
w 320 112 384 112 0
d 384 112 384 48 1 0.805904783
r 384 48 432 48 0 2700.0
w 384 112 432 112 0
d 432 48 432 112 1 0.805904783
x 447 73 480 77 0 18 LED
x 266 167 355 171 0 18 Power FET
x 255 86 308 90 0 18 motor
I 112 224 160 224 0 0.5
w 160 224 176 224 0
x 7 260 111 264 0 18 PWM source
w 176 160 176 192 0
w 176 192 208 192 0
w 208 192 208 208 0
g 208 240 208 272 0
x 62 119 155 123 0 18 gate driver
x 345 136 470 140 0 18 flywheel diode

that’s it! pretty neat, huh?

You can easily make your own by doing file->import with a blank value, then right-click and add parts as you like. File->export will show the config you should save as a txt file if you want to save the circuit or come back later.

You can also copy the java class locally and run it without an internet connection. He updates it from time to time, so check back for new parts and features.

He also has some physics simulators which i haven’t tried, but are probably good, given the high-quality of his electronics site.

Concetrating parabolic trough – part 1

Posted in i make things, solar on January 16, 2011 by makingthingswork

I’ve been looking into solar for water heating and (less so) power generation. I’ve decided that i like concentrating collectors since there’s less to insulate.

I did some tests and decided that while a parabolic collector is great, you can make a ‘good enough’ collector with far less precise construction techniques. I like that. I’m terrible at making things accurately, especially when they can be subjected to nature, and made from wood or other materials (not necessarily straight).

I’m a big fan of ‘coroplast’, aka corrugated plastic sheet. It costs about $15 for a 4×8 sheet of the stuff and it has some great qualities. Most of it is polypropylene, and can be heat welded if that’s what you’re after.

The concept is like this:

Take a piece of wood and attach some plastic sheet to it on one side.

Build a riser about 3′ out and put a pipe or other support on it, which will force the plastic sheet up into a bent shape.

Build an insulated collection mechanism on the top.

This has several key benefits:

  • Small surface to collect. Small surface means less materials and less surface to lose heat from
  • Insulation above collector. Convection is the dominant heat loss mechanism in these collectors, and by keeping all the hot air below insulation, you will lose a lot less
  • ease of construction. Not much to it at all

The main drawback is that you will have to aim it periodically. Thats another post.

After reading some engineering pages, i learned that a cantilever subjected to a strain at the end of it (like proposed above) will form a parabola-like shape. This is apparently well known in amateur radio circles as a ‘stressed parabola’. To get a good focus, you need a long focal length. For solar heat, i think you can get by with a looser focus.

I figured out the math to calculate the focus points for this kind of curve, and within a 10degree arc of aiming (eg if 0 deg is aimed directly at the sun, a +/- 5 deg range) it focuses all the light at a 7-8″ wide spot about 18″ off the origin point (eg x=0,y=0)

So i did a ton of calculations, sought some feedback, and was told it wouldn’t work. So i built a little one. I took a 2×4 piece of coroplast and leaned it on a char, then measured the height every 10 cm. I then did a curve-fit and plotted the focus. It was not anywhere near the same equation as was predicted by the engineering data i had, but the curve fit was spot on just the same, and it gave a 6″ focus! That’s great.

I then built a rig which would be a little more like what i would actually use:

The plastic is attached at 3 points: base, about 1/3 and at the top. It was minimally forced into place, but the middle support was pushed down a little, and i attached them in this order: bottom, middle, top. I should have fixed the top and bottom then attached the middle as ‘insurance’. As you will see later, forcing the middle throws off the curve-fit.

Basic theory:

Every point on a curve has a tangent line, which is the line that just ‘kisses’ the curve at that spot. When a ray of light hits the curve, it will reflect as if it had ‘bounced’ off the tangent line.

The Tangent can be calculated as the derivative of the curve, which is basic Calculus, but isn’t really very difficult to do.

So, to calculate the reflection slope, you do this:

F(ts)=1/tan(2*atan(1/ts)-irad)

ts is the tangent slope. irad is the offset of the inbound ray from vertical in radians.

You can then calculate the y-intercept of the line, and plot it.

Here are some graphs:

The colored lines should show ‘inbound’ (eg top to curve), but i didn’t plot them backwards. Too lazy.

This graph shows where the focus of the reflections would be. As you can see, it’s a pretty tight focus, however the curve does not match as well for this setup, so will need experimental verification.

I should note that the plastic will be coated with some sort of reflective coating (reflective mylar, etc)

PWM DC Motor control circuit

Posted in electronics, i make things on January 16, 2011 by makingthingswork

I’ve decided to start posting some of my makings again. Not sure what it is about January, but here we are.

I picked up a few 12v DC motors with the idea of making a variable speed controller for them. DC motors lend themselves to it, by doing PWM and/or lowering the voltage. I may eventually make a variable voltage driver, but in my experiments, PWM works better, since the higher voltage puts more current and therefore more torque while it’s on.

Here’s the circuit:

This circuit switches ground on/off. The motor/pump should be connected to the +voltage , and the motor ground to the MGND line. Should work with just about any input voltage. I’ve used it at +5 and +12v. Different voltage will need different values for R3, if you have an LED.

The output is out-of-phase with the PWM input. The PWM fet should be a fast switching type, and the other FET should be a power FET. I used IRFZ34N for the power fet, and VN1304 for the switching FET (ignore the part # in the schematic, that was just to get the correct pinout)

Quick description:

R1, Q3, D1, Q2 form a gate driver circuit for the Power FET. When the PWM pulses high, the power fet is turned off. This means the motor is out of phase (opposite) with the PWM input

R1 prevents too much power from going from +12v to GND when the gate is pulled low

D2 is a flywheel diode, to contain any back EMF generated by the motor.

R3, LED1 are just an indicator, and is optional. R3 just sets the current on the LED.

C1 is optional and may smooth the PWM signal out, if desired.

C2 will smooth out the load on the power source. Recommended to keep it.

I have tested this on 12v motors, and it works great! I do recommend a heatsink on the power fet.

I used an arduino to drive a PWM pulse, and used a potentiometer to vary the speed.