Applying user input functionality to what I have already

Hi Everyone,

I have been working on a guitar amp which can be controlled via a phone, computer etc.

I am using Analog potentiometers and at the moment general hobyist motors through an L298N.

I have the values of the potentiometers printing out like they should and same with the motors however now I am wanting to be able to control the entire circuit through user input.

I am wanting to make the potentiometers to turn to defined value via the motors through the serial value of the potentiometer.

Inital pot Value → user applies no. between 1-10, Motor turns the pot to a serial value that has an applied field equal to what the user has applied i.e. 4=4.

I hope that explanation helps a little as I am pretty new to this.
any help on this would be greatly appreciated.

Here is the final output of my code currently.

// Code for Amp

int usrInput;
// initialising the motors
 struct MotorPins{
 const byte DIR;
 const byte ON;
 const byte PWM; } motors[] = {
//DIR  ON PWM 
  {22,  23,  2 }, // Motor 1
  {24,  25,  3 }, // Motor 2
  {26, 27, 4 }, // Motor 3
  {28,  29, 5}, // Motor 4
  {30,  31, 6} // Motor 5
};  

const byte mCount = sizeof(motors)/sizeof(motors[0]);

// initalising the potentiometers
byte Pots[] = {A0, A1, A2, A3, A4}; //define analog inputs connected to pots
byte numberPots = 5; //number of inputs to read

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

// Preparing the motor values
  for (MotorPins mp: motors){
    pinMode(mp.DIR, OUTPUT);
    pinMode(mp.ON, OUTPUT);
    pinMode(mp.PWM, OUTPUT);
  };
}

void motorLoop(){
// setting the direction to turn and speed
    for (MotorPins mp: motors){
    digitalWrite(mp.DIR , LOW);
    digitalWrite(mp.ON, HIGH);
    analogWrite(mp.PWM, 200);
  }; 
}

void loop() {
  for (byte i = 0; i < numberPots; i++) {
    Serial.print(analogRead(Pots[i])); //print value read from pot
    Serial.print(" "); //space between sensor value and text

  }
  Serial.println(); //print blank line between groups of output
  motorLoop();
  delay(1000); //slows loop to once per second
}

or individually

pot → https://www.tinkercad.com/things/1ps6LVLsc0n-potentiometer-read-setup/editel
motor → https://www.tinkercad.com/things/fFQKRTjhDrb-motor-initial-turn/editel

Thanks again for looking,
Ben :slight_smile:

BenjaminoTzu:
I am wanting to make the potentiometers to turn to defined value via the motors through the serial value of the potentiometer.

I'm struggling with that.

Am I correct to think there are two potentiometers and one motor. The motor rotates potentiometerA and the user rotates potentiometerB and you want the motor to move potentiometerA to match the position of potentiometerB.

If that's not correct then please write the correct version.

If it is correct, how is the motor supposed to know when potentiometerA is at the correct setting? You say you are using an L298 so I assume you are using a regular DC motor rather than a servo.

...R

Hi,

There would be 5 motors and 5 pots in the final version. I am using an arduino mega to put everything on. TinkerCAD doesn't have anything bigger than the arduino uno so the code is setup initially on there and taken straight down to arduino IDE.

Essentially I am wanting something along the lines of this but don't know how to go about doing it.

so the max value of the pots is 1023 so this value would be split into 10 sections like so.

0 / 0
1 / 90-110
2 / 190 -210
3 / 290 -310

and so on.

I am not sure if this would be the correct way to go about doing it as I have no background in using this language as I am doing this for an individual project at uni.

so the potentiometer may start at 0 then the user says that they want it to be at 6 so the motor would then turn the pot so that it equals the number so something like 590 - 610 would equal 6.

If that makes any sense to you.

Also not using servo's.

I have had a look at the map function and it doesn't look like it'll help as the things I have read and videos watched show that it is only used to map the one potentiometer.

Like this:

map (Value, 0 ,1023, 0, 255);

This also only tends to be used by people using servos could this be used to create what I am suggesting above?

I'm not sure if it would fix my issue as people are only using it to map 1 set of values on a pot they haven't used it to map multiple values to one pot.

BenjaminoTzu:
so the potentiometer may start at 0 then the user says that they want it to be at 6

This is the bit I can't understand.

How is the user going to provide the input?

so the motor would then turn the pot so that it equals the number so something like 590 - 610 would equal 6.

If the Arduino can measure the voltage at the teminals of the potentiometer then it can keep the motor running until the desired voltage is reached.

However I have been assuming that the potentiometer is being used to control something else - not just being turned for fun. What exactly are you trying to make?

If you want an Arduino to control the position of a potentiometer then a servo would be a great deal easier to use than a simple DC motor. Another option might to use a digital potentiometer that just needs a number sent to it by the Arduino.

...R

Robin2:
How is the user going to provide the input?

Initially I was thinking through the CIN command which would allow the user to put an input in
through the serial monitor. I do want to in future develop this so that it is changed via an input
box on a website however.

If the Arduino can measure the voltage at the teminals of the potentiometer then it can keep the motor running until the desired voltage is reached.

In a way yes that's the kind of thing I am wanting to do. In this case the pot could move
between 3.3v or 5v like what the serial readings show?

However I have been assuming that the potentiometer is being used to control something else - not just being turned for fun. What exactly are you trying to make?

I am making an amplifier which is usually controlled just by an analog potentiometer. People
have made amps which change settings on the amps through remotes and settings however
none of settings are visible on the potentiometers I.e. they don't move to reflect the changes.

I want to make an amplifier which you can turn the potentiometer manually by hand but also
turn it automatically.

The things the pot controls are the motor to define how far to turn it to reach desired settings
and to change the settings of the amp.

If you want an Arduino to control the position of a potentiometer then a servo would be a great deal easier to use than a simple DC motor. Another option might to use a digital potentiometer that just needs a number sent to it by the Arduino.

For this I am wanting it to move and have no resistance. I don't have a huge amount
of money to spend on this project so can't really afford servo's as for digital pots don't they jolt
when you turn them? I need it to be fluid as I am working with a valve amplifier which is 100%
analog. There valves are also fairly brittle and can stop working so need it to be completely fluid
to negate this problem.

Kind Regards,
Ben

BenjaminoTzu:
The things the pot controls are the motor to define how far to turn it to reach desired settings
and to change the settings of the amp.

This brings me right back to what I could not understand in your Original Post. Maybe you can draw a diagram showing how one of your 5 pots and motors is intended to work. Also have a look at my description in Reply #1 and see if you can describe what you are trying to do using a similar style.

I don't have a huge amount of money to spend on this project so can't really afford servo's

Small servos are not expensive. However if you want to be able to turn something manually as well as automatically then they are probably not suitable. On the other hand they are so simple to use that it may be worth giving up the option of manual adjustment.

as for digital pots don't they jolt when you turn them?

They don't have any moving parts - they are just microchips.

...R

Robin2:
This brings me right back to what I could not understand in your Original Post. Maybe you can draw a diagram showing how one of your 5 pots and motors is intended to work. Also have a look at my description in Reply #1 and see if you can describe what you are trying to do using a similar style.

I have attached a very rough diagram bellow with what the final product will look like from the font.
Essentially the motor will turn the pot via cogs.

Small servos are not expensive. However if you want to be able to turn something manually as well as automatically then they are probably not suitable. On the other hand they are so simple to use that it may be worth giving up the option of manual adjustment.

Unfortunately I don’t know if I’d be able to use them as the manual and automatic part of the amp is the whole reason why I am making it. If I can’t get this to work then I’ll have a look into them.

They don’t have any moving parts - they are just microchips.

Ah ok does this mean that they can’t be controlled by hand then?

…R

Image from Reply #7 so we don't have to download it. See this Simple Image Posting Guide

...R

Thanks for the diagram

However I’m still not clear how you want to use the thing. What is the purpose of the potentiometer?

…R

Robin2:
Thanks for the diagram

However I'm still not clear how you want to use the thing. What is the purpose of the potentiometer?

...R

All the pot does is allow the user to turn the amplifier volume, bass and treble up or down. This is what I need to be able to monitor and adapt the amp to work automatically. I need a way which will allow me to monitor the serial output and assign values to certain areas within the output.

This is an amp you can see it has many pots that is why I have 5 of them you would turn these to adjust the settings. The motor will be connected by cogs to adjust the setting of the pot to the desired one. So as above I just need a way to monitor it and react to it.

example.jpg

example.jpg

BenjaminoTzu:
This is an amp you can see it has many pots that is why I have 5 of them you would turn these to adjust the settings.

Am I correct then to think that the potentiometer in your diagram in Reply #8 is intended to represent one of the potentiometers in the picture in Reply #10?

If so, I don't understand why you appear to have a connection between the potentiometer and the Arduino in your diagram. What exactly are you thinking of connecting?

...R

Robin2:
Am I correct then to think that the potentiometer in your diagram in Reply #8 is intended to represent one of the potentiometers in the picture in Reply #10?

Yes that is correct.

If so, I don't understand why you appear to have a connection between the potentiometer and the Arduino in your diagram. What exactly are you thinking of connecting?

I have not included the amp in the diagram because that is a seperate circuit. It will only connect to the potentiometer nothing else. The pot is the only thing connected to both. The motor will be connected to the pot via a mechanism that I will machine.

...R

BenjaminoTzu:
I have not included the amp in the diagram because that is a seperate circuit. It will only connect to the potentiometer nothing else. The pot is the only thing connected to both. The motor will be connected to the pot via a mechanism that I will machine.

If the amp is a separate circuit then how can there be a connection to the Arduino from the potentiometer that is part of the amp?

It's proving extraordinarily difficult to get basic information from you.

...R

Robin2:
If the amp is a separate circuit then how can there be a connection to the Arduino from the potentiometer that is part of the amp?

It's proving extraordinarily difficult to get basic information from you.

...R

Let's forget about the amp bit all together because it's confusing.

All I am wanting to find out how to do is to map values to serial read outs but multiple per pot.

An amp has values from 1-10 to measure how much current/voltage is being passed through per pot. I want to replicate this digitally to a potentiometer somehow however I do not know how to.

The only thing I can find online is the map function which from what I can see only maps 1 set of values I would need 11 (0 , 1, 2, ,3, 4, 5, 6, 7, 8, 9, 10). So I am trying to find another way around this to sort my issue.

Do you have any idea of what could help me?

BenjaminoTzu:
Let’s forget about the amp bit all together because it’s confusing.

All I am wanting to find out how to do is to map values to serial read outs but multiple per pot.

An amp has values from 1-10 to measure how much current/voltage is being passed through per pot. I want to replicate this digitally to a potentiometer somehow however I do not know how to.

Getting 5 values from the Serial Monitor is straightforward. For example the user could enter <2,5,1,10,8> and the Arduino could receive them with the 3rd example in Serial Input Basics. And the parse example illustrates the technique needed to turn those characters into numbers.

If you want to expand those values so that the range 1-10 becomes the range 1 to 1023 then just multiplying the values by 100 will get you close enough. However I suspect it should be 1 - 255 in which case you should multiply by 25.

But that doesn’t even begin to solve your problem. First you need to have a practical strategy for controlling things - and I’m sorry. but I see no sign of that. You CANNOT get a DC motor to move to a specific position without some sort of feedback mechanism - all you can do is make it go fast or slow and change direction or stop.

…R