int sensorPin = 0;
int ledVermelho = 8;
int ledVerde = 9;
#define POWERSUPPLY 12
#define FAN 3
void setup()
{
Serial.begin(9600);
pinMode(ledVermelho, OUTPUT);
pinMode(ledVerde, OUTPUT);
pinMode(POWERSUPPLY, OUTPUT); //Initiates Motor Channel A pin
pinMode(FAN, OUTPUT); //Initiates Brake Channel A pin
}
void loop()
{
int reading = 5.0 * analogRead(sensorPin);
float voltage = reading * 5.0;
voltage /= 1024.0;
Serial.print(voltage); Serial.println(" volts");
float temperatureC = (voltage - 0.5) * 100 ;
Serial.print(temperatureC); Serial.println(" degrees C");
if (temperatureC > 35){
digitalWrite(ledVermelho, HIGH);
digitalWrite(ledVerde, LOW);
digitalWrite(POWERSUPPLY, HIGH); //Establishes forward direction of Channel A
digitalWrite(FAN, HIGH); //Eengage the Brake for Channel A
}
else {
digitalWrite(ledVerde, HIGH);
digitalWrite(ledVermelho, LOW);
digitalWrite(POWERSUPPLY, LOW); //Establishes forward direction of Channel A
digitalWrite(FAN, LOW); //Disengage the Brake for Channel A
}
delay(1000);
}
What is does is when is, when the temperature rises more than 35ºC it turns on a 12v fan that is feeded by a power supply of a computer, both are connected to the motor shield channel port A
i don't understand what is happening, why is this giving me these negative values i really want to know why is this happening
int reading = 5.0 * analogRead(sensorPin);
float voltage = reading * 5.0;
voltage /= 1024.0;
Is about the same quality you have in listening to what we say.
That is not very good.
Read the how to use the forum sticky.
Modify the first post to include code tags.
Then have a think about why you think doing the above will get you a voltage.
Why are you multiplying by 25?
> int reading = 5.0 * analogRead //arduino voltage * getting the voltage reading from the temperature sensor
> float voltage = reading * 5.0 //converting that reading to voltage
He was asking a rhetorical question designed to make you think.
You can put all the comments you like against the code, it will not make it do what you hope.
Grumpy_Mike:
He was asking a rhetorical question designed to make you think.
You can put all the comments you like against the code, it will not make it do what you hope.
why is that?, i just put the comments now to answer his question nothing more, so he can understand what it does, by the way i don't know where he went to get the that number "25"
He gets 25 because you have multiplied that reading by 5 twice and multiplication is a cumulative operation. So multiplying by 5 twice is the same as multiplying by 25 once because five times five is twenty five.
He gets 25 because you have multiplied that reading by 5 twice and multiplication is a cumulative operation. So multiplying by 5 twice is the same as multiplying by 25 once because five times five is twenty five.
oh thanks now i get it, i tested "int reading = analogRead(sensorPin); " and it's the same but i foun why is giving negative temperatura is when i put the motor shield in the arduino and use the code if i just use the arduino it runs perfectly fine (if i don't use the fan and power suppply), i want to use the motor shield to control the fan and the power supply.
I have a doubt as well, if i put the power supply and fan in the digital ports of the arduino ( i am using channel A of the motorshield) will it work with no problem? or i will just crash the arduino?
you can close this post i already solved the problem, it was a supply problem with the LED's i tested each item do discover it and i just didn't turned on the LED's.
The Led's were not having enough voltage to work properly so fixed it by grabing one leg of the Red Led take out one resistence and plug it to the resistence of the other green Led.