Absolute Position Encoders are Crazy
Вставка
- Опубліковано 25 сер 2024
- This strange-looking disk is incredibly useful in determining the absolute position of a rotating disk. I plan to use it to create an anemometer, which is a device used for measuring the wind's speed and direction.
I hope you found this video interesting! If you did, please consider checking out my other videos :)
#encoder #windmill #anemometer #diy #3dprinting #3dprinter #3dprinted #creality #ender #ender3 #prusa #wind #windpower #homemade #fdm #manufacturing #engineering #engineer #electronics #electricalengineering #microcontroller #arduino #arduinoproject
That disk is a really interesting visualization of binary
I agree! It almost seems more intuitive than other methods of teaching binary.
@@christophersfactory im not sure what the normal method of teaching would be cuz i taught myself years ago but i could see someone learning with this
That disk basically just one and zero but somehow my brain not hurt looking at that 😭
They use this design to make rotary switches with multiple states. Each ring doubling the states. 1,2,4,8,16,32...
Mind blown 🤯
I am impressed that so many people knew about grey code, and why it is necessary for this application.
I am too honestly. I’m also impressed that I did enough research for this video to build a working prototype and had never even heard of it, but literally everyone else had 🤣
@@christophersfactory
Lots of electronic/digital techs about here it seems.
- The way things are with the 'throw away society', possibly lots of former/retired/ unemployed techs. 😞
@@jabberwocky1707 20 years at NASA in robotics, but not a tech. ;-)
@@FelonyVideos
Design Engineer then, or Project Management, or ...? Just wondering, don't need to be specific.
- You didn't have anything to do with those outstanding Mars rovers that went *_way_* beyond their original mission length?
- Maybe grey code is 'old hat' as there are possibly other methods to achieve position measurement?
- One method IIRC used for 3D sight positioning determination for HMSD (helmet mounted sighting devices) to aim missile/gun 'by eye', used pulsed magnetic fields of different frequencies so the axes (2 or 3?) can be discriminated from each other.
@@jabberwocky1707 first analyst, then designer, the project manager, then department manager, then independent consultant.
The supercomputer that we ran our simulations on was the best in the world at the time- it had an unheard of 64k of core memory. 😂
You should consider swapping to gray code to avoid synchonization issues between the bits. Otherwise you might run into miscounts.
The cool part is that the patterns are actually the same. Just by cleverly shifting them, you can make it such that only exactly 1 bit changes at a time. This eliminates read timing errors due to bits not physically toggling exactly simultaneously. Though this specific disk contains clock pulse ring which through additional hardware also eliminates read timing errors.
I suppose, not every gray code is easy to 3d print
@@JohnIdlewood Gray codes are easier to 3d print actually, because only 1 hole can appear at a time and everything else is still solid.
Yes. Most directional anemometers use a potentiometer. Lowest resistance value is set to north and you can calibrate direction based on the resistance.
You should use gray-code for the disk and convert to binary in the microcontroler. Your binary disk needs multiple sensors to switch exactly at the same time, which will never happen in practice. Gray-code only has one bit change for each angle so the sensor data is always consistent.
WHS
I approve this message.
Came to say this!
plus in grey code you always know where you are right now even if the disk stops between 2 segments (it will either put out the left or the right portion of where it stops). here in this disk the sensors will give out arbitrary values and you wont be able to know which portion you are on right now
Compass sensor. CDS cells old hat analog. Too many wires and sensors.
There is a simpler way, but please continue. I want to see it work.
Yeah. Watched then and started laughing. I do think it will work but I remember in College they said unread better to use a different encoding order wherein no more than one bit changed per step.
Am I on the right track?
@@jeromewink557Yes you are on the right track! With regular binary encoding, multiple bits will change on each angle and unless all of the sensors switch state at the EXACT same moment, there will be wildly off false readings during the transition between angles. That specific order of code where only one bit changes per angle is called Gray code, or Gray encoding. :3
@@MarbleStarry which now that you have said that and I think about his design he’s going to need layer outside his ring with holes offset from the reading that he can use as a trigger. Or he needs to offset his LSB to slightly trail the rest of the disc and use it’s bounced been logical 1 and 0 as a trigger to read the value.
Make the outer ring of dots a smidgen smaller, and make a latching circuit to enable 'valid position' detection during the rotation. This would eliminate transitional errors. Also, key the center of the hole so the shaft is fixed to the shaft in a way that cannot slip or be out of alignment.
@@frankens43 I was thinking the outer holes were there exactly for that purpose.
Trial and error will show they are small enough.
Use gray code: now say between "south" and "south-southwest" all bits will change. In practice that doesn't happen exactly at the same time. Thus you'll get a bunch of other directions when the vane goes between those two states. Gray code has only ONE change every transition, thus when it is somewhere in the middle between two states, it'll show one or the other but not a totally different state.
And there is a simple circuit that will convert gray code to binary.
Also you can save some diameter by putting the sensors for the highest bit and second highest bit on the same ring, but 90 degrees apart.
Why you have the sync in the outer ring ...
@@MorsDengse If gray code is used you don't need sync. The outer ring could be used to double the resolution, or eliminated to make it more compact.
@@GordieGii Im certainly not disputing that, just noting why the outer ring is there, as it wasnt mentioned.
On another note. No one in their right mind would use such a contraption today : )
@@MorsDengse The sync signal is an obvious solution for someone who is ignorant of the existence of gray code, which the OP admits he was.
My first thoughts for angle sensing would be a magnetic sensor. Not exactly sure what they are called, but they used the Hall-effect to sense the magnetic field.
Cool! A Gray code encoder might be more durable.
Wow! I can't believe I've looked into these encoders this much and haven't seen a Gray Encoder. That looks dope, thanks for the heads-up!
Grey encoding was my first thought, then I saw that it was binary ^^
@@christophersfactory You could go with just 4 sensors. 2 grey code for the four compass points and the other 2 for quadrature (incremental) in between. But then you would have to implement a quadrature decoder. (circuit or software)
@@christophersfactory Another thing that'd be much easier to manufacture would be essentially a potentiometer. To the shaft, add a disc with an inner and outer copper brush (a little bent strip of copper will work), connected with copper wire. Add a second (fixed) disc on a bearing, on it, have a copper wire/plate circle that the outer brush fully touches, regardless of rotation. On this outer ring you put some input voltage. For the inner ring, use graphite or resistive wire or so. Make sure this ring has a tiny break in it Connect a copper wire to this ring at the break. Now you can measure the resistance between the two wires dependent on axis position. Make a voltage divider with a resistance that fits your purpose. If your ring has a resistance from 0-100kOhm for example, you could choose a 10kOhm resistor to divide with to get an output voltage between 0 and 89%. You can read this on an analog pin and by measuring different points (careful: Not linear!) you can create a map/approximating function that calculates angle from voltage.
Imo easier to build and you can make it much smaller and can be useful if you have few digital pins available. Downside is, you need an analog input or ADC. Also, the longevity will be much shorter than your photo resistor approach which is why I think your approach is better for your use case. Just be aware that the accuracy is fully determined by the angle of the slots on the outermost ring, which in your case is ~3 degrees. You can also get significant jitter if the direction changes on a boundary of a slot, meaning your readings could look like 3°,6°,3°,6° even if the actual direction barely changes. If that is good enough for you, perfect!
@@xXIkaron potentiometers are kinda ugly for this, especially compared to photodiodes.
You should swap the encoding out with a Gray encoder. Those rearrange the binary numbers so that each transition always only changes one bit, instead of binary where multiple bits flip. This is used for disc encoders to prevent intermittent wrong signals when multiple bits flip and not all sensors are crazy perfect aligned (which they never are)
also is should allow for a more supportive structure.
The main issue with this approach js the noise. If your bits don’t flip at the same time, you will read a bunch of odd angles during transitions. There are ways to fix that though. Easiest is to reorder the numbers so that only one bit changes at each transition. It is easy to build that sequence recursively for any number of bits. You might want to look up Hamming Distance. It is used in error detection and correction.
To determine direction you only need to signals A & B slightly offset by ~20 deg. And two LDRs.
If you see AB..AB..AB.. thats one direction, if you see BA..BA..BA thats the other direction. And by counting A only you can also determine RPM / speed based on the circumference at location A.
That (incremental encoder) just tells you what direction the encoder has moved, not where it is. You can track an incremental encoder to kinda fake an absolute one with a dead reckoning sort of mechanism, but absolute has advantages like it just telling you the state (position) without needing any zeroing/calibration, and not needing any memory to track the absolute position from step deltas.
@@treelineresearch3387 That is true, but the stated intent in the video was just determining direction of rotation.
@@DejitaruJini thought he was just looking for the angle of the wind and not the direction of rotation.
@@jamesharrell4360 After re-watching, yeah, I retract my statement; my mind interpreted "direction" as in _motor_ direction (where you'd usually find such an encoder disc) instead of _cardinal_ direction. I imagine the commenter at the top of this thread made the same mistake.
When I built one in class, I used two offset sensors on a one bit wheel for direction and change, plus a third sensor for passing North . The wheel was 2D printed on transparent plastic, 3D printing neither needed nor invented . A reflective paper disc would have been even simpler, but the class was focused on writing the code .
You should have used grayCode instead of simple Binary. Therfore you don't have errors on the boundaries, which you will probably have now if the angle is near the pattern change..
Gray code is also recommended to make sure only 1 bit changes during a transition
I was going to mention it as well, that one bit change per digit is really useful on stuff that moves quickly. They use it a lot for government radar dishes because of the reliable speed and precision they provide.
For those who are wondering what "Grey Code" is:
Grey Code is a binary system (1,0) where only 1 bit changes between each step/element (Only 1 change, unlike normal binary which can have multiple changes between each step/element).
Example:
Binary: Grey Code:
7 = 0111 7 = 0100
8 = 1000 8 = 1100
As one can see, in Binary, 4 bits change when it goes from 7 to 8 (First Zero changes to a 1, and the last three 1's change to 0); Whereas in Grey Code, only 1 bit changes when it goes from 7 to 8 (Only first zero changes to 1)
An easier way to tell which way the wind is blowing?
I put a rag on the end of a stick. I call it my Fluctuating Lateral Air Gauge or FLAG for short.
;)
But the binary thing is pretty cool too.
Incremental encoder with a and b signals with proper offsets. Uses a 3rd of hardware and is easier to print and fabricate. Obviously what you did is really cool. Nice job
How will the microcontroller know the absolute direction of the weather vane?
@@Graham_Wideman You re absolutely right.
If it was on a motor, you could add a calibration vane , but this is supposedly free rotating in the wind.
You re not going to wait for a specific wind direction after every time you power this thing.
Yeah but after losing power in the system you no longer know the position of the encoder, also incremental encoders are loosing steps. It's good for some aplications like encoder in 3d printer for screen control, but it won't work in getting position of stepper motor in 3d printer for example, it's too unreliable.
One issue with incremental is it only counts steps and does not give absolute position. Fine if you can A capture all the steps and B calibrate every time power goes out. However on power up the system has no idea what direction its pointing and just starts at 0. if you normaly consider 0 as north but you boot it up while wind is west its going to tell you its north.
Advantage of an absolute encoder is it does not mater what state its in. If its outputing a 10 and you know 10 = west it just works. you only have to figure out the alignment once.
@@merendell He said he wanted direction, not position.
there is a simpler way it's called a wind sock but this is awesome
The idea is to be able to know the wind direction without looking outside or being within range of sight of the measuring device (and maybe as cheaply as possible?).
Windsock and camera. Encoders are expensive because they’re typically used on servos/robotics.
Old school was a segmented ring with only one section energized and a series of contacts around the perimeter. The contact with power lit a bulb to show the wind direction. You don't need half degree resolution and hundred dollars in parts of the input is a wind vane.
wind sock on a potentiometer...
Wet finger works or looking at foliage or water…
if you just want to tell which DIRECTION the wind is blowing, have a transparent disc with a gradient printed on it. the resistance will either gradually increase and then suddenly drop and start over, or do the reverse. you could also tell the speed by how often those restarts happen and it will be more accurate because it happens only once per cycle.
Or just a potentiometer :)
Since photoresistors dont output a discrete voltage, why not just have a spiral inside the disk so you can get an analog reading from the row of resistors? So like 0 degree rotation would mean the furthest diode is the lowest, and 359 degrees the closest diode, the middle diode 180 degrees, etc
The simpler way is a variable resistor, but your solution has its merits.
Back in the day, Amiga mice worked using similar principle, but two bits was enough - six bits is an overkill.
An elegant solution, but it will have to be an endless potentiometer as the wind direction is not guaranteed to never make full rotations
Yes, you can use a single photo resistor and vary the thickness of the disk. So a single circle, progressively thinner, single LED pointing towards the resistor. Thickness of the disk blocks more or less light.
You could use more circles for more granularity, in the same vein of what you have.
You could probably achieve the same effect with a thin, single, or double layer on the bottom and use pin holes. So 120 deg with no layer, 120 deg with one layer, 120 with two layers (on the bottom). Instead of having large holes around the edge, each 120 deg segment has 12 sub sections where it's made of 0-11 pin holes. The light goes through the pin holes, hits the bottom layer, diffuses and creates a uniform but unique amount of light.
You could also use different colors of filament and different LEDs. Green filament absorbs mostly green light. So if you pointed an rgb led at the diffusion. Layer, a green filter would leave rb, red filter gb, blue - rg
Very smart use simple mechanics instead of complex digital methods. Basically bulletproof. Unless it would be subject to dirt or he plans to use sunlight for it. Wouldnt work then either
Elegant solution.
@@D3nn1sI think this is the first time I've ever seen an old comment and wasn't disappointed in myself
@@wilurbean in yourself? Did you come across the same ahort again while scrolling or what?
Your comment was very smart or sensible, so yeah :)
I've often found that in any gust of wind, there can be a flag placed within its path to best indicate its direction.
This many positions is good for telling exactly what position the disc is at. Also can be used to tell direction and speed at which the direction changes. Very nice.
I had also been interested in making my own anemometer at one point, but I felt that these ones where you measure something spinning might not hold up well. I did some digging and found out about ultrasonic anemometers. Because sound is transmitted through air and wind is air moving, that can make a sound wave travel faster or slower depending on the direction, I think. So the idea is that you could take two of these transducers, aim them at each other, and see how long it takes for the sound to travel between them, at least that's how I think they work. If you add another pair perpendicular to the first pair, then you can calculate the vector of the wind direction. You could even add another pair facing vertically and measure the wind in three dimensions.
I think these seem better than traditional anemometers because normally there would be some resistance to getting something spinning, so there would be a minimum speed that you could measure, but I think that an ultrasonic anemometer would be able to measure a lower wind speed.
I never actually did anything more on this project than research, but it will be neat to see what you do next.
We used very similar encoders like this in some navy equipment accurate to .1 degree. They were plated on a glass disk. And it used gray encoding to simplify timing. The key to gray encoding is that only one bit changes between each number.
Gray coding also helps with analog resolution. On optical encoders, you can read partial activations and get better instantaneous velocity readings (where you would otherwise need to integrate).
@@microcolonel I like the "self clocking" aspect of the gray code the most. A simple "or" gate of all the inputs, and you have your clock. No need to an extra clock input. On the design in this video, I think the holes on the outside edge are for clocking. But since that input needs to be narrower than the data bits, it just takes up more room and results in less resolution. In the same size disk with the same size bits, you could get at least one more digit of resolution if you changed the clock bit to a data bit.
Yes, rather than 3d printing this, it might be laser printed onto plastic sheet meaning it could be smaller, use a greater number of bits
I think this is mounted horizontally to give an absolute bearing of the wind. This is not connected to the blades to measure rotational velocity.
The binary code changes in direct relationship to the angular position.
No timing involved.
@@ahaveland Sorry, you miss understood what I was talking about. I was talking about clocking in multiple binary bits into some type of reader, like a microprocessor. If you study this wheel, there are 5 data bits and one clock bit on the wheel. The holes on the outside edge are the clock bits. When one those holes allows light to illuminate the sensor under it, all the other sensors should also be in position for reading, so the pulse caused by the hole can be used to clock in all the other bits. You can't just use the data bits themselves because more that one bit can change between one position and the next, but with gray code, only one bit ever changes, so you can use the change of data bits to act as the clock. All you need is a simple multi input 'or' gate connected to each input or a little code in the micro you are using. So, on the same size wheel, you can use that clock bit position as an added data bit and get 6 bits of resolution instead of 5. Wikipedia has a good discussion on gray code if you are interested.
There is math solution for optimal mecanical - numerical encoding. Gray code. If the disc was using piercings according to gray you can easily also determine speed and direction of the disk. With already available code.
Yes. You could have simply taken a senor and a wind sail. The wind sail turns when filled with air, showing you where the wind is coming from.
I think they normally use a sock type one for this device.
This thing you made would be good if you had a gear box for wind. You could have it swap gears as it moved to each faster ring on the sensor.
You didn't make a directional input, but a speed tracker
Don't forget to add a back light for consistent lighting conditions and add a north sign to the design so that you can mount it aligned with a compass.
Only 2 optical sensors are needed to determine direction. Both located on the outer set of holes. Place them 1.5 x the hole distance apart.
If sensor A goes high when sensor B is high you going CW. If sensor A goes high when sensor B is low your going CCW.
This is how optical encoders function.
Came to say the same
Yes, what you have described is a rotary encoder, but without any absolute reference it cannot tell you anything useful other than when it is spinning. Without a reference, you’d have to calibrate it every time it starts, and you’d have to ensure it never loses power, otherwise you’d have to calibrate it again.
The idea with an absolute position encoder is that it can always tell which direction it’s facing based on the physical layout of the disk. As long as it doesn’t get moved, 00000 will always be north, for example. I have another anemometer I made with a rotary encoder used in tandem with a limit/end switch. The switch gives it a reference, so that it can say, “Alright, any time my rotation closes that connection, I am facing north.” From there, the rotary encoder can tell how many clicks from that reference it has spun. It would still need to calibrate by making at least one full spin every time it turns on, though.
@@christophersfactory It counts stripes as they go by. It knows how many stripes are around the perimeter, so as long as it knows which direction it started in (sometimes encoders have a 3rd sensor for this) it can tell you what direction it's facing now. So that's a maximum of 3 sensors for arbitrary precision, rather than needing log2(precision) sensors.
Good idea but as people below point out you need an absolute reference. One way to do this would be to add a 3rd 'home' sensor on a second track. This would be easier and cheaper but would leave you with garbage data between power failures and when the wind passed through north again. Another option is a single track grey code (see Wikipedia on Grey code) it would require an extra sensor for the same precision but could be done with a single but elaborate track instead of the 5 or 6 here
One possible improvement: use gray code to encode the binary number. Gray code not just makes it easier to 3d-print, it also reduces the error, if any sensor has a wrong reading
Indeed, there are waaaaaayyyy simpler ways but like everyone else says, please keep going.
😇😇👍🏻🙏🏻
Easier ways, sure.. More interesting... Probably not. I have a question though. Are you going to create a compete weather station? You need to keep us updated.
Thank you!! Yes, a complete weather station is definitely in my plans. I’m trying out a whole bunch of different things right now to see what I think is promising. Glad you’re following along. Eventually, when I’m living in a larger space, I would love to have a self-powering, IoT weather station. Probably a little too ambitious for this little balcony though. 🤣
Yes you should simply just connect the weather main to a potentiometer and then read the resistance and set each direction to its resistance value and write a simple interpolation that way you only need one component rather than several photo resistors and a binary disc
A pot has way too much mechanical resistance for his application
That won't allow for an infinite 360° rotation. The correct part would be a rotary encoder
@@AchievedZeus574 360 degrees potentiometers exist
@@maquez650 yes 360 does, but not infinite. When the pot reaches its limit you can’t nicely ask the wind to change directions.
@@TheOfficialOriginalChad how do car stereos/climate controls etc work then? I guess they would need constant power in order not to loose their position, but that should work.
using Gray code lets you have an absolute encoder where only 1 bit changes at a time, which fixes the errors you would get on the edge case where 2 bits may have fuzzy edges read by the optical sensors.
I worked at a steel rolling mill and was in charge of the automation. The system was circa 1970 and used a couple dozen of these. They were high resolution and each one cost around $12,000.
You basically need only one of your rings and two light gates. Your ring hast to be in the pattern 101010. Based on wich of your light gates turned on or off first you can say in wich direction it turns. And you can count the wind speed as well. In German we call this thing "Drehgeber"
In english it is a rotational encoder
Sounds like he's going for absolute direction and not just left or right.
@@psywiped he can get absolute direction by measuring it and than calculating the new position with every turn the
@@Jason-hz2jy what if it lost power or steps?
This will not tell direction since the code from any starting point will be either 1010... or 0101... depending on the starting point. Simplest solution would be analog using a circle of wedges. Increasing signal over time implies one direction and decreasing signal implies the opposite direction. Also provides direction with smaller fractional movements.
I think a wind sock and a pair of eyes have done a good job over the years but go for it!
Exactly and add a camera with a solar panel if its location is out of sight. Even using an old farmers barn wind vane with a camera looking down and at a pointer and dial.
It’s also a very good representation on how a digital storage disk works.
1) You need gray code not plain binary, otherwise you will get nonsense codes at boundaries.
2) Photoresistors are probably too slow to react for this purpose. Try phototransistors or photodiodes as a sensor
Well OK I see what you are doing but you could just wet your thumb and hold it up in the wind. Simple hu. LOL
Haha. A good idea to be sure. I’d love to see an Arduino sensor that can read a windy, wet thumb though 🤣
@@christophersfactory You can for speed. See hot wire anemometers.
I think you should use reverse photo diodes in reverse polarity instead of LDRs. Oh you could also just use a magnetic rotary encoder. Most have a very high Resolution
The disc seems to be counting up, so each value will say where the wind is
(Edit)
It can track 16 positions and speed using the outer dots. By counting 0-15 twice for 180°. It seems like a good measure
0 n/s
2 nne/ssw
4 ne/sw
6 nee/sww
8 e/w
10 see/nww
12 se/nw
14 sse/nnw
16 s/n
You only need two points on a disc to tell which direction it is spinning. This disc would only be necessary if you needed to provide data instead of a simple rotation signal. You still have to implement to your use case.
A recently licked finger: *I’m gonna end this whole man’s career!*
These are normally very expensive (amzn.to/3jEGN9r) hence trying to make my own :)
Be sure to check out part 2, where I took your suggestions into account! ua-cam.com/video/lwLOwk8zhh4/v-deo.html
Hall effect sensor.
Great job but check Gray code. It might be better then put binary pattern you have there
Yes when you get one thats made for 3000rpm they tend to cost quite a lot, but you can also get one for 10-20 bucks
@@taintedsasquatch398 thats an amazing solution that absolutely doesnt do anything, you can’t just slap a hall effect on something and have that work all of a sudden
@@Joshinken An absolute position encoder can be more expensive than a relative encoder. The former incorporates a disk with 8 to 12 or more tracks, whereas the latter only need two tracks and a special zero mark that the system has to find each time it starts up -- not really practical for a weather vane.
Interesting project! My design choices would be gray code encoding, arc slots instead of completely open and connected sectors for better mechanical integrity and an electro/photoetched brass or stainless steel disc.
Rotary encoders can be built with only 2 rings and a switch to know the start position. Offset of which ring switches first can tell you a direction.
Well, this is smart,
However, all you need to detect is the rotation of the wheel, for that, you can simply use a potentiometer, and depending upon the value of resistance detected, you can find out what direction the wind is blowing.
That's one of the mechanisms in an elevator-door-controller (open normal speed, low speed, open-position)
Close normal speed, low speed, close-position
in cnc machines this is how servo motors keep track of their "reference position" and how the motors know how many revolutions to turn to move spindles, turrets, and other axes.
You can buy rotary encoders to do this sort of job, or use a directional magnetic sensor (e.g. AS5600) with a magnet on whatever spins. The magnetic sensor will be more reliable than a photosensor.
If you want to continue the diy approach, I'd use slits instead of holes around the outside :)
Another alternative would involve a more "analog" approach: create your disk with a single "slit" that gets progressively wider as it rotates in a given direction. Next, shine a light onto the disk, then through a lens which focuses it onto a single photoresistor. Now, simply read the resistance of your device to determine its position.
You can use an incremental encoder to measure the direction as well. One photoresistor (out of 2) will always lead or lag behind the other. You simply measure at the falling edge of one bit. If the other is a logic high, you are spinning one direction. If the other is a logic low, you are spinning the other direction.
def an easier way to find the direction, but it's awesome for absolute positioning.
Look up Gray Code and make your encoder with a Gray code for the number of bits you want. That way, only one bit changes with each position, making the encoder much less prone to false outputs as it moves from one state to the next. It should also make it easier to print and more robust.
That looks exactly like the things R2-D2 uses in starwars
⭐️🤺
There might be a simpler way but I like this way because you could use it to get more info, not just direction. A second thing you could get from it would be the speed of the wind.
A propeller attached to a motor. The polarity would change depending on the wind direction as well as being able to tell you the intensity
urinate into the air, if you stay dry the wind is blowing away from you, if you get wet the wind is blowing towards you. one of the first life lessons;)
Yes, you over thought it. Slotted disk with two slightly offset opto sensors. Direction can be determined by which drops first and speed by counting one of them.
you could have just used a HMC5883L magnetometer module to track the horizontal rotation by using the module as a digital compass
If you don't need the absolute position, just having stripes and 2 sensors (offset by half step) works pretty well. Each change is a step. The 2nd sensor is used to determine direction (whether the change is equal or opposite). That's how old ball mice and current mice wheels work. If you DO need absolute position you can just add another sensor with just one signal in one spot of the wheel. Absolute encoders (like gray codes) are ideal for not losing the position if you lose power, but I can't think of many uses where you really need that.
Another way to have absolute position is to have a 2 axis magnetic sensor with a magnet on top of it. The resolution in this case depends on the ADCs used. Some sensors have the ADCs already included with some other features, like with the chips AS5147 or AS5047P which are designed for this purpose.
The simplest way to see what way the wind is blowing is just to go outside and feel what direction it's blowing from
I like an analog solution to this, but it might not have the consistency or precision you want. I use an infinite turn pot and an AtoD converter. The pot will give different resistance depending on the turn. It takes some training to fill a table with the resistance values for the angles you care about.
I used to work at a commercial broadloom carpet factory. We had many old looms, one still used giant punch cards to tell solinoids when to hit the brakes on the yarn selection lift. Anyway, one of these machines was retro fitted with a computer spitting out each line as needed to the loom, resulting in stunning one off designs (ceaser's head in Vegas is partially woven by me). We had a photo sensor like yours, but as a rectangle that had a binary data as the yarn lift happened, which could be deteced by a control box, to brake at a point the software says.
For direction only (a relatively static value), i.e. Wind vane, an encoder with the required resolution (number of bits) is all that is needed.
All holes, segments are not required, outer ring used to "gate" the other "bits" to present binary value/byte/word to microcontroller.
To reduce the number of input pins required on the microcontroller, use a "parallel in - serial out shift register"
Use LED Photo Diodes and Emitters shielded/enclosed from ambient light.
Photo-resistors are slow analog components better used to measure analog light levels.
To inplement direction and speed, use dual edge-triggered optocouplers with an encoder disc with a missing pulse.
Correctly spaced Optocouplers provides direction from the edge timing and the "missing-pulse" provides a counter reset, speed comes from counting pulses/sec.
The difficulty occurs from measuring two different values, direction and speed, using either independent or interdependent sensors and software code.
Use grey code. Not only will you only get one bit change per rotation, but mechanically the disk will be a lot stronger because its material will be better distributed.
It will also be better ballanced if your spinning it with speed.
I began working on a simple model in openscad, about the binary coding, there exist an other version that uses gray's binary coding : you only change one bit each time you increment the number, it's a little bit more complex to process but generally way more precise.
Also, I wouldn't use a photo-resistor, but instead a photo-transistor, the photo transistor either conducts as a diode or blocks current as an open breaker. you would just have to plug it between ground and an input pullup of an arduino for example to get a more accurate reading
I think a stack of magnets and a hall effect sensor can be use to precisely track the angle of wheel, that would be more solid state approach.
This one of the simplest and cheapest implemented to solve the problem 👏👏👏
Put 2 sensors about 5mm apart. Have a spinning disc with equally spaced holes. Whichever sensor detects the hole first determines the direction. You can also get speed data from this.
A much simpler solution would be using an apsolute encoder that uses a magnet and a magnetic field sensor, you would get a lot more detail and it would fit within a smaller footprint. You just attach the magnet to the weathervane so it can rotate and put the sensor close enough to the magnet to read it’s poles
The crucial part is the outer ring with the equally spaced holes as it tells you when the readout is actually valid. Otherwise, if two of the inner rings go form hollow to filled you might get a grossly wrong reading.
AFAIK there are other ways to code absolute positions where only one bit changes for each increment. Of course they don't give you the binary value directly, you have to feed it through a deciding algorithm or table.
Easier way is it encode a shift in frequency, put the holes progressive closer together. One direction will give an FM chirp up, the other down. Pretty easy to decode with a timer input. You only need one track or bit this way.
It's called a binary encoding wheel. 8 codes per quadrant. 32 codes represent 360 degrees. Therefore each code represents 11.5 degrees of rotational position resolution.
On propellers axel install a stick that is loosely connected to the axel .
When the axel rotates clockwise the stick also moves in that direction and touches a micro switch or blocks a light sensor.
When the propeller moves anticlockwise the stick touches the others sensor.
You could do it with 2 bits like the ball trackers in old computer mice.
The controller counts each forward or backward step and adds them up to a complete revolution. Precision depends on the gearing from the weathervane to the 2 bit wheel.
Edit: Gearing might add complexity.
Disadvantage is that if the orientation is ever lost then you're in trouble. You'd need to actively keep track of the orientation.
Depends on if you want an absolute encoder, but you could probably use a continuous rotation potentiometer to get an analog voltage for position (like set South to be 0v and 10v, and North is 5volts, etc). A reed switch could also be added close to South position, to tell if to are at South. No explicit need for a microcontroller then, unless you want to swap the voltage readout to words for the directions instead of having a chart with voltages that equal the directions. Just depends on if photoresistors are much cheaper than potentiometers, since you only need one sensor instead of several.
Cool introduction to absolute digital encoders. As everyone else said, a gray code is better. Someone else mentioned a relative encoder, where you know the direction and quantity of motion but not exact position without calibration.
Well my friend did a thesis at University making a hybrid, where you know relative motion, and after a small number of moves you know absolute position. It involves creating a gray code sequence that has unique subsequences. Lots of graph theory and stuff.
you could try to use gray encoding, so only 1 bit changes its value at a time, preventing glitches during readout, caused by multiple unsynchronized bit flips.
I think there are many far simpler ways to see which way the wind is blowing, like a sock, but this is definitely a very clever method, and I quite like it.
You're going to have issues where the bits don't flip simultaneously, due to imprecision. You can guard against this using Gray encoding (a binary encoding where only one bit flips at a time).
i quickly realized that the disk looked like binary the moment the vid started lol
You could print a gradient of black on a plastic film with laser printer, cut the disc out, where thermalpaint is spread by rotation 0-360° gradually. You could use that analog light transperancy for 1 analog sensor instead of 6 discrete 0/1 binaries, which is smaller and lighter
Just grabb an encoder that gives you two pulse trains (A & B). This gives you pulse + direction. Most microcontrollers already have direct support to decode this kind of encoder. You basically only need a "home" position to calibrate when you start up, then it will not be needen and the absolute position can be calculated by counting pulese according to the direction. A microcontroller may do this for you, in hardware, as well.
This was how old mechanical mouses worked, with way better accuracy than your binary wheel.
If you only need direction/speed and not any sort of position/angle data, a simple phase encoder would be adequate and probably simpler to implement and more reliable - typical phase encoders will have two rings with detection points that are offset so that one ring "makes or breaks" (e.g., interrupts light or not) before the other when rotated in one direction and after in the other. If the rings are A and B, and A is offset relative to B clockwise by 5 degrees, clockwise rotation would have B fire then A and counter-clockwise A then B and a circuit could see which one fires first to determine the direction of rotation. Pulse counts can also be used for rotation speed (RPM).
Also, instead of using optics, magnets in a wheel and Hall effect sensors might be more reliable as the circuitry could be coated or even potted.
Yes -- use Grey code encoding on printed transparency -- you get one more bit of precision and only one bit changes at a time
Magnetic encoders or Hall effect sensors would’ve been way more compact…
Another approach (not necessarily better or worse, depends a lot on the other circuitry you're hooking it up to) would be to use an off-center-mounted magnet and 3 or 4 static hall sensors to detect its position. If you feed the inputs to an ADC, you can precisely calculate the orientation of the wheel/shaft by comparing the relative strength of the magnetic fields between the different sensors.
this is used in a lot of servo type motors today, an example is an industrial robotic arm. There is another way (cheaper way), you can use 5 different coils,
one in the middle, 4 on the outside (for 360°) , if you apply power on the middle coil, it generates an electromagnetic field around it, each coil then will receive a different amount of this magnetic field, and converts it back to electricity, by measuring the voltage, you can calculate the exact angle.
if you only care about the direction, this can be accomplished with only one ring and time, or with two rings independent of time. for a single ring, you can have the increments increase as you turn clockwise. if youre current reading takes longer or shorter than the last, you'll know which direction its moving. if you use two rings, you can have two gaps staggered by half an increment and know which direction its going based on the rise-fall sequence of the rings. (ie fall-outer, fall-inner, rise-outer, rise-inner for cw, and vise versa for ccw)
You could also use a potentiometer and read the resistance. Zero ohms for zero degrees, 10000 ohms for 359 degrees.
Just a single compass sensor would do the trick. This is more for those interested in proof of concepts. Also you'd be reliant on a source of light. So no tracking at night unless you provide your own.
The basic idea is good, however the readings will be mostly buggy and random. You should use grey code (instead of the normal binary sequence from 0 to 1f) where only one bit changes at a time.
For an encoder like this i would propose using a Grey Code. Its a variation of binary BUT each neighboring number/value differ only by 1 bit. This makes detection more efficient and less susceptible to readout errors. Also of you use all the bits on the wheel you do not need all that much valies as only few readouts should tell you the direction of the spin. Unless you also require some precision on the actual orientation of the code wheel and studd attached to it
This is cool but to your question. If you only care about direction and speed a simpler way with the same technology would be to use only 2 points of measure, regular spacing between the gaps, and measure time differentials. Or a magnet and 2 hall sensors so you can use it at night/under cloud cover/inside.
If you’re just looking to get direction and speed, you only need 2 bits of resolution.
Look up the pulse train shown in the data sheets for off the shelf rotary encoders to get a sense of reading and resolution.
You can also find a real world example in the old school Lego Mindstorms rotation sensor from 20 years ago
I reckon a rotary encoder mounted wind vain would've saved you a lot of trouble, that said still an interesting way to approach it
You can make it much more accurate by attaching a gear to it so that it spins at a known ratio. One more mechanism would need to detect which quadrant it is in. Theoretically, you could measure down to whatever the lash of the gear is. Given very tight gearing, it's possible to measure millionths of a degree. Another way would be a clear plate with opaque carbon encoding, a light source, and a magnifying lens.