how is this for a start?

I have put together a schematic and code for an IR controlled 12VDC fan and would like to see if I am headed in the right direction. I am only looking to turn the fan off and on not to control the speed. I am sure that the symbols may not be 100% correct but I can’t get to fritzing at work so I had to cut and paste with MSpaint and the code is below.

IR receiver code

#include <IRremote.h>

int RECV_PIN = 9;
int transistorPin = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(transistorPin, OUTPUT);
}

void loop() {

if (irrecv.decode(&results)) {
Serial.println(results.value, DEC);

if(results.value == -2094865891)
digitalWrite(transistorPin, HIGH); // set the Fan on
else
digitalWrite(transistorPin, LOW); // set the Fan off

irrecv.resume(); // Receive the next value
}
}

Thanks for any input you guys might have

do you want it to be momentary or on/off? your fan now only works if you hold down the button.(not very useful :D)

i have done so IR stuffo n my blog dduino.blogspot.com

Where's the schematic? All I see is a picture of some unidentified parts. Not a big fritzing fan.

Your right crossroads I mis-spoke by saying schematic. The parts are (from top to bottom, L to R) IR Receiver, MOSFET, power supply for motor, and motor/fan. There is also a resistor for the IR Receiver and a Diode for the MOSFET.

@SirBow2
I want the fan to be on until turned off by another press of the remote.

so you want non momentary?

try:

if(results.value == -2094865891)
{
      digitalWrite(transistorPin,!digitalRead(transistorPin));   // set the Fan opposite of current state when button pressed.
}

you may want to add some delays/debounce etc so that it doesnt change really fast.

Ignoring the unidentified parts for now…

This line
if(results.value == -2094865891)

probably want to change this to >= or <=, be hard to hit that number right on the head.

its a IR code, so it needs to be exactly equal to that code for the button. it works fine for me.

ok I updated the code a little bit. This is a result of testing just the IR receiver

#include <IRremote.h>
 
int RECV_PIN = 9;
int transistorPin = 11;
 
IRrecv irrecv(RECV_PIN);
 
decode_results results;
 
void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(transistorPin, OUTPUT);  
}
 
void loop() {
 
  if (irrecv.decode(&results)) {
    Serial.println(results.value, DEC);
 
    if(results.value <= -2094865891)
{
    
     
      digitalWrite(transistorPin,!digitalRead(transistorPin));   // set the Fan opposite of current state when button pressed.
        delay(200);
      }
    irrecv.resume(); // Receive the next value
  }
}

Just tested the whole thing and it works like a charm thanks for your help.