Chicken Coop controlled with uno and ALexa

I am very new to Arduinos and coding, so please bare with me. I have about a 700 post thread about a sawmill head lift that some great members on here have been very patient and helpful in guiding me through. That learning process has led me to this current project.

Currently, I have a linear actuator connected to a BTS7960 motor driver. I have coded an Arduino to open the door at a set time in the morning and close it at a set time at night. The door has limit switches on each end to turn the motor off. I am using the DS3231 RTC to keep the time. It is working as I expect it to, but I would like to improve it and I am not sure how or if it is possible. I have pasted the code at the bottom:

I am an ALEXA fan. I have many smart devices that I can control with ALEXA. What I would like to do is basically have the same setup as I do now. The door opens in the morning and closes at night, but I would also like to be able to control it with a smart relay/ ALEXA. So, that I can Open/Close it any time I want via ALEXA.

What I am thinking is:
I have an old 40A DC motor speed controller with a forward and reverse switch lying around (PWM does not work correctly, but I should only need 100% power for this project).

All this controller needs in order to come on is for one leg of the Forward/Reverse switch to go to ground.

I am fairly confident I can make it work using the arduino and a 2 ch relay to switch f/r and still have the limit switches turn the motor off.
However, if I use a smart Relay, how would I be able to have the limit switches tell the arduino/ALEXA the door is opened/closed?

This may be really simple, but I haven't been able to find something like this while searching the forum.

This is the current code I am using:

#include <RTClib.h> // for the RTC
#include <Wire.h>

// Instance of the class for RTC
RTC_DS3231 rtc;

char t[32];

int RelayUp = 4;
int RelayDown = 5;
int switchA = 6;
int switchB = 7;

const int OnHourUp = 6; //SET TIME TO ON RELAY (24 HOUR FORMAT)
const int OnMinUp = 38;
const int OnHourDown = 21; //SET TIME TO OFF RELAY
const int OnMinDown = 8;
const int upHour; 
const int upMin; 
const int downHour; 
const int downMin;  

int CurrentHour;
int CurrentMinute;


void setup() {
  Serial.begin(9600);
  Wire.begin();
  rtc.begin();
  if(rtc.lostPower()) {      // uncomment this line on the second time upload
   rtc.adjust(DateTime(F(__DATE__),F(__TIME__))); 
  }
  //If time is off comment out the if statement above and adjust the date in the line below
  //rtc.adjust(DateTime(2021,6,9,16,6,0));  
  //The time set above is June 8, 2021 6 16 AM uncomment it
  //Once the time has been set correctly comment out the line rtc.adjust(DateTime(2021,6,8,6,20,0)); line and then
  //uncomment the if statement above that you previously commented out to adjust the time

   pinMode(switchA, INPUT_PULLUP);
   pinMode(switchB, INPUT_PULLUP);
   pinMode(RelayUp, OUTPUT);
   pinMode(RelayDown, OUTPUT);  
   
   
}
void loop() {
 DateTime now = rtc.now();
   // Save check in time;
  sprintf(t, "%02d:%02d:%02d   %02d/%02d/%02d",  now.hour(), now.minute(), now.second(), now.month(), now.day(), now.year());  
   
  CurrentHour = now.hour();
  CurrentMinute = now.minute();

  Serial.print(F("Date/Time:   "));
  Serial.print(t);
 
  Serial.print("\tHour: ");
  Serial.print(CurrentHour);
  Serial.print("\tMinute: ");
  Serial.println(CurrentMinute);

   if(CurrentHour == OnHourUp && CurrentMinute == OnMinUp){
    Serial.println("Door Opening");
    doorOpening();
    }
   
  if(CurrentHour == OnHourDown && CurrentMinute == OnMinDown){
     Serial.println("Door Closing");
      doorClosing();
    }

  if(digitalRead(switchA)==LOW){
     Serial.println("switchA was read");
     
  }

  if(digitalRead(switchB)==LOW){
     Serial.println("switchB was read");
  }


  if(CurrentHour == upHour && CurrentMinute == upMin){
    Serial.println("Door Opening");
    doorOpening();
    }
   
  if(CurrentHour == downHour && CurrentMinute == downMin){
     Serial.println("Door Closing");
      doorClosing();
     }
  
}

void doorOpening()
{
  while(digitalRead(switchA)== HIGH){
    digitalWrite(RelayUp,HIGH);
    digitalWrite(RelayDown,LOW);
  }
    
    if(digitalRead(switchA)== LOW){
    digitalWrite(RelayUp,LOW);
    digitalWrite(RelayDown,LOW);
    Serial.println("Door Opened");
    delay(60000);
    
    }
}

void doorClosing()
{

 while(digitalRead(switchB)== HIGH){
   digitalWrite(RelayDown,HIGH);
    digitalWrite(RelayUp,LOW);
  }
    
    if(digitalRead(switchB)== LOW){
    digitalWrite(RelayDown,LOW);
    digitalWrite(RelayUp,LOW);
    Serial.println("Door Closed");
    delay(60000);
    
   }
}

Thanks!

Good Heavens, no!
Never on a first date!

What is a smart relay? Never heard that word before.

This is similar to what I am talking about:
MHCOZY WiFi Wireless Smart Switch Relay Module for Smart Home 5V 5V/12V,Ba Applied to Access Control, Turn on PC, Garage Door (2CH WiFi Inching Relay) https://www.amazon.com/dp/B07GTKHCST/ref=cm_sw_r_cp_api_glt_i_YB82NE33FJ2SZ3VS46CY

Smart relay may be the wrong wording.

“However, if I use a smart Relay, how would I be able to have the limit switches tell the arduino/ALEXA the door is opened/closed?“

Suggest you just use the limit switches to remove power when they are operated.

Also suggest incorporating a crash secondary limit switch.

Forget about Alexa being notified.


Show us a good schematic of your circuit.

Show us a good image of your ‘actual’ wiring.

Sorry but I don't spend time investigating sales sights. You filter out and post the data, the facts.

Ok, what I am calling a “smart relay” is two relays on a board. The board has a chip that can connect to WiFi. Via WiFi (Alexa or phone app) the relays can be controlled opened/closed.

@LarryD
I can draw a simple schematic, but what I have now isn’t really like it will be when I do it like I want to.

Whow. I agree. A relay board that can receive Wifi. How is that setup?


Not sure I understand your question, but here is a picture. If it will allow me to attach.

Also, a simple wiring schematic of what I think would work if I could connect the arduino to the “smart relay” I am not sure if that is possible or not…

This is a DC motor ?

What voltage is the motor rated at ?

What is the motors resistance ?

What is this motor driver ?

Whow. That's advanced and new stuff to me.
Do You know how to tell that board the data needed so it will connect to Wifi?
I don't know but this is advanced stuff.

12v dc motor brushed motor.

Not sure of motor resistance (like I said I’m new; what does this tell you? How do you tell? Check the ohms on the two leads coming from motor). I don’t have a data sheet or any info on it. It came out of my junk pile.

This is what I’m planning to use as motor driver:

ICQUANZX DC Motor Controller,DC 9-50V 40A DC Motor Speed Control Reversible PWM Controller 12V 24V 36V 48V 2000W Forward Reverse Switch

Yes


Is this a gear motor ?


Also, with 12v applied, how fast does the motor turn ?

No. I’m stupid. I have no idea how to tell. Or even what I would do if I could tell. My thought was if I could figure out what pin/chip energizes the relay on the board and it was within 5v I could set the arduino to supply the voltage or Alexa in order to energize relay.

I can get you that info if necessary. What does that tell me?

Let’s say the motor resistance was 10 Ω.

12v / 10 Ω = 1.2 amps, therefore, a 2A @12v power supply would be needed.


If this is a slow/strong gear motor, speed control probably is not necessary.

It is a 12 motor mounted to a linear actuator. Yes I am sure it is geared some how to connect to the actuator cylinder, but idk how or what ratio. Idk the speed of the motor.

Sounds like all that is needed is a MOSFET and the relays are necessary for control of the motor for up/down operation + the limit switches.

Please measure the resistance on the motor.

When I test it I get 1.3 ohms. But I am testing with a $25 Klein tool multimeter. I do know that the l298 motor driver which I think is rated at 2 amps would not lift it.

So you require a power supply and controller rated for the 10 Amp stall current.