Interfacing with fan and using as switch

Hi all,

I'm currently working on my very first "real" Arduino project!

I recently made a spud gun with an electronic ignition, and I would like to use the Arduino to take care of the controls.

I connected the Arduino to a 16x1 LCD and to a transistor that drives a small fan.
The idea is: the display constantly displays the word "standby" unless the button is pressed, in which case the fan starts running for a couple of seconds.

In the future, another button and transistor circuit will be added to switch on the ignition.

Although the code and circuit work at the moment, I don't find them particularly elegant.

Especially the fact that the button press only gets detected when the code loop starts bothers me, since if I were to insert some long routines in the ELSE-statement, I would have to wait for them to finish before another button press is detected...

Any ideas on how to improve this?

Thanks!

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int loopCount=0;
int dispDeel=2;
int buttonState=0;
const int transPin=6;
const int buttonPin=7;

void setup(){
  lcd.begin(16, 2);
  pinMode(transPin, OUTPUT); // The pin that switches the transistor off or on
  pinMode(buttonPin, INPUT); // The pin that detects the button press
  lcd.setCursor(0, 0); // Puts cursor on leftmost position
  lcd.print("Standby  "); // Shows the word STANDBY after starting up
}

void loop(){
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) { // If the button is pressed
    for (int countE=0; countE < 3; countE++) { // This loops the ventilation sequence for three times (increase number for longer ventlation)
      digitalWrite(transPin, HIGH);  // Turn on the fan
      dispDeel=2;
      lcd.setCursor(0, 0);
      lcd.print("Ventiler"); // Puts the first 8 characters of the word "ventileren" on the screen
      lcd.setCursor(0, 1); // This is because it's a 16x1 fan; this puts text on the right half of the LCD
      lcd.print("en      ");
      delay(400);
         for (int loopCount = 0; loopCount < 3; loopCount++) { // A small loop to display a sequence of 3 flashing dots
          lcd.setCursor(dispDeel, 1);
          lcd.print(".");
          delay(900);
          dispDeel++;
           }
        } 
      lcd.setCursor(0, 0);
      lcd.print("Standby  "); // Puts the word STANDBY on the screen after the ventlation sequence has finished
      lcd.setCursor(0, 1);
      lcd.print("        "); // Clears the right half of the screen
    }
    
  else {
    digitalWrite(transPin, LOW); // This makes sure the fan is off when the button is not pressed
  }
}

Thanks for your reply.

In the meantime, I added the ignition circuit using a similar method as the fan.

However, the ignition circuit does not seem to work with the Arduino. I'm using a flyback driver like this:

I'm trying to feed the circuit 9V with a BD139 NPN Power transistor switched by the Arduino, but I think the circuit draws too much current or something, because it does make some faint noise, but no sparks... (circuit does work when hooked up to a 9V battery, not when switched using Arduino and transistor)

Do you think I could use a relay or something with the transistor circuit to switch the thing with the Arduino?

Thanks!

Updated code:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int loopCount=0;
int dispPart=2;
int fanButtonState=0;
int ignButtonState=0;
const int fanPin=6;
const int fanButton=7;
const int ignPin=8;
const int ignButton=9;

void setup(){
  lcd.begin(16, 2);
  pinMode(fanPin, OUTPUT); // The pin that switches the transistor off or on
  pinMode(fanButton, INPUT); // The pin that detects the button press
  lcd.setCursor(0, 0); // Puts cursor on leftmost position
  lcd.print("Standby  "); // Shows the word STANDBY after starting up
  lcd.setCursor(0, 1);
  lcd.print("        ");
}

void loop(){
  digitalWrite(ignPin, LOW);
  digitalWrite(fanPin, LOW);
  fanButtonState = digitalRead(fanButton);
  ignButtonState = digitalRead(ignButton);
  if (fanButtonState == HIGH) { // If the fan button is pressed
    for (int countE=0; countE < 3; countE++) { // This loops the ventilation sequence for three times (increase number for longer ventlation)
      digitalWrite(fanPin, HIGH);  // Turn on the fan
      dispPart=2;
      lcd.setCursor(0, 0);
      lcd.print("Ventiler"); // Puts the first 8 characters of the word "ventileren" on the screen
      lcd.setCursor(0, 1); // This is because it's a 16x1 fan; this puts text on the right half of the LCD
      lcd.print("en      ");
      delay(400);
         for (int loopCount = 0; loopCount < 3; loopCount++) { // A small loop to display a sequence of 3 flashing dots
          lcd.setCursor(dispPart, 1);
          lcd.print(".");
          delay(900);
          dispPart++;
           }
        } 
      lcd.setCursor(0, 0);
      lcd.print("Standby  "); // Puts the word STANDBY on the screen after the ventlation sequence has finished
      lcd.setCursor(0, 1);
      lcd.print("        "); // Clears the right half of the screen
    }
   if (ignButtonState == HIGH) { // Check if ignition button has been pressed
        lcd.setCursor(0, 0);
        lcd.print("Ontsteke"); // Puts the first 8 characters of the word "ontsteken" on the screen
        lcd.setCursor(0, 1); // This is because it's a 16x1 fan; this puts text on the right half of the LCD
        lcd.print("n       ");
        delay(900);
        digitalWrite(ignPin, HIGH); // Activates the ignition circuit
        delay(3000);
        digitalWrite(ignPin, LOW); // Deactivates the ignition circuit
        delay(200);
        lcd.setCursor(0, 0);
        lcd.print("Standby  "); // Puts the word STANDBY on the screen after the ignition sequence has finished
        lcd.setCursor(0, 1);
        lcd.print("        "); // Clears the right half of the screen
   }
}

Thanks again for your speedy reply, Richard!

Why not just feed the ignition circuit directly from the Arduino. The 470 ohm base resistor could connect to an Arduino digital output pin instead of pin 3 of the 555 timer chip. Just figure out the optimum frequency and number of pulses to make a good reliable ignition spark.

Might be possible, but someone built the circuit for me on a custom PCB, so it's quite hard to change anything.

9V may very well be way too low depending on the nature of your flyback transformer (which we know nothing about). Does that circuit work with the rated power supply voltage? What leads you to think you can make it work with a lower supply voltage?

I got the circuit working with a 9 V battery, with a variable power supply on as little as 5V.
Only it stops working whenever I try to supply 9V via a transistor using a circuit like this one:

Too many unknowns to offer any speculation about why, but that circuit arrangement (with that whole circuit as the "load") isn't common, and you are finding out why.

;D

I guess it'll keep me busy for another couple of hours (days, weeks,...?)

Only it stops working whenever I try to supply 9V via a transistor using a circuit like this one:

You have to disconnect the ground from your 15-30V power supply from the ground on the flyback driver and connect it to the 0V (ground on the arduino. Then the collector of the transistor connects to all the places with the ground symbol except the capacitors each side of the regulator, those should go to the arduino ground as well.

I got it working with a 12V relay.

Although the circuit works now, the Arduino jams when the ignition starts; I think it's because of the high frequency HV signal because the Arduino also misbehaves when I run the HV ignitor on its own near the Arduino.

Isolation time!