Go Down

Topic: 大家好 我有一点关于温度和光感应系统的问题 (Read 2596 times) previous topic - next topic

jollyroger1224

这时我的project 的图。

我的project是关于光和温度感应系统,环境光越暗 LED就越亮 然后如果温度超过16度越多,那个DC MOTOR转的就越快
int motorPin = 9;
int temperaturePin =A0;
int potentiometerPin = A1;
int ledpin = 7;
int photoResistor = A2;

void setup()
{
 Serial.begin(9600);
 pinMode(motorPin,OUTPUT);
 pinMode(ledpin,OUTPUT);
}

void loop()
{
 //T
 float tempvalue = analogRead(temperaturePin);
 float tempvolt = analogRead(temperaturePin)*(5.0/1024);
 float temperature = (tempvolt - 0.5)*100;
 
 //potentiometer sensor
 float potenvalue = analogRead(potentiometerPin);
 float potenvolt = analogRead(potentiometerPin)*(5.0/1024);
 float potentiometer_degree = ((potenvalue+1024)*16)+16 ;
 

 Serial.print ("Potentiometer value = ");
 Serial.print (potenvalue);
 Serial.print ("  ");
 Serial.print ("Potentiometer volt = ");
 Serial.print (potenvolt);
 Serial.print ("  ");
 Serial.print ("Potentiometer degree = ");
 Serial.print (potentiometer_degree);
 Serial.println("  ");
 
 //temperature output
 Serial.print("Temperature value = ");
 Serial.print(tempvalue);
 Serial.print("  ");
 Serial.print("tempvolt = ");
 Serial.print(tempvolt);
 Serial.print("  ");
 Serial.print("temperature = ");
 Serial.println(temperature);
 Serial.println("  ");
 delay(1000);
 
 //motor
 int pulseTime = 2100;
 if (temperature > potentiometer_degree)
 {
   digitalWrite (motorPin,HIGH);
   delayMicroseconds(pulseTime);
   digitalWrite(motorPin,LOW);
   delay(25);
 }
 else
 {
   digitalWrite (motorPin,LOW);
 }
 
 //LED
 int lightvalue=analogRead(photoResistor);
 int threshold = 700 ;
 Serial.print("Lightvalue = ");
 Serial.print(lightvalue);
  if (lightvalue > threshold)
 {
   digitalWrite(ledpin,HIGH);
 }
 else
 {
   digitalWrite(ledpin,LOW);
 }


}


这个是我的programm,问题是 只有那个LED对光部分的反应,然后不管我怎么调整Potentiometer, DC motor 都没有转。 我找不到问题出现在哪里,可以帮我看一下吗?

yyl12138

You cannot drive the motor directly with Arduino. The current of the output is not big enough.You need a motor drive.

Go Up