Need Intro Project Help!

New to Coding and Arduino, I picked up a starter kit and i have been trying to write the code for the fan module that came with the kit, but it is not performing as intended.

When code below is ran; the motor immediately turns on and I am unable to control it with the POT or the buttonpin.

After a while, motor speed will pick up the orange light on my board lights up and I basically cannot upload any new sketches to the project.

I am not sure as to what I have done wrong, I have followed the example given and have tried other possible solutions to the code online but none have worked.

The delay is set so I have a few seconds to upload blank sketch after plugging/unplugging board in. Thank you so much in advance!

const int buttonPin =11;
const int STATUS_LED =13;
int MOTOR_FORWARD =9;
int MOTOR_REVERSE =10;
int potPin =A0;
int MOTOR_MIN_SPEED =0;
int MOTOR_SPEED;
int MOTOR_MAX_SPEED =150;
int POT_VAL =0;
int buttonState =0;

void setup() {
Serial.begin(9600);
pinMode(buttonPin,INPUT);
pinMode(MOTOR_REVERSE,OUTPUT);
pinMode(MOTOR_FORWARD,OUTPUT);
pinMode(STATUS_LED,OUTPUT);

}

void loop() {
buttonState =digitalRead(buttonPin);
POT_VAL = analogRead (potPin);
MOTOR_SPEED = map (POT_VAL, 0, 1023, MOTOR_MIN_SPEED, MOTOR_MAX_SPEED);
analogWrite (MOTOR_SPEED, potPin);

if (buttonState ==LOW){
  analogWrite(MOTOR_FORWARD,MOTOR_MAX_SPEED);
  analogWrite(MOTOR_REVERSE,MOTOR_MIN_SPEED);
  digitalWrite(STATUS_LED,HIGH);
}
if (buttonState ==HIGH){
  analogWrite(MOTOR_REVERSE,MOTOR_MAX_SPEED);
  analogWrite(MOTOR_FORWARD,MOTOR_MIN_SPEED);
  digitalWrite(STATUS_LED,LOW);
}
delay(8000);

}

Hello eye(!),
Welcome.

You are assuming those of us who can help are familiar with the kit you have and whatever example you are using, this is unlikely to be the case

Please post a schematic of your wiring, hand drawn and photographed is fine. Photos of what you have made help too, please make sure it is easy to follow the wiring in the photos.

Thanks

buttonState will always have a value, HIGH or LOW. Therefore the motor always run.

Here we go!

So this is the kit I have basically picked up from my local hobby store. (attached below hopefully)

I know it is an off kit but unfortunately guys, this is the one I have. Yes, I have already had to painfully and successfully reprogram the 16u2 chip using Flip and Atmel-Studio. Hence the delay in the code to give me some time to catch it if it malfunctions. :joy:

Included is an image of the Sensor Shield connections as it will only let me post one image as a new user. Will add more as I figure out how.

@Railroader I understand that the buttonState is either HIGH or LOW. The motor does run, but almost has a mind of its own; runs at low speed and then kicks in to high gear and an orange light comes up in the upper left location of the Sensor Shield above the Green “ON” light in the same position.

  1. The goal of the Sketch is to have the fan motor spin at the speed (Set from 0 to 150) varied by the analog potentiometer in location A0

  2. The buttonPin in location 11 is supposed to trigger the fan motor to spin in reverse while the STATUS_LED is supposed to be a confirmation.

  3. The fan motor is connected to row 9, with INA = 9 and INB = 10 as my connections.

Hello eye,

Please edit your code to format it as code, select all the code and use the </> on the toolbar.

Your photo is next to useless as I can only see one end of the wires. Please create and post a schematic. A list of this connected to that is useless. Please read How to get the best out of this forum before posting anything else.

Thanks,

@PerryBebbington All right, deleted previous post about the code as it was not in the </> format. I do not understand how to draw a schematic for this as this is Day-4 of ever doing anything like this.

I will try to draw and post everything as it is plugged in. It really is just a plug and play kit that allows you to edit the code on Arduino. pin13 is a simple red_led chip with white(ground) red(+) black (-). The four-red wires are respective to the board, top to bottom (G, V ,S) with pin11 being momentary push button, pinA0 is potentiometer, and pin9 (Ground, Voltage, INA), and finally pin10(INB).

(Example)
Potentiometer-on-Chip------------------------------Board
(G)------------------------(Black_Wire)----------(G)pinA0 on black row
(V)-------------------------(Red_Wire)------------(V)pinA0 on red row
(S)-------------------------(White__Wire)--------(S)pinA0 on white row

int buttonPin =11;
int STATUS_LED =13;
int MOTOR_FORWARD =9;
int MOTOR_REVERSE =10;
int potPin =A0;
int MOTOR_MIN_SPEED =0;
int MOTOR_SPEED;
int MOTOR_MAX_SPEED =150;
int POT_VAL;
int buttonState =0;

void setup() {
pinMode(buttonPin,INPUT);
pinMode(MOTOR_REVERSE,OUTPUT);
pinMode(MOTOR_FORWARD,OUTPUT);
pinMode(STATUS_LED,OUTPUT);

}

void loop() {
buttonState =digitalRead(buttonPin);
POT_VAL = analogRead (potPin);
MOTOR_SPEED = map (POT_VAL, 0, 1023, MOTOR_MIN_SPEED, MOTOR_MAX_SPEED);

if (buttonState ==LOW){
  analogWrite(MOTOR_FORWARD,MOTOR_SPEED);
  digitalWrite(MOTOR_REVERSE,LOW);
  digitalWrite(STATUS_LED,HIGH);
}
if (buttonState ==HIGH){
  analogWrite(MOTOR_REVERSE,MOTOR_SPEED);
  digitalWrite(MOTOR_FORWARD,LOW);
  digitalWrite(STATUS_LED,LOW);
}
delay(8000);
}