Hello,
I trying to adopt the code for 28BYJ-48 stepper motor with ULN2003 driver board for roller blinds control. Code is working, but when the stepper motor is always on - it gets hot. Because of it also its consumes more energy. So thats why I want to turn on ULN2003 board only when new action is started, and after that it should be shuted down again. I could do it, because ULN2003 has On/Off jumper:
Question #1: I trying to use relay for that On/Off. Could I do it without relay and control On/Off jumper directly from arduino? Does relay is the best solution?
Question #2: I suck at programming, but I trying to add theese lines to my code to control the relay SIL05-1A72-71D, which controls the ULN2003 driver board:
int powerPin = 7; //before SETUP
pinMode(powerPin, OUTPUT); // In SETUP
digitalWrite(powerPin, LOW); // In SETUP
digitalWrite(powerPin, HIGH); // In void receive function
delay(CURTAIN_CLOSED); // In void receive function
digitalWrite(powerPin, LOW); // In void receive function
digitalWrite(powerPin, HIGH); - I think is in right position, but I don't know how to turn off relay when action is done. Please advise for coding, because I not good in it. Thank You! Below is the code:
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_NODE_ID 10
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
// Enable repeater functionality for this node
//#define MY_REPEATER_FEATURE
#include <SPI.h>
#include <MySensors.h>
#include <AccelStepper.h> //import biblioteki AccelStepper
#define HALFSTEP 8
#define CURTAIN_CLOSED 10000 // wartosc gdy kurtyna zamknieta
#define CURTAIN_OPEN 0 // wartosc gdy kurtyna otwarta
#define CHILD_ID 1
int powerPin = 7;
// definicje MySensors
MyMessage message(CHILD_ID, S_COVER);
// Definicja pinow silnika
#define IN1 3 // IN1 - zielony
#define IN2 4 // IN2 - czarny
#define IN3 5 // IN3 - niebieski
#define IN4 6 // IN4 - czerwony
AccelStepper stepper1(HALFSTEP, IN1, IN3, IN2, IN4);
void setup()
{
stepper1.setMaxSpeed(1000.0);
stepper1.setAcceleration(100.0);
stepper1.setSpeed(200);
stepper1.moveTo(CURTAIN_OPEN);
pinMode(powerPin, OUTPUT);
digitalWrite(powerPin, LOW);
}
void presentation()
{
// Wyslanie informacji o wersji programu
sendSketchInfo("Roller blinds", "1.0");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID, S_COVER); // Window Cover sub-type, commands: V_UP, V_DOWN, V_STOP
}
void loop()
{
stepper1.run(); //Start
}
void receive(const MyMessage &message)
{
// if message = V_UP start moving until closed
if (message.type==V_UP) {
digitalWrite(powerPin, HIGH);
if (stepper1.distanceToGo() == 0){
if (stepper1.currentPosition() == CURTAIN_OPEN){
stepper1.moveTo(CURTAIN_CLOSED);
// Store state in eeprom
saveState(message.sensor, message.getBool());
request(CHILD_ID, V_UP, 0); // request new values from controller
}
}
}
if (message.type==V_DOWN) {
digitalWrite(powerPin, HIGH);
stepper1.moveTo(CURTAIN_OPEN);
// Store state in eeprom
saveState(message.sensor, message.getBool());
request(CHILD_ID, V_DOWN, 0); // request new values from controller
}
if (message.type==V_STOP) {
digitalWrite(powerPin, HIGH);
stepper1.setCurrentPosition(0);
// Store state in eeprom
saveState(message.sensor, message.getBool());
request(CHILD_ID, V_STOP, 0); // request new values from controller
}
// delay(CURTAIN_CLOSED);
// digitalWrite(powerPin, LOW);
}