Hey all I got a program I found here somewhere working for controlling a fan from a computer. The wiring is pretty simple. Red supply, black ground, yellow rpm tachometer(not used in this application), and a blue control wire. The blue wire accepts a pwm control pulse train, the code is here.
void setup()
{
Serial.begin(9600);
pinMode(6, OUTPUT);
}
unsigned char speed;
unsigned int low = 1;
unsigned int high = 10;
unsigned int baseTime = 10;
void loop(){
digitalWrite(6,LOW);
delayMicroseconds(low*10);
digitalWrite(6,HIGH);
delayMicroseconds(high*10);
if (Serial.available()){
speed = Serial.read() - 48;
low = speed;
high = baseTime - speed;
Serial.println(high);
}
}
Basically what this does is ramps the fan speed up and down depending on the input(ranging from >0 and <10) from the serial port. Now that part is working dandy. My other program is a little different. I've hit a little bump and I'm not sure if it's because I'm a dullard or if it's something more.
const int propPin = 0;
const int methPin = 1;
const int carbPin = 2;
const int propFan = 6;
unsigned char speed;
unsigned int low = 1;
unsigned int high = 10;
unsigned int baseTime = 10;
int propIn, methIn, carbIn;
void setup() {
Serial.begin(9600);
pinMode(6, OUTPUT);
}
void loop() {
char str[7];
propIn = analogRead(propPin);
methIn = analogRead(methPin);
carbIn = analogRead(carbPin);
sprintf(str, "%04d", propIn);
Serial.print(str);
sprintf(str, "%04d", methIn);
Serial.print(str);
sprintf(str, "%04d", carbIn);
Serial.print(str);
int inByte = Serial.read();
switch(inByte){
case 'a':
break;
case 'b':
break;
case 'c':
break;
case 'd':
break;
case 'e':
break;
case 'f':
break;
case 'm':
tone(13, 500, 1000);
break;
default:
if (propIn || methIn || carbIn > 500){
tone(13, 500, 1000);
}
int propFan = map(propIn, 0, 1023, 1, 9);
for (int i=0; i < 20000; i++){
digitalWrite(6,LOW);
delayMicroseconds(low*10);
digitalWrite(6,HIGH);
delayMicroseconds(high*10);
speed = propIn - 48;
low = speed;
high = baseTime - speed;
}
}
}
This is basically a program to control 3 fans based on how much of a particular gas is in the air. The empty cases are for user inputs from VB6 which is finished 8-). I'll be able to assign fan speed functions inside each one as soon as I find out how to get them to work in this program. I've been trying to find the bug for hours, does anyone here have a knack for sniffing these types of things out? It's driving me nuts! >:(
Please help! :-/