Need programing help for Arduino UNO R3

Need help writing and/or modifying code to control one or possibly two relays and one pwm output with an analog thumbwheel switch. Uploaded AnaloginOutSerial example to convert analog thumbwheel switch to the PWM output which worked fine. I am trying to modify code to also control one or possibly two relays simultaneously by the same thumbwheel switch. Relay is also PWM. Relay needs to turn on when thumbwheel switch is moved either direction and turn off when thumbwheel switch is centered/neutral position. I am new to this and would greatly appreciate any assistance.

Back to the top…

We need to see your schematic.
It’s unusual to read a thumbwheel via Analog, and equally unusual to drive relays with PWM
Your description of a thumbwheel is odd (Decimal, or Hex ?). Maybe links to the products you’re trying to use ?

Both can be done with a good reason , but we MUST see how everything is hooked up.

A photo is good, but a schematic tells us so much more.
Any code should be contained within [code tags]

1 Like

Also on Git

I will gather the information and explain in more detail what I am trying to achieve. It will take a some time.

8V Supply = 50mA
5V Supply = 374mA

proportional_roller_HECR2.pdf (357.2 KB)
Project-51.pdf (48.7 KB)

Schematic and supporting information is posted. The example I uploaded to CB works exactly as I need it to. I just need to add the two 5V relays to perform the other functions I need. Thank you.

Post a schematic as how you have wired it, that schematic from the arduino web site is missing lots of parts including the relays etc.

Very similar to mine...


Schematic.pdf (48.7 KB)
proportional_roller_HECR2.pdf (357.2 KB)
SVAB HERC II Thumbwheel switch is analog per manufacturer.

Schematic.pdf (48.7 KB)

Schematic looks OK. Just to refresh where we are at: At this point we know that relays cannot be PWMed unless in the seconds or longer rate otherwise they fry. Solid State relays can be PWMed on DC but have an upper PWM frequency generally in the Khz or greater.
The 12V relay powered by another relay is possibly confusing, At this point I will assume you cannot drive it with the Arduino, if so this is a viable solution.

I suggest you use a solid state relay for the PWMing, that will eliminate Module #2 and the 12V relay. Let us know if this helps.

That simulator is great! I will try it out and let you know how it works out. Thanks

Solved!
Thank you all for your help!

}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  // map it to the range of the analog out:
  outputValue = map(sensorValue, 0, 1023, 0, 255);
  // change the analog out value:
  analogWrite(analogOutPin, outputValue);

  // print the results to the Serial Monitor:
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);

  // wait 2 milliseconds before the next loop for the analog-to-digital
  // converter to settle after the last reading:
  delay(2);

    //*******************************************************************************
  // relays ON if sensor < 300, relays OFF if >=400, <=600, relays ON if sensor > 700, 
  //*******************************************************************************
    if (sensorValue > 700) {
    digitalWrite(relays, HIGH);
  } if (sensorValue < 300) {
    digitalWrite(relays, HIGH);
  } else if (sensorValue >= 400 && sensorValue <= 600) {
    digitalWrite(relays, LOW);}
}

  

 
 

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