# Setup not working-Arduino

#### Man10

Joined Jul 31, 2018
122
I connected a bts7960 board to a mabuchi 555 motor and I connected the bts7960 board to a 8 volt battery. I connected the bts7960 board to an arduino uno. The arduino uno is suppose to pick a random number. There are only 3 possibilities. They are 0, 1 and 2. If it picks a 1, it lowers a rock and then raises a rock. If it picks a 0 or 2, then it's not suppose to do anything. However sometimes it picks a 2 and lowers the rock and will not raise a rock.
This does not happen every single time. Sometimes it picks a 0 and lowers the rock and will not raise the rock. This does not happen every single time. Why is it not working as intended? If it were then if it picks a 0 or 2, then nothing would happen. But it sometimes lowers the rock, when picking a 0 or 2.

#### Man10

Joined Jul 31, 2018
122
Here is a schematic

#### Man10

Joined Jul 31, 2018
122
C:
long v;
Void setup() {
pinMode( 6, OUTPUT );
pinMode( 5, OUTPUT );

Serial.begin(9600);
v = random(0, 3);
Serial.println( v );

If( v == 1 ) {

analogWrite( 6, 100 );
anologWrite( 5, 0 );
delay(300);
analogWrite( 6, 0 );
anologWrite( 5, 0 );
delay(4000);
analogWrite( 6, 0 );
anologWrite( 5, 100 );
delay(300);
analogWrite( 6, 0 );
anologWrite( 5, 0 );
delay(4000);
}

}
Mod edit: code tags-JohnInTX

Last edited by a moderator:

#### Man10

Joined Jul 31, 2018
122
Here is the code I use.

#### trebla

Joined Jun 29, 2019
486
This is the setup section code, it runs only once after startup.

#### Ya’akov

Joined Jan 27, 2019
6,289
setup() runs once, to set up various hardware and constants.

loop() runs after that, and loops until it is terminated.

If you want something to run over and over, put it in loop().

#### trebla

Joined Jun 29, 2019
486
anologWrite( 5, 0 );
No such function i can found in common Arduino environment.

random(0,3) gives numbers 0 to 3, so there is four possibilities.

#### trebla

Joined Jun 29, 2019
486
This is about the analogWrite() function not anologWrite()

#### Man10

Joined Jul 31, 2018
122
setup() runs once, to set up various hardware and constants.

loop() runs after that, and loops until it is terminated.

If you want something to run over and over, put it in loop().
I don't want it to run over and over. I want it to run only once when I start the program.

#### Man10

Joined Jul 31, 2018
122
This is about the analogWrite() function not anologWrite()
I sure I wrote analogWrite in the arduino ide. I double checked the code a lot. AnologWrite was a typo.

#### trebla

Joined Jun 29, 2019
486
I sure I wrote analogWrite in the arduino ide. I double checked the code a lot. AnologWrite was a typo.
Maybe is better if you paste code from IDE (using <code> tags). It is difficult to found problems if code is incompletely presented here.

#### Man10

Joined Jul 31, 2018
122
long v;
Void setup() {
pinMode( 6, OUTPUT );
pinMode( 5, OUTPUT );

Serial.begin(9600);
v = random(0, 3);
Serial.println( v );

If( v == 1 ) {

analogWrite( 6, 100 );
analogWrite( 5, 0 );
delay(300);
analogWrite( 6, 0 );
analogWrite( 5, 0 );
delay(4000);
analogWrite( 6, 0 );
analogWrite( 5, 100 );
delay(300);
analogWrite( 6, 0 );
analogWrite( 5, 0 );
delay(4000);
}

}

#### Man10

Joined Jul 31, 2018
122
This is the code I wrote in the arduino ide. When I tried to copy the code I used onto the forum I made some typos.

#### trebla

Joined Jun 29, 2019
486
The code should work, unless Serial.println() does not interfere with PWM setup. You can insert a second long delay after print command to be sure. But i suspect loose wires, maybe from pin 6 or supply.