// Code written with the wonderful help of MRMS - WORKSHOP // "How DC GEAT MOTOR Works with ARDUINO and L298N" // Created March 2020 // https://www.youtube.com/watch?v=GPVC84D5ULw int motorPin = 6; int resistorPin = A0; int lightVal = 125; //L298N MOTORDRIVER //direction control: int IN1 = 2; int IN2 = 4; void setup() { pinMode(motorPin, OUTPUT); pinMode(resistorPin, INPUT); pinMode(IN1, OUTPUT); //clockwise pinMode(IN2, OUTPUT); //counterclockwise Serial.begin(9600); } void loop() { int resistorValue = analogRead(resistorPin); Serial.println(resistorValue); if (resistorValue > lightVal) { delay(2000); digitalWrite(IN1, HIGH); //motor spins clockwise digitalWrite(IN2, LOW); delay(1000); digitalWrite(IN1, LOW); //motor stops for 2 seconds digitalWrite(IN2, LOW); delay(2000); digitalWrite(IN1, LOW); //motor spins counter clockwise to create slack digitalWrite(IN2, HIGH); delay(750); } else { digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); // motor doesnt spin } //for motor to spin counter clockwise //digitalWrite(IN1, LOW); //digitalWrite(IN2, HIGH); }