That sensor has an analogue output so you have to run it into one of the analogue pins, not pin 0.
Then read the value with analogRead(), decide if the value is different to the last reading and if so start the fan and also start a timer. After 5 seconds stop the fan.
int sensorPin = A0; //sensonr
int fanPin = 13; // fan
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(fanPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(fanPin, HIGH);
// stop the program for milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(fanPin, LOW);
// stop the program for for milliseconds:
delay(sensorValue);
}
int sensorPin = A0; // select the input pin for the ir sensor
int fanPin = 13; // select the pin for the fan
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(fanPin, OUTPUT);
}
that was the code I used to get it to read the IR pin
int IRpin = 0; // analog pin for reading the IR sensor
void setup() {
Serial.begin(9600); // start the serial port
}
void loop() {
float volts = analogRead(IRpin)0.0048828125; // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
float distance = 65pow(volts, -1.10); // worked out from graph 65 = theretical distance / (1/Volts)S - luckylarry.co.uk
Serial.println(distance); // print the distance
delay(100); // arbitary wait time.
}
int IRpin = 0;
// select the input pin for the potentiometer
int fanPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
// analog pin for reading the IR sensor
void setup() {
Serial.begin(9600);
// start the serial port
}
void loop() {
float volts = analogRead(IRpin)0.0048828125; // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
float distance = 65pow(volts, -1.10); // worked out from graph 65 = theretical distance / (1/Volts)S - luckylarry.co.uk
Serial.println(distance); // print the distance
delay(100);
sensorValue = analogRead(IRpin);
Sorry but I can't keep up, that's about 4 totally different pieces of code, we still don't know what values the sensor is returning, and now we have complicated floating point maths just (I gather) to turn on a LED/fan when something gets close.
sending a voltage to the sensor
You are (I assume, still haven't seen a schematic) supplying the sensor with 5v but you aren't "sending" it anything, you are reading the sensor's output.
And then how do I get it to trigger the lights?
What lights, a minute ago it was a fan. Or do you mean the LED on pin 13?
State the project goals clearly, is it movement or proximity you need to measure? Does the fan/whatever start when X happens and stop 5 seconds later even if X is still happening, or should it start when X happens then stop 5 seconds after X stops. etc etc.