Go Down

Topic: Code is not working in my project (Read 483 times) previous topic - next topic


Dec 02, 2016, 09:51 am Last Edit: Dec 02, 2016, 10:07 am by myboss11
Im new to coding
Im a bacholar mechanical engineer
And this is my project
So we have 4 zero relays control 4 motors and 7 high relays
Can you help me fix the code
The rmotor wont start

Heres the code

Code: [Select]
int button = 22;  // Start button input pin
const int rmotor = 21;  // paper roller motor
int rsensor = 45; // slotted switch paper rotor

const int cmotord = 10; // cutter motor down
const int cmotoru = 11; // cutter motor up
int csensord = 39; // cutter down sensor
int csensoru = 37; // cutton up sensor

int pu = 35; //pnumatic up motor
int pd = 31; // pnumatic down motor
int ps = 33; // pnumatic sucktion
int pccw = 9; // pnumatic counter clock wise motor sensor
int pcw = 8; // pnumatic clock wise motor
int pus = A0; //pnumatic up motor sensor
int pds = A1; // pnumatic down motor sensor
int pccws = 41; // pnumatic counter clock wise motor sensor
int pcws = 43; // pnumatic clock wise motor sensor

void setup() {
  pinMode(pu, OUTPUT);
  pinMode(ps, OUTPUT);
  pinMode(pd, OUTPUT);
  pinMode(pccw, OUTPUT);
  pinMode(pcw, OUTPUT);
  pinMode(pus, INPUT);
  pinMode(pds, INPUT);
  pinMode(pccws, INPUT);
  pinMode(pcws, INPUT);
  pinMode(rmotor, OUTPUT);
  pinMode(cmotord, OUTPUT);
  pinMode(cmotoru, OUTPUT);
  pinMode(button, INPUT);
  pinMode(rsensor, INPUT);
  pinMode(csensord, INPUT);
  pinMode(csensoru, INPUT);


void loop()
if (digitalRead(button))

if (digitalRead(rsensor)) {

digitalWrite(pd, HIGH);
digitalWrite(rmotor, LOW); //rotator motor moves the paper
delay (3000);
digitalWrite(pd, LOW);
digitalWrite(cmotord, HIGH); //the motor go down to cut the paper

  if (digitalRead(csensord)) {

digitalWrite(cmotord, LOW); //Establishes forward direction of Channel A
delay (500); //Disengage the Brake for Channel A
digitalWrite(cmotoru, HIGH); //Spins the motor on Channel A at full speed


if (digitalRead(csensoru))  {

digitalWrite(ps, HIGH);
delay (1000);
digitalWrite (pu, HIGH);


if (digitalRead(pus)) {
  digitalWrite (pu, LOW);
  digitalWrite (pccw, HIGH);

  if (digitalRead(pccws)) {
  digitalWrite (pccw, LOW);
  digitalWrite (pd, HIGH);

if (digitalRead(pds)) {
  digitalWrite (pd, LOW);
  digitalWrite (ps, LOW);
  digitalWrite (pu, HIGH);
  digitalWrite (pu, LOW);
  digitalWrite (pcw, HIGH);

 if (digitalRead(pcws)) {
  digitalWrite (pcw, LOW);




And there is funny smell in the circuits
I'd fix that first.

Please remember to use code tags when posting code.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.


We're probably going to need a schematic to be able to help you.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into sections is fine but large spaces for no reason just make for more scrolling when we're trying to read your code.

I'd recommend writing your code like:
Code: [Select]
if (digitalRead(button) == HIGH)
instead of:
Code: [Select]
if (digitalRead(button))
This will make it more clear which pin state your code is expecting. Frequently you will wire a button to ground so that you can use the internal pull-up resistor, this means that LOW would actually be the the state associated with a closed contact. To make things even more clear and the code more maintainable I will usually do something like this in my code:
Code: [Select]
const byte buttonPressedState = HIGH;
and then:
Code: [Select]
if (digitalRead(button) == buttonPressedState)


Dec 03, 2016, 02:14 am Last Edit: Dec 03, 2016, 02:14 am by lastchancename
I'm guessing OP has a low-side relay to switch ground/0v, and high-side relay to control each motor... Why? we have to guess.

If this is intended to control the motors forward/reverse - he may will better off with an H-Bridge, or two relays arranged as 'power on/off' (SPST), and 'reverse polarity' (DPDT).

Both solutions are very common and have a variety of applications based on motor power, requirement for PWM etc.
Experienced responders have a nose for laziness, (they were beginners once)... expecting the poster to contribute to the learning experience.

Go Up