Trouble with flyback diode, I think

The project: I want to have a small 5v window fan controlled by temperature to bring cool air into my bedroom in the winter. I also want it to display the actual temp and target temp, and have the target temp controlled by momentary switches. I've made it, and it seemed to work perfectly on the breadboard, but when I soldered it up, the displays go funky (random characters) and the serial monitor shows that the actual temp is -127c (lowest value/null voltage). I'm also getting random button presses.

I thought that I had probably wired the flyback diode wrong across the fan terminals, but when I disconnect the fan, I'm still getting the same problem.

Any advice or tips to improve my code/wiring would be appreciated.

Cheers,
Scotty

EDIT: I have the wrong resistor values in the diagram. should be 9.7k on the temp reader and 820 on the switches.


#include <OneWire.h>
#include <DallasTemperature.h>
#include <TM1637Display.h>  //has to be the library from Robojax as it supports multiple display outputs


#define ONE_WIRE_BUS 13

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

float Celcius = 0;

const int buttonPin1 = 9, buttonPin2 = 8;  // the number of the pushbutton pins

// variables will change:
int button1_State = 0, button2_State = 0;  // variable for reading the pushbuttons status
int count_value = 20;  //sets initial target temp on startup
int prestate = 0;

/// Module 1 connection pins (Digital Pins)
#define CLK1 3
#define DIO1 2

// Module 2 connection pins (Digital Pins)
#define CLK2 5
#define DIO2 4

TM1637Display display1(CLK1, DIO1);// define display 1 object
TM1637Display display2(CLK2, DIO2);// define display 2 object

uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 };  // all segments clear



void setup(void)
{
  display1.setBrightness(0); //sets brightness to lowest
  display2.setBrightness(0);
  pinMode(10, OUTPUT);  //goes to mosfet
  Serial.begin(9600);  //i still don't really get why it's 9600...
  sensors.begin();

  // initialize the pushbutton pin as an input:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
}

void loop(void)
{
  sensors.requestTemperatures();  //checks temp
  Celcius = sensors.getTempCByIndex(0);  //defines temp as celcius


  Serial.print("Actual Temp: ");
  Serial.print(Celcius);
  Serial.print(" C    ");
  Serial.print("Target Temp: ");
  Serial.print(count_value);
  Serial.println(" C  ");  //records actual and target temp on one line


  display1.showNumberDecEx(Celcius, false);  //display one shows actual temp in degrees c
  display2.showNumberDecEx(count_value, false);  //display 2 shows target temp in degrees c


  if (Celcius > count_value) digitalWrite(10, HIGH); //tells mosfet to turn 5v fan on when actual temp is above target temp
  if (Celcius <= count_value) digitalWrite(10, LOW); //turns fan off when actual temp isat or below target temp

  // everything from here to the end is cut and paste from a sample button counter code i found online.
  button1_State = digitalRead(buttonPin1);
  button2_State = digitalRead(buttonPin2);
  // counter increment if the pushbutton 1 is pressed.
  if (button1_State == HIGH && prestate == 0) {
    count_value++;


    prestate = 1;
  }
  // counter decrement if the pushbutton 2 is pressed.
  else if (button2_State == HIGH && prestate == 0) {
    count_value--;


    prestate = 1;
  }
  else if (button1_State == LOW && button2_State == LOW) {
    prestate = 0;
  }

  delay(50);
}

Your component diagram is confusing. Please supply a circuit diagram. with properly named connections. and logic arrangement of all components.

Couple of things:

  1. it is poor form to make a junction like image it gives the viewer no way to follow your wires.

  2. You didn't show your power input.

  3. The best I can tell the diode is in correctly.

  4. The fan takes 100 ma. It may be marginal powering it from the board 5V.

  5. The fan is a brushless fan that will not take kindly to being PWM'd. I know you are currently just going ON/OFF but in case you consider it in the future.

I suggest you dump all the other code and run the fan on for 10 seconds and off for 10 seconds, just to prove the hardware is working. Consider using the example "blink without delay" code.

So are you powering this through the USB connector, or with 5 V to the "5V" pin?

The fan would not need a "flyback" diode if it is brushless as computer fans are. What is its actual current rating?

Your circuit diagram is pretty ambiguous here:
poor_fritzing

Only by magnifying could I establish what was going on - and determine the diode is correct.

You have a crossing wire which I think you meant to be connected?:
poor_fritzing2

Its very important with diagrams like this to know the conventions - crossing lines without a dot are not connected. Its best never to have more than 3 lines meeting at a connection point (which should have a dot to signify a join).

You run different wires on top of each other in several places - again this will cause confusion. The point of a circuit schematic diagram is to clarify, not confuse, so learning the conventions is vital to being able to communicate circuits effectively.

I've measured high voltage spikes from brushless fans being switched - use that diode!

Thanks! I’m super new at this so I just used Cirkit Designer to draw the diagram. I’m in the process of learning how to draw a proper circuit diagram so I can repost.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.