Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [pwm]

PWM is a form of signal modulation that allows digital output to approximate an analog signal. Use this for questions about using the PWM pins (marked with ~).

21
votes
1answer
37k views

What is the frequency of PWM output on Arduino

What frequency do Arduinos use for normal PWM when you use analogWrite()? And is it different for different Arduino model? I'm interested specifically in the Mega 2560, but also want to know if it's ...
18
votes
2answers
22k views

Why do some pins have a different PWM frequency?

According to the Arduino reference for analogWrite(), the PWM frequency on most pins is ~490 Hz. However, it's ~980 Hz for pins 5 and 6 on the Uno, and for pins 3 and 11 on the Leonardo. Why are ...
11
votes
5answers
14k views

How to output a true analog voltage at output pin

Regarding my program, it is a program that does some calculations and then outputs a voltage based on the result using analogWrite function. However my problem is that I had done my programming based ...
9
votes
2answers
23k views

Increase PWM bit resolution

I would like to increase the PWM bit resolution of the Arduino Uno. At this moment it is 8-bit which I consider too low. Is this possible without losing the ability of interrupts and delays? Koen ...
9
votes
3answers
3k views

Controlling water temperature accurately

I have following setup: Arduino Duemilanove Small water heater connected with optical relay (PWM is ok) Waterproof DS18B20 temperature sensor Unknown amount of water (but temperature sensor and ...
8
votes
2answers
3k views

Does millis() conflict with the PWM pins associated with timer 0?

I've read that the millis() function uses the same timer as a couple of PWM pins. If you're using those PWM pins, will millis() still return the correct value?
8
votes
3answers
1k views

Write PWM with only 8 bit? (Timer2)

I have a problem with the Servo library. I need to read a PPM signal and create a PWM signal of each channel. The problem is that PPM has a higher resolution than PWM so I want to use the 16 bit ...
7
votes
2answers
34k views

Set PWM frequency to 25 kHz

I currently can set four PWM pins to around 31 kHz with the following code: void setup() { TCCR1B = TCCR1B & B11111000 | B00000001; // Set PWM frequency for D9 & D10: pinMode(...
7
votes
2answers
8k views

How precise is the timing of pulseIn()?

I've been using the pulseIn() function for processing PWM-based binary data encoding. It works well for distinguishing pulses which are significantly different lengths, e.g. 500us vs. 1500us. That ...
7
votes
1answer
1k views

How can the Arduino Uno support up to 12 servos if it only has 6 digital PWM pins?

According to this: The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) ...
6
votes
3answers
901 views

Why does an RGB LED between VCC and PWM work?

I'm an Arduino beginner and I recently bought a cheap starter kit on eBay. One of the lessons in the starter kit is an RGB LED controlled by 3 PWM output pins. However, the arrangement of the ...
6
votes
3answers
1k views

Adjust time calculation after Timer0 frequency change

I have an Arduino Nano with an 328P and need all 6 PWM pins. Thus, I had to adjust the prescaler and WGM Mode of Timer0. It is now in phase correct PWM mode with a prescaler of 1. TCCR0A = _BV(...
5
votes
4answers
2k views

ArduinoUNO/MEGA, Is there a way to exceed 256 in analogWrite

I am using Arduino UNO/MEGA, I want to analogWrite(pin, val); where the value is 0-1023. How can I make that ? Thanks.
5
votes
4answers
11k views

Can I connect a PWM pin on one Arduino to an analog input on another?

I was considering several different ways to send simple data from one Arduino to another when I though, why not connect a PWN pin of one Arduino to the analog pin on another? I could send simple ...
5
votes
2answers
608 views

How can I use PWM in power saving mode (ATmega328)?

I fail to use PWM in power saving mode. The output behaves erratically. This should be possible, I guess. The following is a minimal working example: /* MWE: Cannot use PWM in any power saving ...
5
votes
1answer
988 views

Why does an LED sometimes flash when increasing brightness?

This is admittedly a cross-post from LED fade malfunction (random flash) but I can't get an answer on the Arduino forum. I was mucking around with some very basic code and I noticed that when ...
5
votes
1answer
5k views

Difference between PWM and regular output port for servos?

I have been controlling my servomotors for a while now only using pin 0. After some research, it has became apparent to me that the ports with ~ are the PWM pins. I thought that all pins sent out ...
5
votes
1answer
703 views

Simulating touchscreen input using PWM

I'm porting a project from a teensy microcontroller to the arduino. Essentially the project uses a microcontroller to simulate touchscreen input for the Nintendo 3DS console. I am doing this by ...
4
votes
1answer
367 views

Arduino PWM malfunctioning

I am controlling 4 motors using the PWM ports on an Arduino Uno (3,9,10,11). For some reason, the motor hooked up to port 11 doesn't move with my current code. I know it's a code issue because I can ...
4
votes
2answers
4k views

How to increment and decrement an output voltage by using two buttons?

I'm trying to create a code using an Arduino Uno board to increment and decrement the output voltage of the Arduino Uno which is 5 volts and I need to step it up to 10 volts which I have done below. ...
4
votes
2answers
146 views

How to move my robot in the right direction?

After all there is more question poping up then answers i decide to upload the pdf where is everything writen, like the wire, motor type and what we can and can't use. Here is the link pdf format of ...
4
votes
1answer
141 views

How can I maintain PWM output while still performing other tasks?

I want to generate a PWM signal that I can turn on and off with a button press without using interrupts. Is there a way to keep the PWM output going while running other processes?
4
votes
2answers
380 views

how to solve Varing duty cycle value while using Pulsein()

Well im new to coding, but i do have the basic knowledge. I'm using an UNO to measure a duty cycle. The source of pulse is a Tektronic signal generator (Duty cycle set to 50.000 with frequency of 2khz)...
4
votes
1answer
950 views

PWM multiplexing on Arduino nano

simulate this circuit – Schematic created using CircuitLab Its a simple project. I am trying to drive 3 RGB LEDs using Arduino Nano. Since Arduino Nano does not have 9 PWM pins, the only ...
4
votes
1answer
193 views

Help managing the fallout from timer0 mode and prescaler change on ATMega2560 without modifying wiring.c

For a driving application I need the PWM mode to be phase correct and the prescaler to be 1. The issue is that the board I am working with has the load hooked up to a PWM pin reliant on timer0. The ...
3
votes
1answer
1k views

Why do I get negative voltages for a PWM waveform?

I used my Arduino Uno's pin 3 to generate a PWM output. The code is: void setup() { // Put your setup code here, to run once: } void loop() { analogWrite(3, 180); } I connected the output ...
3
votes
2answers
7k views

attiny85 and arduino - analogRead + pwmOut

I am using the Arduino IDE to program the attiny85. I want to take an incoming analog reading, then based on that reading, output a specific PWM value. Here's my circuit: and here's my code: // to ...
3
votes
3answers
290 views

What is the phase of tone?

Is it garanteed (with some precision) that the phase of a PWM-signal generated by tone is the same on each pin? Can it be altered (by internal means of Arduino) so that it's different on different ...
3
votes
3answers
2k views

Arduino PWM fading led

I am trying to blink an LED with PWM on Arduino. I don't know what is wrong but my LED is not fading as expected. What is wrong? I think that I have bad registers settings, but I am not sure. LED ...
3
votes
4answers
6k views

Transistor amplifier to drive speaker using Arduino PWM [closed]

I have been working on a project lately which uses Arduino to play a wav file from SD card. I am using TMRPCM library which made the job very easy. But the problem is that the output sound in the ...
3
votes
2answers
1k views

If a Timer is used, disabling some PWM pins, can I still use those pins for Digital write?

It's my understanding that when a Timer is used on an Arduino (in my case the Arduino Mega), it can disable analog write on some PWM pins, which pins depends on the Timer being used. For instance on ...
3
votes
2answers
4k views

can i give a vcc to 14v?

What is maximum voltage PWM pins can give? can i give a vcc to 14v?
3
votes
1answer
970 views

PWM signaling with Arduinos: What is the reason for the ground connection?

This may sound like a very dumb question and I apologise in advance. I've gone through reading about PWM and working on some example sketches to control PC fan speeds using PWM and Arduino. In all ...
3
votes
3answers
15k views

Use Arduino's PWM to control motor direction?

I'm looking for a way to allow Arduino to control a motor using PWM. So far what I have gathered is that using Arduino's PWM sets the digital value of 255 to 5v and 0 to 0v. However what I am ...
3
votes
2answers
315 views

How to read OC0A when in CTC (toggle) mode?

I have this code, which puts the Arduino into CTC mode with interrupts, and outputs a square wave on PD6 (OC0A): void setup_timer(double p_ms, double duty){ DDRD |= (1 << 6); // set pin 3 as ...
3
votes
2answers
521 views

Can a timer be used in both CTC and (fast) PWM mode simultaneously?

I would like to generate a sequence of pulses of varying lengths in the range of 0-100us, so that from the start of one pulse to the start of the next there is a delay of 100us. I have set up timer0 ...
3
votes
2answers
23k views

How to control 19 RGB LED strips with one arduino?

I need to light up 19 RGB LED strips, which it seems would require 19*3=57 PWM outs and 57 transistors. The transistors aren't an issue, but of course the 57 PWM's is. Even if I hacked the digital ...
3
votes
2answers
283 views

Controlling two AC devices, device turning on incorrectly

I am making use of the code below to control the speed of an AC fan and the intensity of an AC Lamp with an Uno. The problem I am having is that, when I set the lamp intensity to low or medium, the ...
3
votes
7answers
20k views

How to eliminate noise from PWM controlled 12V fan at low speed

I am trying to build a simple fan controller (single fan). So far I have successfully created a circuit which powers the fan with an external 12v DC adapter and added a transistor (NPN) to switch it ...
3
votes
1answer
3k views

Do I need to use a resistor if I am using a potentiometer to control an LED's brightness?

I am currently tinkering with an arduino, and am using a potentiometer to change the brightness of an LED. I understand that usually, a resistor is added to the circuit to limit the current flowing ...
3
votes
1answer
283 views

Arduino leave PWM on

I am doing an aquarium light sunrise/sunset. Till now programming wise I only did the sunrise. After running the code the light starts to rise up fine, than at full brightness, it turns off. I want ...
3
votes
1answer
72 views

Timer interrupt triggers too often

The following question is based on the Arduino Pro Mini (8MHz, 3.3V) I'm in process of developing (yet another) LED strip driver shield. For that I wrote a simple control loop, that adjusts the ...
3
votes
1answer
100 views

Can you tell me if this circuit will work?

Here's an image of my circuit diagram. There are 8 9g servos connected to the arduino gpio pins. The servos have an external power supply of 3 volts (may vary depending on the voltage requirement of ...
3
votes
3answers
920 views

Is it possible to control the speed of DC motors with Arduino's analogWrite() using analog pins?

I'm trying to control the speed of two DC motors that are connected to a dual H bridge. I always used digital PWM pins with analogWrite() to change the speed, but since I'm making a project that will ...
3
votes
1answer
2k views

Fading the brightness of LEDs using MAX7219 and PWM

I am doing a project with bi-color led matrix 8x8 and MAX7219 as the LED driver. I want to implement a fading effect on the LEDs, like mixing the two colors by varying the individual duty cycles. My ...
3
votes
4answers
30k views

Control Speed of DC FAN Using Arduino PID Library

I want to make a circuit that control speed of DC fan Using Arduino PID Library to get thing at specific temperature. The circuit looks like this but can be changed, The dc fan motor connected to PWM ...
3
votes
2answers
564 views

How close to 5 kHz can I set the PWM frequency on an UNO pin 11?

I'm rebuilding a laser CNC machine and using LaserWeb4 as the control interface and GRBL 1.1 as the low-level interface to the stepper motors, limit switches and the laser. I have all the motion ...
3
votes
2answers
3k views

Multiple tones with one piezo buzzer

I have figured out how to make a piezo buzzer play two tones at once with analogWrite() and tone() but how would I make an actual song by playing both bass and treble, such as this one. Here is the ...
2
votes
2answers
813 views

Arduino PWM Pins Interrupt

I am creating pwm from an arduino pin with 50% duty cycle. I just want to know how can i detect its every falling edge using timer interrupt? I don't want to connect that PWM pin to an external ...
2
votes
2answers
245 views

Does the square-wave nature of PWM dictate how much resistance you need?

I think the answer is yes, but I wanted to ask the question anyway for future common reference. And to check my understanding. Say I want to power 10 LEDs with PWM with my Mega 2560. I have a bunch ...