Getting This Fan To Work

I am trying to get a fan to blow 3 seconds then stop for 27 minutes. My connections and code may be all wrong. Here is the schematic but I have substituted an AI Thinker ESP32 Cam. I have replaced the Uno in this image with my camera.

    https://github.com/espressif/arduino-esp32

  Please be sure to select the right ESP32 module
  in the Tools -> Board menu!

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

/* Fill-in your Template ID (only if using Blynk.Cloud) */
//Device 10
#define BLYNK_TEMPLATE_ID   ""


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

const int RELAY_PIN = A5; // the Arduino pin, which connects to the IN pin of relay

int speedPin=5;
int dir1=4;
int dir2=3;
int mSpeed=255;


// the setup function runs once when you press reset or power the board
void setup()
{
  // Debug console
// initialize digital pin A5 as an output.

pinMode(RELAY_PIN, OUTPUT);
pinMode (speedPin, OUTPUT);
pinMode (dir1, OUTPUT);
pinMode (dir2, OUTPUT);
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
}
// the loop function runs over and over again forever
void loop()
{
  Blynk.run();
 
 digitalWrite(RELAY_PIN, HIGH); // turn on fan 3 seconds
 delay(3000);
 digitalWrite (RELAY_PIN, LOW); // turn off fan 1797 seconds
 delay(1797000);
  digitalWrite (dir1, HIGH);
digitalWrite (dir2, LOW);
analogWrite (speedPin, mSpeed);```


Here is a drawing of the device, with explanation:

[Schematic_Bug_Cam_2022-05-21.pdf|attachment](upload://nTl8PkClp7vuNjzRiUBE9VhWov0.pdf) (32.9 KB)

Right now, the fan will not spin.  I would like to use millis so that the fan can operate without disrupting other portions of the program.

Can you help a newbie reduce the learning curve?

If you want your program to be responsive, you need to get rid of those delay() calls and just track elapsed time since the start of an event. Look at the Blink Without Delay example in the IDE (File->examples->02.digital->Blink Without Delay).

You will also need to keep track of what state the program is in (fan_on/fan_off) so you know what to do when the desired time has elapsed.

1 Like

Thank you. I will look at that right now.

Where?

Hi,

Have you got code that JUST turns the fan ON and OFF, to prove your circuit?
Nothing else in your code.

Do this before adding any other code.
Develop your code in stages.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

int speedPin=5;
int dir1=4;
int dir2=3;
int mSpeed=255;

void setup() {
  // put your setup code here, to run once:
pinMode (speedPin, OUTPUT);
pinMode (dir1, OUTPUT);
pinMode (dir2, OUTPUT);
Serial.begin (115200);
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite (dir1, HIGH);
digitalWrite (dir2, LOW);
analogWrite (speedPin, mSpeed);

}```

Hi,

Does your code make the motor spin?

Your diagram ahs the bottom cut off.

Tom.. :smiley: :+1: :coffee: :australia:

In that case your schematic is not useful. Uno and ESP32 have different pins and voltages. We will not be able to spot any error you have made with that schematic.

Please post a schematic showing the components you are using, how you have wired them together, what power supplies you are using. Hand drawn schematic of your circuit is better than a professionally produced schematic of a different circuit.

Here's a 3 second ON every 30 minutes non blocking timer, adjust to your preference.

void loop()
{
  static unsigned long start = millis();
  unsigned long interval = 1800000, // 30 minutes
                runTime = 3000; // 3 seconds
  
  if(millis() - start > interval)
    start += interval;
  digitalWrite(RELAY_PIN,millis() - start < runTime);  
  //  more
  //            code
  //                     here
  //
} // end loop

Yes, the original fan code made the fan spin with the Uno. I did not want to use Uno unless I can get it to be a slave to my ESP32 cam or vice versa. I explored how to do that, but it felt I was going down a rabbit hole.

Thank you.

The schematic and the code for the fan alone were prepared for me by a friend of one of my former employees. I would have preferred that he use the ESP32 cam but he was doing me a favor.

Sorry, I have attached an updated schematic.

Hi,
So your UNO circuit worked and you are now trying to get an ESP32 version working?

Can you now post your ESP32 schematic?

You are aware that the ESP32 uses 3V3 logic not 5V like the UNO?

Can you post a link to motor data/specs?

Do you have a DMM?

How are you powering the motor in the ESP32 circuit?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Thank you. I will work on putting these things together.

Dealing with medical and work situations over last 2 days. I will finish it today.

I am editing the sketch to reflect this schematic.

@TomGeorge I have replaced the UNO with the Nano 33 IoT. Link to motor data/specs, https://datasheets.raspberrypi.com/case-fan/case-fan-product-brief.pdf I will power it through a 9v battery that is reduced to 5v.

Hi,

What sort of battery?
A small 9V smoke detector battery will not be able to supply the current.

Tom.. :smiley: :+1: :coffee: :australia: