I am looking for help with my PWM Exhaust valve controller project please

why is that necessary.

I guess to preserve the life of the level shift transistors and partly to help me learn more about coding.

I have a level shift circuit to bump the serial voltage from +5v to +12v, This helps with noise interference and allows for any voltage drop along the cable to the valves.

Mike.

s200bym:
I guess to preserve the life of the level shift transistors

I doubt it would make any significant difference if the transistor is operating comfortably within its specifications.

I'm not good at electronics but I wonder if this simple circuit might be an option - I'm assuming you already have a resistor between the Tx pin and the transistor and that it is at least 500 ohms.

Tx ------> resistor ---------------------> base of transistor
                            |
                            |
I/O pin <-------------------

If the I/O pin is set as INPUT it should have no impact on the serial transmission. If it is set to OUTPUT and LOW it will pull the receiving device LOW even though the Tx pin remains HIGH.

DO NOT call me if the smoke escapes :slight_smile:

...R

EDIT to change the words "receiving device" to "base of transistor"

Unfortunately, that didn't work. it pulled the TX pin down but it just halved the voltage and kept it at +2.5V.

Thanks anyway,

I'll keep having a play over the next few days with different codes and functions.

Have a good Christmas.

Mike.

s200bym:
Unfortunately, that didn't work. it pulled the TX pin down but it just halved the voltage and kept it at +2.5V.

Note that I have changed Reply #21. However I assume you already did what is in the revised version.

My proposed circuit should have no effect on the Tx pin. If your Tx pin is pulled LOW then your circuit is not the same as my diagram and you are at risk of damaging the Tx pin and the I/O pin.

Make a simple pencil drawing showing how you have everything connected, and including details of the components, and post a photo of the drawing.

Also post the program.

...R

Hi Robin2, Hope you had a great Christmas?

Sketch and components

Code

int LED1 = 8; // Indicates Valve Closed
int LED2 = 9; // Indicates Valve Open
int LED3 = 10; // Power/Programme Running
int pullDown = 2; //Pulls TX Pin 1 Down

const int  buttonPin = 3;    // The pin that the pushbutton is attached to
const int valvepin = 1;      // The pin that the valves are attached to


int period = 15000;
unsigned long time_now = 0;

// Variables will change:
int buttonState;         // Current state of the button
int lastButtonState;     // Previous state of the button
bool valveStatus;



void setup()
{
  Serial.begin(9600);          //  Setup serial
  // Initialize the button pin as a input with pullup, active low
 pinMode(pullDown, OUTPUT);//Set pin 2 to output
  pinMode(buttonPin, INPUT_PULLUP);
  //Initialize button states
  buttonState = digitalRead(buttonPin);
  lastButtonState = buttonState;




  Serial.println("Exhaust Valves ");
  pinMode (LED1, OUTPUT);
  pinMode (LED2, OUTPUT);
  digitalWrite (LED3, HIGH);
  digitalWrite (pullDown, LOW);

}

void loop()

{

  // Read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // Compare the buttonState to its previous state
  if (buttonState != lastButtonState) //Changed
  {
    if (buttonState == LOW) //New press, so change valve flag
    {
      valveStatus = !valveStatus;
    }
    delay(50);
  }

  lastButtonState = buttonState; // Save the current state as the last state, for next time through the loop


  if (valveStatus) //Positions the valve
  {
    Serial.write(0x56);
    Serial.write(0x31);
    Serial.write(0x0A);

    Serial.print("Valve Status: ");
    Serial.print(" Valve Open");
    Serial.println(" (Loud Mode)");
    digitalWrite (LED1, LOW);
    digitalWrite (LED2, HIGH);
    
     {
while (digitalRead(buttonPin) == HIGH);
  }
    delay (200);

  }
  else
  {
    Serial.write(0x56);
    Serial.write(0x30);
    Serial.write(0x0A);

    Serial.print("Valve Status: ");
    Serial.print(" Valve Closed");
    Serial.println(" (Quiet Mode)");
    digitalWrite (LED2, LOW);
    digitalWrite (LED1, HIGH);
    
     {
while (digitalRead(buttonPin) == HIGH);
  }
    delay (200);
  
  
    }
  
}

Thanks for the nice clear diagram.

This is a case where this is inappropriate - and especially not in setup()

 pinMode(pullDown, OUTPUT);//Set pin 2 to output

Normally that pinMode should be INPUT. And when you want to disable the Tx signal you should change it to OUTPUT and set it LOW. When you want to re-enable the Tx signal set it back to INPUT which is the high impedance state.

Something like this pseudo code

if (txShouldBeEnabled == true) {
   pinMode(pullDown, INPUT);
}
else {
  pinMode(pullDown, OUTPUT);
  digitalWrite(pullDown, LOW);
}

Have you measured the voltage at the base of the transistor when the pullDown pin is OUTPUT and LOW?

...R

I'm clearly doing something wrong.

I guess it is to do with the code.

when I put your pseudo code in it threw up an error for "txShouldBeEnabled" saying it is not declared in scope, so I changed it to "valvePin" and it then verified but I am not getting any results. It just shows +5V all the time.

int LED1 = 8; // Indicates Valve Closed
int LED2 = 9; // Indicates Valve Open
int LED3 = 10; // Power/Programme Running
int pullDown = 2; //Pulls TX Pin 1 Down

const int  buttonPin = 3;    // The pin that the pushbutton is attached to
const int valvePin = 1;      // The pin that the valves are attached to


int period = 15000;
unsigned long time_now = 0;

// Variables will change:
int buttonState;         // Current state of the button
int lastButtonState;     // Previous state of the button
bool valveStatus;



void setup()
{
  Serial.begin(9600);          //  Setup serial
  // Initialize the button pin as a input with pullup, active low
  pinMode(buttonPin, INPUT_PULLUP);
  //Initialize button states
  buttonState = digitalRead(buttonPin);
  lastButtonState = buttonState;




  Serial.println("Exhaust Valves ");
  pinMode (LED1, OUTPUT);
  pinMode (LED2, OUTPUT);
  digitalWrite (LED3, HIGH);
  

}

void loop()



{

  // Read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // Compare the buttonState to its previous state
  if (buttonState != lastButtonState) //Changed
  {
    if (buttonState == LOW) //New press, so change valve flag
    {
      valveStatus = !valveStatus;
    }
    delay(50);
  }

  lastButtonState = buttonState; // Save the current state as the last state, for next time through the loop


  if (valveStatus) //Positions the valve
  {
    Serial.write(0x56);
    Serial.write(0x31);
    Serial.write(0x0A);

    Serial.print("Valve Status: ");
    Serial.print(" Valve Open");
    Serial.println(" (Loud Mode)");
    digitalWrite (LED1, LOW);
    digitalWrite (LED2, HIGH);
    
    if (valvePin == true) {
   pinMode(pullDown, INPUT);
}
else {
  pinMode(pullDown, OUTPUT);
  digitalWrite(pullDown, LOW);
}
    
     {
while (digitalRead(buttonPin) == HIGH);
  }
    delay (200);

  }
  else
  {
    Serial.write(0x56);
    Serial.write(0x30);
    Serial.write(0x0A);

    Serial.print("Valve Status: ");
    Serial.print(" Valve Closed");
    Serial.println(" (Quiet Mode)");
    digitalWrite (LED2, LOW);
    digitalWrite (LED1, HIGH);
    
    if (valvePin == HIGH) {
   pinMode(pullDown, INPUT);
}
else {
  pinMode(pullDown, OUTPUT);
  digitalWrite(pullDown, LOW);
}
    
     {
while (digitalRead(buttonPin) == HIGH);
  }
    delay (200);
  
  
    }
  
}

s200bym:
when I put your pseudo code in it threw up an error for "txShouldBeEnabled" saying it is not declared in scope,

That's not surprising. I was assuming you would know to create a boolean variable at the top of your program. Also, while I am perfectly happy for you to use my code, I had assumed you would just adapt the concept into your own program.

I have no idea why you would call the variable "valvePin".

...R

To be honest I think I am going to knock this on the head and just leave it how it is for now. I haven't really a clue about coding. The program I have here I had a lot of help with and as you can probably tell it is a very messy code. I don't even really understand what a lot of it means. some of the code I added worked out of sheer luck.

The electrical circuitry side of things I can do no problem and the bits I don't know I can pick up quickly. Coding, on the other hand, I am really struggling to pick up.

I guess I need to try and find a course like a C/C++ course and try and go from there.

Thanks very much for your help anyway.

Mike.

s200bym:
I guess I need to try and find a course like a C/C++ course and try and go from there.

My suggestion is to look for a course that is centred on Arduinos because regular C/C++ for PCs has a lot of stuff that is not relevant to an Arduino and a lot of that will probably appear early in the course.

...R

Sent you a PM if you have a few minutes for a question or two about this kit. Thanks.

a4000:
Sent you a PM if you have a few minutes for a question or two about this kit. Thanks.

To whom did you send a PM?

Most of the regulars don't deal with questions in PMs. Questions should be posted in the public Forum.

Also, you should start your own Thread - unless you are trying to assist with this Thread.

...R

Robin2:
To whom did you send a PM?

Most of the regulars don't deal with questions in PMs. Questions should be posted in the public Forum.

Also, you should start your own Thread - unless you are trying to assist with this Thread.

...R

Sent PM to OP concerning the kit purchased, not an arduino question.