Chicken house door: use all pins of ESP8266

Hi, I would like to introduce you into my project (I know, its already many times solved and I can buy already complete solution even on Aliexpress)...

But I get responsibility for few months to take care of few of ladies (chicken). And because we are in area where is common that wild animal will "kill" them (not eat, just kill them). I am facing challenge every night to close Chicken house and every morning to Open it.

Close is not big problem for me, but woke up before 9 its harder and harder....and chicken already waiting for release.

I have many many board and sensors at home so I got idea "why not to be more productive and improve quality of my life = lets automatize that opening of door".

For that I prepared sets of:
Board:

  • EPS8266

Sensors, stepper, etc:

  • 2x magnetic sensor (reader) which is for door. MC-38
  • 1x trigger for sensor
  • stepper 28BYJ-48 (include driver ULN2003)
  • few buttons

Power:

  • 2-4x Li-ion batteries 18650 (2 in serie)
  • 1x mini 560 DC-DC step down (5-20V to 3.3V)

Bonus:

  • PCF8574 I2C interface, 8-bit parallel
  • Real time clock module

Instalation:

  • Above door will be stepper with "role" to door. Every time when it turns few time, it will move door up or down.
  • On the door will be magnetic sensors which recognize if door is close or open. (And when it should stop moving).
  • Logic will be in small box powered by 2x18650 in serie (aprox. 5-7V). This power will be connected directly on the driver of stepper motor. Also the same power will be connected to Step-down to 3.3V and power the ESP8266.
  • On the side will be connected to board also 2 (in worst case one) micro button(s). Which will trigger to close or open door on command.
  • board will be connected to wifi to check actual time and have "simple" instruction. Close door at 10pm and open at 6:30am.
  • as bonus can be in case that wifi will not be available (or will have problem to connect), can use real time module (which keep time with small battery).

Description of work:

  • On morning will system check time and if is 6:30.
    -- Check what sensors say about position of the door.
    -- if they are close, open them.
    -- open them with turning stepper on one direction till second sensor will say "door is fully open".

  • On evening will system check time and if its aprox 22:00.
    -- check if the door is still open.
    -- if they are open, close them.
    -- close them by turning with stepper to second direction till first sensor will say "door is fully close".

  • In case that I wish to close / open it in different time and manually. There will be 1 or 2 micro buttons which will check where is door now and if they are open -> it will close it. And opposite.

My concerns:

  • mainly about battery life
    -- dont want to keep system all day on and waiting in loop. For that case I would like to make sleep look that every 30minutes it will sleep and wake up (check all time and if its too early, fall a sleep again).
    -- when falling sleep, how to trigger opening/closing by button manually when system is sleeping.

  • how to be sure that its working?
    -- I prepare even small piezo which in case of "closing/opening" door and sensors will not react in few minutes = door is stuck. It will start beeping.

  • number of function is too high to make it simple and too many components with board which don't have so many pins. So maybe I will need to cut some functions.

Thanks for telling.

My progress / steps:

  • I prepared breadboard, all stuff around on table.
  • Connect esp8266 with regular power module to breadboard include stepper motor with driver (Baby steps, one function per step)
  • I am able to turning with stepper on both sides.

Problems:

  • pins / connection.
    -- stepper works perfectly, but I could set it up on pins D1, D2, D5, D6.
    -- But D1 and D2 is for I2C which I would like to use maybe for real time clock module.

When I look on table what pins I can use (when I imagine boot from scratch): D1, D2, D5, D6, D7. Thats not much. When I release D1 and D2 and put stepper on D5, D6, D7, D8 ...I am facing issue that it will not boot because of D8.

And thats just start, I still need space for connect 1 or 2 buttons, 2 sensors and one piezo?

I was thinking to connect all sensors and buttons (inputs) and also piezo (output) on PCF8574 I2C interface, 8-bit parallel. But for that I will need empty i2c (D1 and D2)
Can I put just this i2c module and control all (include stepper over it)?


BTW

There are quite a few threads about this same topic on this website, search.

Schematics and software might help.

Most don’t use WIFI.

1 Like

Get a rooster.

2 Likes

I will check that threads.
Wifi is not necessary to use, thats correct. But when ESP have WIFI function....

Anyway, I will ask you if you know how to set up stepper be controlled over PCF8574 i2c?

I had some code which was working on control stepper with regular connection to esp.
When I put PCF8574 between, I am confuse how control over is working. (my pcf if on 0x20 address).

#include <PCF8574.h>
#include <AccelStepper.h>

const int stepsPerRevolution = 2048;  // change this to fit the number of steps per revolution

// ULN2003 Motor Driver Pins before:
/*#define IN1 14
#define IN2 12
#define IN3 13
#define IN4 15*/

#define IN1 P0
#define IN2 P1
#define IN3 P2
#define IN4 P3

// Set the i2c HEX address
PCF8574 pcf8574(0x20);

// initialize the stepper library
AccelStepper stepper(AccelStepper::HALF4WIRE, IN1, IN3, IN2, IN4);

void setup() {
  // initialize the serial port
  Serial.begin(115200);

  // Set the pinModes
  pcf8574.pinMode(P0, OUTPUT);
  pcf8574.pinMode(P1, OUTPUT);
  pcf8574.pinMode(P2, OUTPUT);
  pcf8574.pinMode(P3, OUTPUT);
  pcf8574.begin();
  
  // set the speed and acceleration
  stepper.setMaxSpeed(700);//500
  stepper.setAcceleration(100);
  // set target position
  stepper.moveTo(4*stepsPerRevolution); //1*
}

void loop() {
  // check current stepper motor position to invert direction
  if (stepper.distanceToGo() == 0){
    stepper.moveTo(-stepper.currentPosition());
    Serial.println("Changing direction");
  }
  // move the stepper motor (one step at a time)
  stepper.run();
}

But as you probably expect, control of stepper fail. Lights on driver of stepper shine but thats all.

So do you think that when most of them dont use wifi, its better to switch to classic Arduino (nano or different version) where is more "open" pins?

The question is, do you want to use wifi?

Personally, I see no need for WIFI.

An LDR and maybe RTC is a must have.

A good RTC is DS3231.

1 Like

See this thread:

A NodeMCU is arguably not the best choice. It appears to have more pins than a WeMOS D1 Mini, but the "extra" pins down the left hand side of your illustration are not usable as the following description indicates.

The other matter is how effectively it can be put to "sleep".

As I have noted in another post today, the obsolete ULN2003 is not the best choice. A TPIC6B595 requires only three pins to control and could control two of those steppers or one and four other controlled outputs, such as an "active" piezo buzzer.

Arguably not that necessary if connected to the Internet.

Priceless! :rofl:

1 Like

If you are running out of I/O pins, look at the MCP23008 IO port expander.

The Wemis D1 Mini is my go-to board. Mostly because I can do OTA programming.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.