Problem with Code to Open Solenoids

High Im using a MAF voltage to open 3 solenoids progressively, as airflow increases.
The MAF puts out 0-5v as airflow increases.
The Nano output should be 50% duty pulse.
When I test the Nano, using it's own 3.3v, as a test signal (I verified that voltage is present.) , I get no digital output.
I'm kind of a noob. Any help would be appreciated.


#define INJECTOR_PIN 2
#define PUMP_PIN 3
#define MAF_PIN A0
#define SOLENOID1_PIN 4
#define SOLENOID2_PIN 5
#define SOLENOID3_PIN 6

unsigned long pulseDuration, pulseFrequency, previousMillis = 0;
double pulseProduct;

void setup() {
  pinMode(INJECTOR_PIN, INPUT);
  pinMode(PUMP_PIN, OUTPUT);
  pinMode(MAF_PIN, INPUT);
  pinMode(SOLENOID1_PIN, OUTPUT);
  pinMode(SOLENOID2_PIN, OUTPUT);
  pinMode(SOLENOID3_PIN, OUTPUT);
}

void loop() {
  if(millis() - previousMillis >= 50) {
    previousMillis = millis();
    pulseDuration = pulseIn(INJECTOR_PIN, HIGH);
    pulseFrequency = 60000 / pulseDuration; // Frequency in minutes

    pulseProduct = pulseDuration * pulseFrequency;

    if(pulseFrequency > 25) {
      analogWrite(PUMP_PIN, pulseProduct*4);
    } else if(pulseProduct == 0.3) {
      analogWrite(PUMP_PIN, 0.18*255);
    } else if(pulseProduct == 5.7) {
      analogWrite(PUMP_PIN, 255);
    } else {
      analogWrite(PUMP_PIN, 0);
    }

    float mafVoltage = analogRead(MAF_PIN) * (5.0 / 1023.0);
    if(mafVoltage > 1.7) {
      analogWrite(SOLENOID1_PIN, 0.5*255);
    }
    if(mafVoltage > 2.8) {
      analogWrite(SOLENOID2_PIN, 0.5*255);
    }
    if(mafVoltage > 3.9) {
      analogWrite(SOLENOID3_PIN, 0.5*255);
    }
  }
}

I just bought an oscilloscope, but I just used the VOM so far, to see there was no output.

It remained to explain what is connected to this pin and the purpose of this device.

I suggest you post a schematic (wiring0 of your project, even if done freehand

The obvious question is: did you get a value from reading the analog_in?

Yes. Though I expressed it awkwardly.
The 3.3v was taken to AO. I read 3.3v there.

There is another function involving INJECTOR_PIN2 that I am not testing yet. It makes dital output to the single pin3. But I'm not testing that one yet.

    pulseDuration = pulseIn(INJECTOR_PIN, HIGH);
    pulseFrequency = 60000 / pulseDuration; // Frequency in minutes
    pulseProduct = pulseDuration * pulseFrequency;

This part of your code is blocking nano.
See in the simulator.
" Nano_seensor - Wokwi ESP32, STM32, Arduino Simulator

With this part released, it does not print on the serial,
but with this part commented,
the value read from the potentiometer (simulating the sensor) appears on the serial.

Run the simulator with the part released and then comment on the part and run it again.
and vary the potentiometer value.

I think what we want is for you to use the serial monitor, and Serial.print()ing, to confirm the values of key variables and be certain they are properly informing the flow through your code.

I don't think I've ever gotten something to work, and know for sure it is doing it the way I want, relying only on the behaviour I observe.

Printing or extra LED feedback or logic analyzer or oscilloscope - whatever it is, a window into what the code is up to.

I leave most of that printing, if that's what I used, in the sketch. They chat quite a bit as they go about their business.

When deployed, the printing just goes into the bit bucket who cares?

TBH I would be adding printing before squinting if I were in the lab ready to take a closer look at you sketch.

a7

You thinks it block the whole Nano? I'm not testing injector code yet, but maybe it doesn't matter.
Ah I start to see now. Maybe the code can not run. Very smart. I didn't see that possibility.
Thank you

Yes that makes sense.
I never used the serial printer yet, so it's a good time to learn.
Thanks.

Hi.
I don't know if I'm really stupid, or if it's just limited to today, but I cannot make a waveform appear on this oscope/generator.
I need to supply my Nano with an approx. 20Hz 25% duty signal.
I've watched a dozen video on this model and am apparently missing something.
The instruction book help a little, but not enough.
This is the ADS1014D. Very cheap, low performance, but all I need is a general output and also read.
I see guys on YouTube and they have a wave right here.
I've connected the output to ch1 input. I push auto run, and various other buttons.
Basically every button I push just makes the wave parameters window disappear.




Edit: I think this scope is broken. Getting a replacement.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.