Hi, I'm working on a school project where I'm building a small convyeor belt using an Arduino, DC motor and IR sensor for moving object detection so my color sensor can read color value.
I'm using single mosfet IRFZ44N to control DC motor. I can control DC motor using mosfet normally as turning it ON/OFF using digitalWrite using an arduino.
So, I want to stop convyeyor belt for 500ms when IR sensor detects HIGH and let color sensor read color of object and then let object move ahead normally on belt.
I have written below code but the IR sensor detect object but motor never stops running.
#define IR_COLOR 8 // ESP32 pin GIOP18 connected to OUT pin of IR obstacle avoidance sensor
//#define IR_RED 35
#define Motor 9
unsigned long previousMillis = 0;
const long interval = 1000;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// initialize the Arduino's pin as aninput
pinMode(IR_COLOR, INPUT);
pinMode(Motor, OUTPUT);
// pinMode(IR_RED, INPUT);
//digitalWrite(Motor, HIGH);
}
void loop() {
// read the state of the the input pin:
int state = digitalRead(IR_COLOR);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval){
previousMillis = currentMillis;
if (state == LOW)
digitalWrite(Motor, LOW);
else
(state == HIGH);
digitalWrite(Motor, HIGH);
}}
I'm not sure why you think that this is related to "Avrdude, stk500, Bootloader" issues hence your topic has been moved to a more suitable location on the forum.
I have provided code and as you suggested I inserted few Serial.println() for debugging purpose but still motor keeps running. I'm definitely missing something in my code.
#define IR_COLOR 8 // ESP32 pin GIOP18 connected to OUT pin of IR obstacle avoidance sensor
//#define IR_RED 35
#define Motor 9
unsigned long previousMillis = 0;
const long interval = 1000;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// initialize the Arduino's pin as aninput
pinMode(IR_COLOR, INPUT);
pinMode(Motor, OUTPUT);
// pinMode(IR_RED, INPUT);
//digitalWrite(Motor, HIGH);
}
void loop() {
// read the state of the the input pin:
int state = digitalRead(IR_COLOR);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval){
previousMillis = currentMillis;
if (state == LOW)
digitalWrite(Motor, LOW);
else
(state == HIGH);
digitalWrite(Motor, HIGH);
}}
I haven't figured out that how I can start motor after 500ms again. As I write LOW, Motor pin remains OFF as it is still detecting obstacle ahead of it. I want to start motorpin again after 500ms to continue work!