WIND DIRECTION WITH ROTARY ENCODER

i get false readings,it could be on the first if you turn it fast,the point is that is happening,there is not a standard spot it happens

You get missing counts when you turn it fast. Not extra counts.

Because of how the encoder works, and how you are reading it with the interrupt, the count value is immune to switch bounce. It may bounce up and down by one count, but it can't add or miss counts.

If you are missing counts on fast rotation I would expect that the response rate of the internal mechanical switches is not fast enough. If its not fast enough to respond to the changing wind direction you see, then you will need to use a faster non contacting optical or magnetic encoder.

One possibility to get higher response speed from the encoder is to read it for 24 counts per revolution instead of 48. Change the interrupt trigger from CHANGE to RISING or FALLING which ever seems better. There may be a difference between opening and closing the switch. You will still get 15 degrees of resolution.

I just did a quick look at the original code.
One can't determine direction that way.
Any change of A or B input can be a change in direction.
You can't just look at input B.
Also, the biggest problem, as mentioned, the
serial takes too much time. The inputs need to be on interrupt.
Dwight

Interesting, thanks. Your vane is quite long, from tip to tail, compared to my vane. How does it perform outside? Is it steady, or does it swing around a lot?


The reason you could not upload your photos was that they were too large. Resize them to around 1024 pixels wide and you should be OK.

Change the interrupt trigger from CHANGE to RISING or FALLING which ever seems better. There may be a difference between opening and closing the switch. You will still get 15 degrees of resolution.

Can you explain it more,what should i change on my code,and where

Interesting, thanks. Your vane is quite long, from tip to tail, compared to my vane. How does it perform outside? Is it steady, or does it swing around a lot?

It perfoms very well,its swinging easily cause of the long wing,and its steadt cause of the weight,the shaft is from a stainless welding electrode,and the front little cone thing is heavy enough

for anynoe of you want a reliable forever wind vayne this is the best construction of all,but you must have a 3d printer xD Best wind vane by far

Can you explain it more,what should i change on my code,and where

Change this

attachInterrupt(digitalPinToInterrupt(3), readEncoder, CHANGE);

To this

attachInterrupt(digitalPinToInterrupt(3), readEncoder, RISING);

Or this

attachInterrupt(digitalPinToInterrupt(3), readEncoder, FALLING);

cattledog:
Change this

attachInterrupt(digitalPinToInterrupt(3), readEncoder, CHANGE);

To this

attachInterrupt(digitalPinToInterrupt(3), readEncoder, RISING);

Or this

attachInterrupt(digitalPinToInterrupt(3), readEncoder, FALLING);

When i did that a full rotation is counting 24 so its the half of my 48 reading that i had before,but the problem still going on...it is missing counts

it is missing counts

In my opinion you need an optical or magnetic encoder to reliably rotate the encoder at high speed. You might also investigate an "absolute" instead of "incremental" encoder for your application.

Using only rising or falling will only count 1/2 no counts
are missed.
Dwight

Okey guys,i think im going to change the construction concept to something else,thank you all for your responses,i learn a few things,Cya

kaloudis94:
for anynoe of you want a reliable forever wind vayne this is the best construction of all,but you must have a 3d printer xD Best wind vane by far

Thanks for that link, very interesting!