Use of potentiometer code and response

No matter how I code the "map" or what values for "hi" or "lo" I use (see below for code), or which Analog pin (A0 A1, A2) or even changing out the potentiometer, I am unable to get the PC to read anything but the "lo" value for the output. It seems to ignore the value of the potentiometer as if no input is being obtained from the analog input. This problem is new, and up until recently I have used the "map" function countless times in prior work using this code with great success.

(I had had a problem with the com port assignment and uploaded the most recent version of the Arduino UNO program 1.8.3.)

Please advise, Regards.

int potpin = A2;
int hi = 1;
int lo = 500;

Val = map(analogRead(potpin), 0, 1023, hi, lo);

Please advise

OK. I advise you to post a schematic showing how the potentiometer is wired.

I advise you to quit f**king with map until you KNOW that you are getting good data from the potentiometer.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

int potpin = A2;
float rpm;
float Valt;
int hi = 1;
int lo = 50;
int pmno = 1;
int emno = 2;
// emno is number of on off intervals per sequence
int em1pin = 5;
int k = 1;
// k=1, 40-6000; k=2, 80-12000; k=3, 120-18000rpm; k=4 160-24000rpm
int ak = 1.;
float valc = .3;
float Val;
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(5, OUTPUT);
digitalWrite(5, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
// set up alternating electomagnets:
//now need to change on off time with pot:
//Val = analogRead(potpin);
Val = map(analogRead(potpin), 0, 1023, hi, lo);
Val = pow(Val,ak)/k;
//Val = valc*(Val * pow(k,(1/Val)));
// print line ON OFF
delay (Val);
//Serial.print(" Delay off is ");
//Serial.println(Val);
// sequence the EMs through MOSFETs
digitalWrite(em1pin, HIGH);
//next
//Val = analogRead(potpin);
Val = map(analogRead(potpin), 0, 1023, hi, lo);
Val = pow(Val,ak)/k;
// Val = valc*(Val * pow(k,(1/Val)));
delay (Val);
//Serial.print(" Delay on is ");
//Serial.println(Val);
digitalWrite(em1pin, LOW);
// next
Valt = Val*emno;
//rpm is Hz cps not rpm
rpm = 1000/(Valt)/pmno;
Serial.print("Hz is ");
Serial.println(rpm);
// return
}

The circuit is simple - no need to show a
Analog A0 or A1, or A2 to Potentiometer pin 2; either of pins 1 or 3 to Arduino UNO 5VDC power, and alternate to ground.

"The circuit is simple - no need to show a
Analog A0 or A1, or A2 to Potentiometer pin 2; either of pins 1 or 3 to Arduino UNO 5VDC power, and alternate to ground. "

The reason for the schematic is in your description. I have seen thousands of potentiometers and have never seen one with pin numbers. Show the schematic.

Paul

Per attachment

Potentiometer Circuit fro Arduino.pdf (125 KB)

My guess is the Arduino Analogs are non-functional for some reason?

hgkelly:
My guess is the Arduino Analogs are non-functional for some reason?

What do you get when you Serial.print the analog value?

Paul

Start with something simple, like this:

const byte potpin = A2;
const int hi = 1;
const int lo = 50;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int input = analogRead(potpin);
  Serial.print("input==");
  Serial.print(input);

  int mapped = map(input, 0, 1023, hi, lo);
  Serial.print(";  mapped==");
  Serial.print(mapped);
  Serial.println(";");


  delay(2000);
}

That will tell you if the potentiometer on A2 is wired correctly and map() is doing what you expect.

I get the correct Hz in the monitor print, but as noted, I am unable to adjust the setting from the potentiometer. The value given on the monitor corresponds to the "lo" setting on the "map" - always. I have tried different potentiometers. The result is always the same. Only one frequency is provided no matter the potentiometer setting.

I have been using this code for over a year without a problem. I may have fried the analog circuits in the Arduino by accident. That is all I can guess.

Thank you for your enquiry and assistance. Your further comments are very welcome.

here are the results from the monitor;

input == 1023; mapped ==50

I tried a new potentiometer and am amazed that the monitor now provides the correct pot readings! I have no idea why this has occurred since I had used this same pot for a test previously without success.

Thank you for your help. I will assume that somehow the answer was provided. The smoke has cleared

Regards,

HGKelly

Hi,
Good that you found the problem.
Can you please post your code, using code tags.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks..Tom.. :slight_smile:

hgkelly:
I tried a new potentiometer and am amazed that the monitor now provides the correct pot readings! I have no idea why this has occurred since I had used this same pot for a test previously without success.

Thank you for your help. I will assume that somehow the answer was provided. The smoke has cleared

Regards,

HGKelly

If you went back to the first POT, it will probably work correctly, now.

Paul