I am Ajay Singh, a beginner at Arduino. I am trying to control a 12 V PWM-controlled motor. I am using the ESP-32S LEDC method to modify the PWM. I am using the adafruitIO platform to control PWM using Wi-Fi.
I have attached the power and ground wires to the 12 V power supply. The blue is connected to one of the PWM ports (pin 16) of the board. I am able to change the PWM that I checked with the multimeter. But the fan keeps running at full speed without any effect of PWM on it.
I have not connected the yellow wire (rpm wire) anywhere. Any help would be highly appreciated. Below is the code and image of the hardware. Thanks in advance!
#include "config.h"
/************************ Example Starts Here *******************************/
// this should correspond to a pin with PWM capability
#define fanPin 16
// setting PWM properties
const int freq = 25000;
const int ledChannel = 0;
const int resolution = 10; //0 = 0%, 1024=100%
// set up the 'analog' feed
AdafruitIO_Feed *dcFan = io.feed("dcFan");
int count=0;
unsigned long start_time;
int rpm;
void IRAM_ATTR isr() {
}
void setup() {
//Adafruit IO controls are set for 10 bit direct control of both fans 0 = 0%, 1024 = 100%
ledcAttachPin(fanPin, ledChannel);
ledcSetup(ledChannel, freq, resolution);
// start the serial connection
Serial.begin(115200);
attachInterrupt(22, isr, RISING);
// wait for serial monitor to open
while(! Serial);
// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();
// set up a message handler for the 'dcFan' feed.
// the handleMessage function (defined below)
// will be called whenever a message is
// received from adafruit io.
dcFan->onMessage(handleMessage);
// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
dcFan->get();
}
void loop() {
// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
io.run();
}
// this function is called whenever an 'dcFan' message
// is received from Adafruit IO. it was attached to
// the analog feed in the setup() function above.
void handleMessage(AdafruitIO_Data *data) {
// convert the data to integer
int reading = data->toInt();
Serial.print("received <- ");
Serial.println(reading);
/*int frequency = ledcReadFreq(ledChannel);
Serial.print("Fan frequency: ");
//Serial.print(reading_float);
Serial.println(frequency);
*/
int duty = ledcRead(ledChannel);
Serial.print("fan duty cycle: ");
//Serial.print(reading_float);
Serial.println(duty);
// write the current 'reading' to the led
ledcWrite(ledChannel, reading); // ESP32 analogWrite()
}
type or paste code here
Thank you for your response. I am sorry I am not using any driver. Do I need one, if I am already able to modify the PWM on ESP32 PIN, which is directly connected to the fan's blue wire?
I have not confirmed it with oscillocope, but I have checked the voltage level with multimeter and it is showing voltage between 1 to 3 V when I am modifying the duty cycle.
In such case, I would quickly check the Motor functionality using an Arduino UNO which can supply 25 kHz (0-5V) PWM signal at DPin-9. Be sure that the GND-pin of 12V supply is connected with GND-pin of UNO. Test Sketch for Arduino UNO (compiled and not tested):
Oh, I see, thank you very much. It's working now. Actually, I just goggled about the wire configuration, and yellow wire is tech wire generally. But for this motor YELLOW is PWM. Thanks a lot again!
Hello again, I am having some trouble adjusting PWM. So, what's happening is that sometimes the PWM signal gets changed, but sometimes it won't. I tested it once, and it worked fine the voltage on the terminal and the speed of the motor changed. But the next time I try it again, I get a 0.8 v PWM signal which doesn't change.
I read about ESP32S and they said that some pins are active low and I need to initialize these pins to active low in the setup function of the code. But, I haven't tried it yet. Any idea/suggestion what can be wrong here?