Go Down

Topic: Using hc-sr501 PIR with 28BYJ-48 Unipolar Stepper with ULN2003 drivers (Read 215 times) previous topic - next topic

dap122893

Hello everyone,

I'm a complete beginner who is at a wall with how to code. I'm working on a project that is an automatic toilet seat lid and seat the size of a child first toilet. The motors I'm using are 2 28BYJ-48 Unipolar Steppers with 2 ULN2003 drivers, one for each. The sensors I'm using are 3 HC-SR501 PIR Motion Detectors. I'm using a 5v power supply.

The idea is that the first sensor when triggered will lift the seat and lid together. If the person needs the seat down they do a small motion with their foot on a sensor facing down that triggers the seat motor. If they do decide to sit down the third sensor will be attached to the underside of the lid that will monitor them so when they get up the lid closes. If the seat is not dropped after the initial rise, there will be a timer set at 90 secs that will drop the seat and lid together.

***The code I have is just trying to get the first sensor to work and move both motors. When I turn it all on the motors just move on their own, will stop and then maybe move again. Me trying to trigger the sensor doesn't do anything. Can anyone put me on the right path? I feel like if I can get an understanding of the first I can apply that to 2nd and 3rd sensors. Please refrain from telling me to go study sample projects and such. I have looked through so many pages that it only gets more confusing. Thanks. ***

Code: [Select]
// Include the AccelStepper Library
#include <AccelStepper.h>

// Define Constants

int inputPin1 = 2;               // choose the input pin (for PIR sensor)
int pirState1 = LOW;             // we start, assuming no motion detected
int val1 = 0;

int inputPin2 = 3;               // choose the input pin (for PIR sensor)
int pirState2 = LOW;             // we start, assuming no motion detected
int val2 = 0;

int inputPin3 = 4;               // choose the input pin (for PIR sensor)
int pirState3 = LOW;             // we start, assuming no motion detected
int val3 = 0;

// Define step constants
#define FULLSTEP 4
#define FULLSTEP 4

// Define Motor Pins (2 Motors used)

#define motorPin1  10     // Blue   - 28BYJ48 pin 1
#define motorPin2  11     // Pink   - 28BYJ48 pin 2
#define motorPin3  12    // Yellow - 28BYJ48 pin 3
#define motorPin4  13    // Orange - 28BYJ48 pin 4
                       
                       
#define motorPin5  6     // Blue   - 28BYJ48 pin 1
#define motorPin6  7     // Pink   - 28BYJ48 pin 2
#define motorPin7  8     // Yellow - 28BYJ48 pin 3
#define motorPin8  9     // Orange - 28BYJ48 pin 4

// Define two motor objects
// The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48
AccelStepper stepper1(FULLSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper2(FULLSTEP, motorPin5, motorPin7, motorPin6, motorPin8);

void setup()
{
  // 1 revolution Motor 1 CW
  stepper1.setMaxSpeed(1000.0);
  stepper1.setAcceleration(50.0);
  stepper1.setSpeed(500);
  stepper1.moveTo(1024); 
 
  // 1 revolution Motor 2 CCW
  stepper2.setMaxSpeed(1000.0);
  stepper2.setAcceleration(50.0);
  stepper2.setSpeed(500);
  stepper2.moveTo(1024);
 
pinMode(inputPin1, INPUT);
pinMode(inputPin2, INPUT);
pinMode(inputPin3, INPUT);
 
  Serial.begin(9600);

}

void loop(){
  val1 = digitalRead(inputPin1); // read input value
    if (val1 == HIGH) {            // check if the input is HIGH
    stepper1.moveTo(1024);        // Move motors
    stepper2.moveTo(-1024);}
 
      stepper1.run();
      stepper2.run();
   
}

attiny85nightmare

what about time delay adjust and trigger selection jumper on the sensor? the minimum time is 5 secs, that is an eternity for arduino.I have no experience with this library but maybe you should try to remove the motors and the library and debug the sensor first, turning a led on and off on any arduino pin or sending a dummy message over serial.

wvmarle

You're going to want some ways to interrupt the motion. It's going to be pretty frustrating otherwise, if e.g. the seat decides to go up while you're not really finished you want to have a way to get it back down easily.

Are those tiny steppers even strong enough to lift/lower toilet seats?
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up