It is currently Thu Feb 23, 2017 8:40 am

All times are UTC - 8 hours




 Page 1 of 1 [ 3 posts ] 
Author Message
 Post subject: Arduino motor control with proximity sensor help
PostPosted: Wed Feb 15, 2017 10:25 am 

Joined: Mon Feb 13, 2017 6:05 pm
Posts: 2
Hello


Basically if it was an LED I want the LED to be turned off when a proximity sensor detects an object, then after 2 seconds I want the LED to come back on while the prox is still sensing the object, so that it can clear the prox and start the code over for the next object to be picked up by the prox. I have changed my code so many times, and all I can come up with is the prox senses the object and turns off led but with object in front of prox i cant get nothing else to happen.

I was just useing led as an example, it is actually a motor that is turning an arm that is going in front of prox to stop motor at 12:00 position, but once arm is in front of the prox motor stops. I need something to turn on motor after a 2 second delay to clear prox and restart again. I want motor to stop for 2 seconds at 12:00 position then turn motor on till it reaches 12:00 again. I have learned a lot in this Venture but I am stuck and I need to get this project going. I am sure it's quite easy but I am new to this.


I have been working on a project, while trying to figure out how to control it, that is how i found out about Arduino, needless to say the Arduino world is new to me. The project consists of controlling a wheel chair motor via a 100 amp solid state relay with a proximity sensor. What i am trying to accomplish is the shaft of the motor will be at the center of an arm so that the prox sensor will detect when the motor has rotated to the 12:00 position. Once the prox senses the arm I want the motor to stop for 2 seconds and then rotate again until prox senses the arm again which will be 1/2 revolution being that it will see both ends of the arm in 1 rev pausing for 2 seconds each time before rotating again. The code i wrote allows me to stop the motor when the prox senses the arm but i have been trying for a week to figure out how to get it to only stop for 2 seconds then rotate again. Pin 12 is going to control side of the solid state relay not the actual motor. Code is below.

int sensorVal;


void setup(){
//configure pin2 as an input and enable the internal pull-up resistor

pinMode(2, INPUT_PULLUP);
pinMode(12, OUTPUT);

}

void loop(){
sensorVal = digitalRead(2);
// The Logic is inverted a low on pin 2 means a sinking switch is activated
// and a high on pin 2 means the switch is unactivated and pulled up by the internal resistor
// this is not a problem since the controller can interpret the data any way we tell it to

if (sensorVal == HIGH){
digitalWrite(12, HIGH);
}
if (sensorVal == LOW ){
digitalWrite (12, LOW );

}
}

Can this even be done with just the Arduino alone or do i need a motor or relay shield. I have tried putting in delays but it does not react the way i need it to.

Thanks in advance


Offline
 Profile Send private message  
 
 Post subject: Re: Arduino motor control with proximity sensor help
PostPosted: Tue Feb 21, 2017 7:11 pm 
User avatar

Joined: Sat Nov 08, 2003 1:01 am
Posts: 1548
Location: Phoenixville, PA USA
I don't proclaim to be a programmer (DOSBASIC and some VB4 are about as far as I went), but one way to accomplish your goal is to:

When the sensor detects the arm, set the sensor output to stop the rotation.
"Pause" for 2 seconds (probably something like PAUSE 2000)
When PAUSE is done, disable sensor.
Reset motor to start turning.
Re-enable sensor.
Loop

That should put you on the correct path.

CeaSaR



_________________
Hey, what do I know?
Offline
 Profile Send private message  
 
 Post subject: Re: Arduino motor control with proximity sensor help
PostPosted: Wed Feb 22, 2017 9:27 pm 

Joined: Mon Feb 13, 2017 6:05 pm
Posts: 2
Thanks for the reply i have tried delay after the prox senses the arm and it stops the motor, what i am haveing trouble with is since the arm stops in front of the prox, i dont know how to get the arduino to ignore the signal after the 2 seconds elapses so that it can repeat. I have to have the motor start again, i have studied this for more hours than i can count these last two weeks, i either dont understand it or am missing something.


int proxPin = 2; // signal pin
int proxVal;  //reading from proxPin
  int motorPin = 12;  // pin controlling motor
  unsigned long lastTimeProxTriggered = 0;  //the last time the prox was triggered
  unsigned long interval = 2000;  // how long the motor will delay
  int motorPinState = HIGH;
void setup(){
 //configure pin2 as an input and enable the internal pull-up resistor
 pinMode(proxPin, INPUT_PULLUP);
 pinMode(motorPin, OUTPUT);}void loop(){
 unsigned long currentMillis = millis();
 proxVal = digitalRead (proxPin);
digitalRead (motorPin);
 // The Logic is inverted a low on pin 2 means a sinking switch is activated
 // and a high on pin 2 means the switch is unactivated and pulled up by the internal resistor
 // this is not a problem since the controller can interpret the data any way we tell it to if (proxVal == HIGH){
 digitalWrite (motorPin, HIGH);
 
}
 if (proxVal == LOW ){
   digitalWrite (motorPin, LOW);
  
 }
  else if (proxVal == LOW && currentMillis-lastTimeProxTriggered >= interval ){
    lastTimeProxTriggered = currentMillis;
  
  digitalWrite (motorPin, HIGH); 
  }
 }

All it does is stop wont turn motor on i know im missing something.


Offline
 Profile Send private message  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 3 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: