Go Down

Topic: DC MOTOR + LM35 (Read 163 times) previous topic - next topic

LoadzFire

Hi,

I've got a project : I want to move a motor one time per day with the LM35 temperature sensor.
My problem is : the motor turn randomly.
Here is my code

Code: [Select]
int val;
int tempPin = A0;
boolean volet;

void setup()
{
 
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(8, OUTPUT); //Initiates Brake Channel A pin
Serial.begin(9600);
//digitalWrite(12, LOW); //Establishes backward direction of Channel A
//digitalWrite(9, LOW);   //Disengage the Brake for Channel A
//analogWrite(3, 0);   //Spins the motor on Channel A at half speed

}
void loop()
{
//START TEMPERATURE
val = analogRead(tempPin);
float mv = ( val/1024.0)*5000;
float cel = mv/10;

Serial.print("TEMPRATURE = ");
Serial.print(cel);
Serial.print("C");
Serial.print(" ");


delay(5000);
//END TEMPERATURE

//START MOTOR
if ((cel < 22) && (volet = false)) //- 21 degres (temperature)
{
  digitalWrite(12, HIGH); //Establishes backward direction of Channel A
  digitalWrite(8, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 100);   //Spins the motor on Channel A at half speed
  delay(5000);
  analogWrite(3, 0);   //ARRETER LE MOTEUR
  volet = true;
  delay(1000);
  Serial.println("voletferme");
 
}
if ((cel > 25) && (volet = true)) // + 25 degres (temperature)
{
  digitalWrite(12, LOW); //Establishes backward direction of Channel A
  digitalWrite(8, HIGH);   //Disengage the Brake for Channel A
  analogWrite(3, 100);   //Spins the motor on Channel A at half speed
  delay(5000);
  analogWrite(3, 0);   //ARRETER MOTEUR
  volet = false;
  delay(1000);
  Serial.println("voletouvert");
 
}
//END MOTOR
}


So someone can help me on this project ?

Here is my schema

Smajdalf

I don't know what board is on your picture so I don't know if the motor is wired correctly (you cannot connect motors to regular Arduino directly). But you have at least 2 mistakes in your code.

1)
if (myVal = 17) is WRONG
if (myVal == 17) is correct

2)
What part of your code is supposed to provide "one time per day" part? I don't see it.

Also you should include the picture into your post, there is a guide for it somewhere.
On 8-bit (i.e. Uno) use "byte" instead of "int" if possible - it is faster and saves resources!

756E6C

Sounds like you are getting "jitter" from the LM35, first try a load resistor (1k to 3.3k) from A0 to GND, if that doesn't help, try a 0.1uF (100nF) ceramic capacitor in parallel with the resistor, if that doesn't help, remove the resistor, if all of the above don't help, you may need a "smoothing" algorithm.

LoadzFire

I don't know what board is on your picture so I don't know if the motor is wired correctly (you cannot connect motors to regular Arduino directly). But you have at least 2 mistakes in your code.

1)
if (myVal = 17) is WRONG
if (myVal == 17) is correct


ok thank
Quote
2)
What part of your code is supposed to provide "one time per day" part? I don't see it.

Also you should include the picture into your post, there is a guide for it somewhere.

I want to know how i can do my code on time per day only (this part is not in my code, i want to add it but i dont know how).
Sounds like you are getting "jitter" from the LM35, first try a load resistor (1k to 3.3k) from A0 to GND, if that doesn't help, try a 0.1uF (100nF) ceramic capacitor in parallel with the resistor, if that doesn't help, remove the resistor, if all of the above don't help, you may need a "smoothing" algorithm.
Ok i will try with a resistor ^^

756E6C


Smajdalf

It depends on expected accurancy, time of running etc. You have many options.

1) Use a RTC.
2) Use internal timing to know it is a new day. It will drift a bit but I doubt it will matter if the motor runs 400 times in 399 days.
3) Use a sensor to know it is a new day (possibly some detection of light).

Also what exacly means one time per day? Exactly once between 2 midnights (if it is not triggered sooner it MUST run at 23:59:59)? Up to once? No sooner than 24 hours from last run? Not longer than 24 hours from last run?
On 8-bit (i.e. Uno) use "byte" instead of "int" if possible - it is faster and saves resources!

LoadzFire

It depends on expected accurancy, time of running etc. You have many options.

1) Use a RTC.
2) Use internal timing to know it is a new day. It will drift a bit but I doubt it will matter if the motor runs 400 times in 399 days.
3) Use a sensor to know it is a new day (possibly some detection of light).

Also what exacly means one time per day? Exactly once between 2 midnights (if it is not triggered sooner it MUST run at 23:59:59)? Up to once? No sooner than 24 hours from last run? Not longer than 24 hours from last run?
I want (I'm not sure it's possible) my code (for the motor) run one time per day max, but it will also be possible that the motor does not run for a day.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy