回到首页 返回首页
回到顶部 回到顶部
返回上一页 返回上一页

懒汉浇水 简单

头像 gada888 2020.05.25 672 0

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

project-image

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

材料清单

  • arduino pro mini X2
  • 12g 伺服电机 X1
  • 光线传感 X1
  • 输液瓶 X1

步骤1 找物料

project-image
project-image
project-image
project-image
project-image
project-image

步骤2 选择传感

project-image
project-image
project-image
project-image
project-image

步骤3 连线图-发射端

project-image

步骤4 连线图 接受端

project-image
代码
//发送信号

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");
}
}

评论

user-avatar