Hey Guys!
I've got a home project going on atm and I was trying to monitor the room temperature.
Now when the tmp > 25C a computer fan is meant to turn on. The coding is correct but I notice that when my fan is plugged into my arduino the analog reading sky rockets.
I believe it would have to do with the current, but I not sure.
TL;DR
Whats the solution to have multiple sensors running at the same time without interference?
#include <TimeAlarms.h>
#include <Time.h>
#include <TimeLib.h>
#include <stdio.h>
#include <stdlib.h>
#define C_TEMP A0
#define TEMP 15
#define FAN 3
#define LED 5
bool lightSwitch = true;
time_t t = now();
void setup() {
Serial.begin(9600);
setTime(11,00,00,5,22,2016);
Alarm.alarmRepeat(3,0,0, f_lightSwitch); // 8:30am every day
Alarm.alarmRepeat(21,0,0, f_lightSwitch); // 8:30am every day
pinMode(FAN, OUTPUT);
pinMode(LED, OUTPUT);
}
void loop() {
tempControl();
digitalClockDisplay();
lightControl();
Alarm.delay(1000);
}
void lightControl()
{
if(lightSwitch == false){
digitalWrite(LED, LOW);
}
else{
digitalWrite(LED, HIGH);
}
}
void f_lightSwitch()
{
if(lightSwitch == false){
lightSwitch = true;
}
else{
lightSwitch = false;
}
}
void tempControl()
{
float tempC = analogRead(C_TEMP)* 5000L / 1024L / 10;
if(tempC > TEMP){
digitalWrite(FAN, HIGH);
}
else{
digitalWrite(FAN, LOW);
}
Serial.print("TEMP = ");
Serial.println(tempC);
Serial.print("VOLT = ");
Serial.println(analogRead(C_TEMP));
}
void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}
void printDigits(int digits)
{
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
Hi,
Welcome to the forum.
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html
then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
How are you switching the fan ON and OFF and where is it getting its power from.
What Arduino controller are you using, none of the controllers can supply enough current to power a fan directly, so it must have its own power supply.
Tom.... 
Hi Tom,
Thanks for the reply
Attached is a photo of my circuit with labels
The fan is being controlled by a TIP120 (which to my understanding is a switch).
The fan is being powered by the Vin port on the Arduino and the power source is a 12v ac/dc adapter.
Currently I'm using an Arduino UNO.
I should probably note I'm using a 5v computer fan =)
Louis
A circuit diagram were more helpful.
As I decipher the picture, you are powering the fan from the Arduino Vcc. This is not a good idea, motors and other actors should have an independent power source. The 3.3V and 5V outputs can be used only to power sensors or other low power circuits.
Also missing is a base resistor (1k?) for the TIP120. Only the gates of FETs can be connected directly to output pins, but bipolar transistors require a current limiting resistor between the output pin and the transistor base pin.
Also missing is a snubber for the fan, e.g. a diode. Please learn more about powering and switching motors and other inductive loads. The Learning section contains a number of interesting tutorials.
Hi,
Please check the pinouts of your transistor.
It looks like you have the UNO output connected to the centre pin of the transistor, TO-220 case will have the left pin as Base and the centre as Collector, and the right as Emitter.
And as Dr has pointed out, you need a base resistor.
Tom.... 