Nano + PIR + sequence speed DC motor
hello,
i used code (bellow) on nano detect presence , turn on dc motor.
i make launch "speed sequence" instead.
something
0-1000ms = 0 max speed (exponential)
1000ms-1200ms = 0 speed
1200ms-2200ms = 0 max speed (exponential)
2200ms-2400ms = 0 speed
2400ms-6000ms = max speed
something that, choregraphy dc motor.
i m aware big change code bellow, hope can help
// constant won't change:
const int pirpin = 2; // pin pushbutton attached to
const int ledpin = 13; // pin led attached to
// variables change:
bool piroutput = false; // counter number of button presses
int pirstate = 0; // current state of button
int lastpirstate = 0; // previous state of button
void setup() {
// initialize pin 2 input:
pinmode(pirpin, input);
// initialize led output:
pinmode(ledpin, output);
}
void loop() {
// read input pin:
pirstate = digitalread(pirpin);
// compare buttonstate previous state
if (pirstate != lastpirstate) {
// if state has changed, increment counter
if (pirstate == high) {
// if current state high button
// wend off on:
piroutput = true;
}
else {
// if current state low button
// wend on off:
// serial.println("off");
piroutput = false;
}
// delay little bit avoid bouncing
delay(50);
}
// save current state last state,
//for next time through loop
lastpirstate = pirstate;
// turns on led every time pir sensor detects motion
if (piroutput == true) {
digitalwrite(ledpin, high);
} else {
digitalwrite(ledpin, low);
}
}
i used code (bellow) on nano detect presence , turn on dc motor.
i make launch "speed sequence" instead.
something
0-1000ms = 0 max speed (exponential)
1000ms-1200ms = 0 speed
1200ms-2200ms = 0 max speed (exponential)
2200ms-2400ms = 0 speed
2400ms-6000ms = max speed
something that, choregraphy dc motor.
i m aware big change code bellow, hope can help
// constant won't change:
const int pirpin = 2; // pin pushbutton attached to
const int ledpin = 13; // pin led attached to
// variables change:
bool piroutput = false; // counter number of button presses
int pirstate = 0; // current state of button
int lastpirstate = 0; // previous state of button
void setup() {
// initialize pin 2 input:
pinmode(pirpin, input);
// initialize led output:
pinmode(ledpin, output);
}
void loop() {
// read input pin:
pirstate = digitalread(pirpin);
// compare buttonstate previous state
if (pirstate != lastpirstate) {
// if state has changed, increment counter
if (pirstate == high) {
// if current state high button
// wend off on:
piroutput = true;
}
else {
// if current state low button
// wend on off:
// serial.println("off");
piroutput = false;
}
// delay little bit avoid bouncing
delay(50);
}
// save current state last state,
//for next time through loop
lastpirstate = pirstate;
// turns on led every time pir sensor detects motion
if (piroutput == true) {
digitalwrite(ledpin, high);
} else {
digitalwrite(ledpin, low);
}
}
Arduino Forum > Using Arduino > Project Guidance > Nano + PIR + sequence speed DC motor
arduino
Comments
Post a Comment