How do I write a sketch for Pwm input of selected value on analog pin to give an output on a digital pin
Welcome to the forum
Your topic was MOVED to its current forum category which is more appropriate than the original as it is not an Introductory Tutorial
What PWM value are you hoping to measure using an analogue input, bearing in mind that a PWM signal is always either HIGH or LOW and what varies is the ratio of the time that the signal spends in each state ?
Take a look at the pulseIn() function instead
I am a beginner to the arduino. Programmes .
Have got the with potentiometer on analog input switching on led on output.
I would like to change the voltage reference to a Pwm signal from my Rc transmitter for use on my model boat.
I think the what is available is
1000 full reverse 1500 neutral 2000 full forward.
I would like to switch on led at approximately 1600 and 1800
If this makes sense
As I said
It allows you to measure the length of a pulse on a digital pin. The length of a pulse of a PWM signal varies as you change its pulse width. The 1000, 1500 and 2000 numbers that you quote are the two extremes and centre pulse widths (in microseconds) of standard servos
Basically you feed the signal that would normally go to a servo to an Arduino digital pin and use pulseIn() to measure the pulse width then use its value to determine whether any action should be taken
Start with something like this
byte receiverPin = 7;
unsigned long duration;
void setup()
{
Serial.begin(115200);
pinMode(receiverPin, INPUT);
}
void loop()
{
duration = pulseIn(receiverPin, HIGH);
Serial.println(duration);
delay(100);
}
Thanks this is a great help. Will be trying it tomorrow.
However could I impose and ask where do I get the output to the led
My example prints the pulse length. To control an LED on/off you need to test the length of the pulse and turn the LED on or off when it is greater than or less than your required values
Many thanks got some idea now.will get to work on it tomorrow
Report back how you get on and/or if you have any problems
Hi had a busy day, but have manage to get the board working. I can now switch on and off at any desired position of the throttle on the transmitter. Exactly what I was after.
Many thanks for your excellent help and advice.
It is a crude method, but it works as long as there is nothing much else going on in the sketch
Good luck with your project
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.