Go Down

Topic: Dc motor, PIR Sensor, speed controller - is it possible ? (Read 645 times) previous topic - next topic

Emil0101

Hi, good people.
I am trying to make an installation in which a PIR Sensor triggers a dc motor every time there is movement. I want the dc motor to be turned on for three minutes. In those three minutes I want the motor to stop every 20 sec, for 20 sec. Is it at all possible. For instance with a speed controller. Sorry if it it a stupid question,  this is my first time using an Arduino.
Thanks in advance.

CrossRoads

Yes, easy to do.
Code: [Select]

byte pirPin = 2;
byte motorPin = 3;
byte motorState = 0;
byte x;

void setup(){
pinMode (pirPin, INPUT_PULLUP); // assumes open-collector type that pulls the pin low when active
pinMode (motorPin, OUTPUT); // assume pin drive a transistor base (NPN) or gate (N-channel MOSFET)
                                                  // high to sink current through a  motor
}
void loop(){
if (digitalRead(pinPin) == LOW){
for (x=0; x<9; x=x+1){
motorState = 1 - motorState; // so 1-0-1, 0-1-0, 1-0-1
digitalWrite (motorPin, motorState);
delay (20000); // dumb delay, there are smarter ways to do this
}
digitalWrite (motorPin, LOW); // turn off at end
}
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Emil0101

Hi thanks a lot.
I am really happy that it is possible, I actually just copy pasted the code that you sent me to see how it worked, and this message popped up 'pinPin' was not declared in this scope. How can i fix this problem ?

Lunedor

Just change pinPin to pirPin at following line;

if (digitalRead(pinPin) == LOW)

Will be

if (digitalRead(pirPin) == LOW)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy