Welcome InMyPi Forum / Guestbook




Luberth Sat 23 Mar 2019 at 21:22:38
Arduino Chicken Coop Door Encoder Gearmotor version

-
Arduino Chicken Coop Door Encoder Gearmotor version

Under Construction / work in progress

Recieved an 12vdc 18rpm gearmotor 23-3-2019 from my Cheap Chinese friends <;-)
connected the hall effect encoder to an arduino uno (aLike Arduino Encoder Example)

about 7125 pulses per rotation
think i wil need someting like 10 rotations
71250 counts wil not fit in signed int so wil use signed long


pinout off my aliexpress china gearmotor hall effect encoder
i left the wire colors away because the wire colors are confusing
howto connect is also written in white on pcb print silk screen

if you follow the pbc trace you can see motor power connection is soldered to pin1 and pin6
the wire colors are confusing!!!

red and white = motor power
black encoder = ground - 0vdc
blue = encoder +3.3vdc
yellow and green = encoder pulse A-B
the wire colors are confusing!!!

will make a pwm position control this week
for the chicken coop door with arduino
never have done something like this, so it will be fun
Motion Controlled Arduino Uno with L298N H-bridge motordriver and Gearmotor with Hall effect encoder


my design idea, whats in my head, whats on my mind (Other then SEX)
a door home switch higher as normal open position
on startup/powerup/reset program setup{} lets motor run in home switch
when switch touched set home position encoder counter to 0
then move to an dooropen encoder value position
or move to an doorclose encoder value position
open close based on time or LDR light sensitive resistor

home switch can also function as fault/overtravel switch
---- if the motor runs clockwise or counterclockwise eventualy the doorslide will always in the end go up
---- so in both directions it wil function as an overtravel switch = error


first test with arduino gearmotor encoder position
not perfect yet but looks like it


first test with arduino gearmotor encoder position
not perfect yet but looks like it



// first test encoder gearmotor home down up loop
// http://84.106.2.21:8888/forum/index.php?action=view&id=268
// www.luberth.com
// not perfect yet but looks like it

// arduino with L298N H-bridge motor driver and 12vdc/12rpm hall effect encoder gearmotor  

volatile signed long counter = 0;       // This variable will increase or decrease depending on the rotation of encoder
const int Enable_PWM_Pin = 10;          // enable motor b use a PWM i/o pin
const int ClosePin = 8;                 // direction close motor b
const int OpenPin = 9;                  // direction open motor b
signed long downposition;
signed long  uppositon;



void setup() {
  Serial.begin (9600);

  pinMode(0, INPUT_PULLUP); // home switch pullup input pin 2
                            // a Normally closed switch from GND to D0
                            // so D0 gets high 1 when touched
  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 encoder activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 on most Arduino.
  attachInterrupt(0, ai0, RISING);  // should it be RISING or FALLING 
  //B rising pulse from encoder activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 on most Arduino.
  attachInterrupt(1, ai1, RISING);  // should it be RISING or FALLING 

  //home search switch
  //   for safety should be something added here like
  //       if homeswitch not seen in ??seconds then turn off motor
  // and report error
  while (digitalRead(0) == 1) {                    // until homeswitch touched
    digitalWrite (ClosePin, HIGH);                 // turn on motor up direction
    digitalWrite (OpenPin, LOW);                   //
    analogWrite (Enable_PWM_Pin, 150);             // enable motor, 150 speed 255=full speed
    Serial.println (counter);
  }
  digitalWrite (ClosePin, LOW);                    // turn off motor close direction
  digitalWrite (OpenPin, LOW);                     // turn off motor open direction
  analogWrite (Enable_PWM_Pin, 0);                 // enable motor, 0 speed
  Serial.println (counter);
  counter = 0;                                     // set home position to 0
  Serial.println (counter);
// move a bit away from the switch
    digitalWrite (ClosePin, LOW);                 // turn on motordown direction
    digitalWrite (OpenPin, HIGH);                   //
    analogWrite (Enable_PWM_Pin, 150);             // enable motor, 150 speed 255=full speed
 delay(1000);
    Serial.println (counter);
    digitalWrite (ClosePin, LOW);                 // turn off motor close direction
  digitalWrite (OpenPin, LOW);                     // turn off motor open direction
  analogWrite (Enable_PWM_Pin, 0);                 // enable motor, 0 speed
  Serial.println (counter);
  delay(1000);
}



// stop the motor
void StopMotor() {
  digitalWrite (ClosePin, LOW);                    // turn off motor close direction
  digitalWrite (OpenPin, LOW);                     // turn off motor open direction
  analogWrite (Enable_PWM_Pin, 0);                 // enable motor, 0 speed
  Serial.println (counter);

}

void Error(){
   StopMotor();
while(1==1){
  Serial.println ("something went totaly wrong overtravel protect by homeswitch");
  // touched the homeswitch during up or down mowe
  // maybe encoder count failure??? failing connector, broken encoder wires
  // encoder wires wrong  counting wrong way
  //loop forever
  //beep
  //alarm
  //lcd
}
}


void DoorMotorClose() {
  if (counter <= 0) StopMotor();
  digitalWrite (ClosePin, HIGH);                  // turn on motor close direction
  digitalWrite (OpenPin, LOW);                    // turn off motor open direction
  analogWrite (Enable_PWM_Pin, 200);              // enable motor, 200 255=full speed
  while (counter >= uppositon) {
    //Serial.println (counter);
    if(digitalRead(0) == 0)Error();           // something went totally wrong should not see a home switch now
    if (counter <= (uppositon + 1000))  analogWrite (Enable_PWM_Pin, 100); //do not use a value less then 100
  }
  StopMotor();
}



// open door
void DoorMotorOpen() {
  if (counter >= downposition) StopMotor();
  digitalWrite (ClosePin, LOW);                   // turn on motor close direction
  digitalWrite (OpenPin, HIGH);                   // turn off motor open direction
  analogWrite (Enable_PWM_Pin, 200);              // enable motor,  speed 200 255=full speed
  while (counter <= downposition) {
    //Serial.println (counter);
    if(digitalRead(0) == 0)Error();           // something went totally wrong should not see a home switch now
    if (counter >= (downposition - 1000))  analogWrite (Enable_PWM_Pin, 100); //do not use a value less then 100
  }
  StopMotor();
}



//***LOOP***
void loop() {
  downposition = 33000;
  uppositon = 3000;

  Serial.println (counter);

  if (counter <= downposition)DoorMotorOpen();
  Serial.println (counter);
  delay(15000);

  if (counter >= 0)DoorMotorClose();
  Serial.println (counter);
  delay(15000);

}




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++;
  }
}

// first test encoder gearmotor home down up loop
// http://84.106.2.21:8888/forum/index.php?action=view&id=268
// www.luberth.com







Arduino chicken coop door http://84.106.2.21:8888/forum/index.php?action=view&id=255






































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


Name
Subject
Message

, <code> <b> <i> <u> .






POLL / VOTE
Did you like this Page id=268 ?

NO:         YES:




   


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



http://forum.luberth.com - - http://www.luberth.com/forum/

thanks for your support
Thank You!




Co2 FootPrint of this WebServer



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