所有分类
主题 主题
平台 平台
我的工作台
userHead
注册时间 [[userInfo.create_time]]
创造力 [[userInfo.creativity]]
[[userInfo.remark]]
[[d.project_title]]
articleThumb
[[d.material_name]]
timelineThumb
进入工作台
折叠
所有分类 我的工作台
展开

懒汉浇水

gada888 gada888 2020-05-25 23:35:08

家里在小区有一套旧房,但是在4F,非电梯房,阳台有一些花要浇,平时有时间了回去看下,但问题是有时候会忽视浇水。

projectImage

这次的想法是在楼下用激光头来指挥楼上的arduino和伺服电机来开启输液器的截止阀浇水5秒然后关闭。

材料清单 材料清单
2x
arduino pro mini
1x
12g 伺服电机
1x
光线传感
1x
输液瓶
步骤1 步骤1
找物料
projectImage
projectImage
projectImage
projectImage
projectImage
projectImage
步骤2 步骤2
选择传感
projectImage
projectImage
projectImage
projectImage
projectImage
步骤3 步骤3
连线图-发射端
projectImage
步骤4 步骤4
连线图 接受端
projectImage
代码 代码
	                    					//发送信号

char stringToMorseCode[] = "a";

// Create variable to define the output pins
int laser = 13;      // init a laser

//Set the speed of your morse code

int dotLen = 200;     // length of the morse code 'dot'
int dashLen = 200;    // length of the morse code 'dash'
int PauseLen = 200;  // length of the pause between cha
int SpaceLen = 200;     // length of the spaces between cha

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output for laser light.
  pinMode(laser, OUTPUT); 
}

void loop()
{ 
  // Loop through the string and get each character one at a time
  for (int i = 0; i < sizeof(stringToMorseCode) - 1; i++)
  {
    // Get the character in the current position
  char tmpChar = stringToMorseCode[i];
  // Set the case to lower case
  tmpChar = toLowerCase(tmpChar);
  // Call the subroutine to get the morse code
  GetChar(tmpChar);
  }
  // At the end of the string long pause before looping
  LightsOff(2000);      
}


// DOT
void MorseDot()
{
  digitalWrite(laser, HIGH);    // turn the laser on 
  delay(dotLen);              // hold in this position
}
// DASH
void MorseDash()
{
  digitalWrite(laser, HIGH);    // turn the laser on 
  delay(dashLen);               // hold in this position
}
// Turn Off
void LightsOff(int delayTime)
{
  digitalWrite(laser, LOW);     // turn the laser off   
  delay(delayTime);             // hold in this position
}

// *** Characters to Morse Code //
void GetChar(char tmpChar)
{
    MorseDash();
    LightsOff(PauseLen);
    MorseDot();
    LightsOff(PauseLen);
    MorseDash();
    LightsOff(PauseLen);
    LightsOff(SpaceLen);      
  }

	                    				
代码 代码
	                    					//接收代码
#include <Servo.h>
Servo myServo;
int photo1 = A2; // LDR pin
int servoPin = 8; // servo pin
int val1 = 0; 
void setup()
{
Serial.begin(9600);
myServo.attach(servoPin);
myServo.write(90);
pinMode(photo1, INPUT);
Serial.println("LDR v1.0");
}
void loop()
{
delay(500);
val1 = analogRead(photo1);
Serial.print("LDR Value: ");
Serial.println(val1);
if (val1 >= 800)
{
myServo.write(90);
Serial.println("To Dark");
}
else if(val1 < 800)
{
myServo.write(0);
Serial.println("LDR sleep");
}
}
	                    				
Makelog作者原创文章,未经授权禁止转载。
0
0
评论
[[c.user_name]] [[c.create_time]]
[[c.parent_comment.count]]
|
[[c.comment_content]]