I am making a fan controller that can be controlled by a reostat, or anything that can define an analog signal. My problem is that when I try to add a read of any kind on pins the fan stops working. I have it hooked up to a TIP120, and when it is just outputting signal it works like a charm on my old repurposed computer fan. The problem occurs when I try to use a potentiometer in an analog read. This completes some oddity which causes the entire thing to screw all and stop it like a heart attack. Below I will list the coding that I was trying to scavange from/combine with to make the fan interval speed run. I am using an idea that I have tried and proven of using a similar process to light up an LED and make it blink with different frequencies/brightnesses.
This code below here is the code that I found worked, and I pulled it offline. This is what allowed me to run a fan in the first place. Short and simple. Could have made it myself, but I decided it was quicker to ctrl+C/ctrl+P
// Define which pin to be used to communicate with Base pin of TIP120 transistor
int TIP120pin = 3; //for this project, I pick Arduino's PMW pin 11
void setup()
{
pinMode(TIP120pin, OUTPUT); // Set pin for output to control TIP120 Base pin
analogWrite(TIP120pin, 255); // By changing values from 0 to 255 you can control motor speed
}
void loop()
{
}
This is the LED code that I am trying to salvage from. I normally comment more in programs at least I try to, but these programs are short enough that they should be easily interpreted.
int led = 9;
void setup() {
Serial.begin(9600);
}
void loop() {
int pot = analogRead(A0);
int lumins = 257 - pot / 4;
int reverse = 1025 - pot;
Serial.println(pot);
delay(20);
analogWrite(led, LOW);
delay(reverse);
analogWrite(led, lumins);
delay(reverse);
}
in here you will see some of the solutions that I have tried to improve the probability of it working. I thought at first if my sample rate was too slow and interferring with the writing, but I found that not to be the case. This on its own did stop the analog write, but it was not the only thing that caused a complete halt in the process. If I assigned a pin as an input this too would kill the fan.
int logic = 3;
void setup(){
//Serial.begin(115200);
}
void loop(){
pinMode(logic, OUTPUT);
analogWrite(logic, A0 / 4);
pinMode(A0, INPUT);
analogRead(A0);