Switchable PWM project

Hi All,

So I'm trying to figure out how to make a switchblade PWM device. I'll have a wireless Relay/Mosfet set up to tell Arduino to switch between momentary commands. This is to control a brushless speed controller with fixed PWM input. I ask for help as i really do struggle writing code because of poor learning retention. Electronics I'm ok with due to it being hands on. So if any kind person can direct me in the right way that would be great.

Simple diagram of idea below

Remote swith with three functions

Off function 0% PWN output Always default function unless one of two switches pressed.

Switch 1 Momentary 30% PWM

Switch 2 Momentary 60% PWM

So Two inputs and Three PWM out puts for Arduino.

continuous script until turned off.

I'm looking to either make a circuit myself of just embed a current Arduino device already available smallest form factor possible 32bit preferable if you have any advice.

thank you all for any time and advice you can give.

The PWM duty cycle can be adjusted by analogWrite() on any Arduino.

Thank you Dr, The issue is i cannot comprehend how to write the code. i know i need to set pins for input and out put and PWM along with coding what pwm output for each switch etc. but I don't actually understand how that works. A switch in my hand is very east to understand but I don't understand how code works. sorry for being annoying but I'm being brutally honest as I'm struggling.

PWN level is governed by setting a number between 0 and 255 I believed I just don't understand how to implement it. and recommendation on a very small 32bit Arduino device?

Many thanks

If you want to do this project yourself then start with the IDE examples on button input and PWM. Else there is a Jobs and Paid Consultancy forum section for turnkey solutions.

fantastic so this isn't a forum to seek help and advice!!!!

Did you read the sticky topics on top of this forum section?

I'm not here to do your homework for free. Stepping out...

Hello regenerate3d

This is a nice project to get started.

Keep it simple and stupid firstly.
Run some tutorials for the hardware selected.
If you are happy with the results of the tutorials you can merge these to your project.

Have a nice day and enjoy coding in C++.

Thank you for replying. I've been working on this code for 6 months now, i have fairly severe learning issues related to reading and comprehension. That's why hands on is always better. i shall continue on and try and figure it out.

What is the frequency of your PWM signal?

Which 32-bit Arduino Board you have -- is it ESP32?

Currently don't have a board but i need it to be as small as possible and 32bit for future proofing reasons.

This is the code I've come up with and it wont work

#include <Servo.h>

Servo PWM;  // create servo object to control a servo

int SwitchLow = 2;  // Pin designation for Switch Medium Low
int SwitchMed = 3;  // Pin designation for Switch Medium Speed
int val;    // variable to read the value from the analog pin

void setup() {
  PWM.attach(9);  // attaches the servo on pin 9 to the servo object
}


void loop1() {
  val = digitalRead(SwitchLow);            // reads SwitchLow
  val = map(val, 0, 1, 0, 45);     // Once Switch Low pressed Arduino will output 40% duty cycle of PWM
  PWM.write(val);                  // sets the PWM according to the scaled value
  delay(15); // waits 15ms
}
  void loop2() { 
  val = digitalRead(SwitchMed);            // reads SwitchMed
  val = map(val, 0, 1, 0, 60);     // Once Switch Med pressed Arduino will output 60% duty cycle of PWM
  PWM.write(val);                  // sets the PWM according to the scaled value
  delay(15);                           // waits 15ms
  }

Did you study the Compiler messages?

Your sketch does not have a loop() function in it so will not compile. Is that what you mean ?

honestly I haven't a clue I am still struggling with understanding how the code works. Because its not actually in my hands and its virtual I can't just swap and replace component till i get it right.

Where did you get the code from ?

I don't know what that is. Due to learning issues I am unable to retain information. it's almost like memory loss

The compiler delivers messages for this.

just used the servo example and then tried to slice bit i kind of know to get it to work. one of the loops works on its own but when I add a second switch i falls apart. I'm using tinkercad Arduino simulator

26:1: error: 'Loop' does not name a type; did you mean 'loop'?

is returned on simulator

In function main': 46: undefined reference to loop'
error: ld returned 1 exit status

sorry this is returned the other one was a previous issue.

That message did not come from the sketch that you posted

Which simulator are you using ?