|
这个有两个infrared sensor,一个LM35DT,一个servo,一个LCD,一个GROVE temperature sensor
作用:
利用2个infrared sensor来控制servo的不同转向
lm35DT是用来检测水温度
GROVE是用来检测环境温度
LCD显示35和GROVE的温度度数
问题:
lm35DT在LCD显示的温度一直在10多和30多之间跳,正常温度显示是20度左右
已用失败方案:
1.components用额外电源供电
lm35差点烧了。。很烫
servo转的比平时还快,然后就失灵了
2.用中断
尝试用中断来减少arduino的工作量,但是还是没什么用
求大神给个解决方案,感激不尽,再不行只有用2个arduino分开搞了。。。
以下是我的代码
通熟易懂的
#include <Wire.h>
#define PIR_MOTION_SENSOR2 2 //Use pin 2 to receive the signal from the module
#define PIR_MOTION_SENSOR3 3
#include <Servo.h>
Servo myservo;
#include <math.h>
const int A = 4275; // B value of the termistor
const int R0 = 100000; // R0 = 100K
const int pinTempSensor1 = A0; // Grove - Temperature Sensor connect to A0
#include "rgb_lcd.h"
rgb_lcd lcd;
const int colorR = 100; //define LCD screen color
const int colorG = 100;
const int colorB = 100;
int pos = 0; //define servo intialization of angle
int tempPin = 1;
void setup()
{
lcd.begin(16, 2); // define screen row and column
lcd.setRGB(colorR, colorG, colorB); //define LCD color
delay(100);
Serial.begin(9600);
pinsInit();
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
{
if(isPeopleDetected2()) //if it detects the moving people?
{
turnonlcd(); //lcd and servo turn on
}
}
{
if(isPeopleDetected3())
{
turnofflcd();
}
}
waterTemp();
}
void pinsInit() //define PIR sensor input
{
pinMode(PIR_MOTION_SENSOR2, INPUT);
pinMode(PIR_MOTION_SENSOR3, INPUT);
}
void turnonlcd() //**lcd and servo turn on function
{
pos = 0;
myservo.write(pos);
int a = analogRead(pinTempSensor1);
float Rs1 = 1023.0/a-1.0;
Rs1 = R0*Rs1;
float temp1 = 1.0/(log(Rs1/R0)/A+1/298.15)-273.15; // convert to temperature via datasheet
lcd.setCursor(11,0);
lcd.print("P:OUT"); // show first row imformation
lcd.setCursor(0,1);
lcd.print("ET=");
lcd.print(temp1); // show second row temp
delay(10);
}
void turnofflcd() // **lcd and servo turn off function
{
pos = 179;
myservo.write(pos);
int a = analogRead(pinTempSensor1);
float Rs1 = 1023.0/a-1.0;
Rs1 = R0*Rs1;
float temp1 = 1.0/(log(Rs1/R0)/A+1/298.15)-273.15; // convert to temperature via datasheet
lcd.setCursor(11,0);
lcd.print("P:IN "); // show first row imformation
lcd.setCursor(0,1);
lcd.print("ET=");
lcd.print(temp1); // show second row temp
delay(10);
}
void waterTemp()
{
int temp;
int tempC = analogRead(tempPin);
temp = tempC * 0.48828125;
lcd.setCursor(0, 0);
lcd.print("WT=");
lcd.print(temp);
delay(100);
}
boolean isPeopleDetected2() // **Return-boolean funtion:Detect whether people moves in it's detecting range
{
int sensor2Value = digitalRead(PIR_MOTION_SENSOR2);
int sensor3Value = digitalRead(PIR_MOTION_SENSOR3);
if(sensor2Value == HIGH&&sensor3Value == LOW) //if the sensor value is HIGH?
{
return 1;
}
else
{
return 0;
}
}
boolean isPeopleDetected3()
{
int sensor2Value = digitalRead(PIR_MOTION_SENSOR2);
int sensor3Value = digitalRead(PIR_MOTION_SENSOR3);
if(sensor3Value == HIGH&&sensor2Value == LOW)
{
return 1;
}
else
{
return 0;
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|