Forum / Guestbook

Luberth Tue 19 Mar 2019 at 8:33:48
Arduino Encoder Example

Arduino Encoder Example

A Arduino Enconder test for my arduino automatic chicken coop door

red=+5vdc red
black=0vdc ground blue
white=pin 2 int white
green=pin 3 int green

original example was unsigned count i make it signed for negative below 0
maybe signed long is better as signed int, now after 32767 it counts down again
unsigned int 0 to 65,535
signed int -32,768 to 32,767
signed long from -2,147,483,648 to 2,147,483,647

//I recieved an Encoder today, a BirthDay present from my Friends from China
//and it works in notime, Arduino is Great, this encoder using looked so difficult for me in the past

//Please Donate To Help Me Afford New Equipment And Software To Make My Videos More : 

Nobody out there that wants to buy a Cup of Coffee for me ;-(
its 19 march when i wrote this, This day 51 years ago i entered this world,
But Sorry i am not giving koffie and pie to all of you out there ;-)

// my encoder = LDP3806-360BM-G5-24C // IT GIVES 720 COUNTS PER REVOLUTION // // arduino code example encoder // red= +5vdc red // black= 0vdc, ground blue // white= pin 2 interrupt white // green= pin 3 interrupt green // original example was unsigned from 0 in negative direction to 65thousand something => signed from 0 to negative =-1 volatile signed int temp, counter = 0; //This variable will increase or decrease depending on the rotation of encoder void setup() { Serial.begin (9600); pinMode(2, INPUT_PULLUP); // internal pullup input pin 2 pinMode(3, INPUT_PULLUP); // internalเป็น pullup input pin 3 //Setting up interrupt //A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 on moust Arduino. attachInterrupt(0, ai0, RISING); //B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 on moust Arduino. attachInterrupt(1, ai1, RISING); } void loop() { // Send the value of counter if( counter != temp ){ Serial.println (counter); temp = counter; } } void ai0() { // ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH // Check pin 3 to determine the direction if(digitalRead(3)==LOW) { counter++; }else{ counter--; } } void ai1() { // ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH // Check with pin 2 to determine the direction if(digitalRead(2)==LOW) { counter--; }else{ counter++; } } // // //

A Arduino Enconder test for my arduino automatic chicken coop door

now i want to do something like this

End of Message, Thanks For Viewing! ☺
Tip: if your watching on your phone or tablet ⁝ add / save to homescreen and you get a nice icon its Free!
Tip: on your computer or laptop do not forget to bookmark this page its Free!
BookMark ShortCut Keys press ctrl+d on your keyboard



Reply to this Message

Did you like this Page id=261 ?

NO:         YES:


Design a Bit like ForumOne 4.0 WayBack 1999 ©
Always Read the Small print?! - -


thanks for your support
Thank You!

Co2 FootPrint WebServer

                         My Cheap Chinese Friend Ali     
Copyright Luberth Dijkman 2018 ... 2019

GoodBye Galaxy!