DS3231 clock module + Set time feed water

DS3231 library   :     https://drive.google.com/file/d/1161Y-FyaHFAjGNcsAwsUpPnpZHLVhH8c/view?usp=sharing

Code

// DS3231_Serial_Easy
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// A quick demo of how to use my DS3231-library to 
// quickly send time and date information over a serial link
//
// To use the hardware I2C (TWI) interface of the chipKit you must connect
// the pins as follows:
//
// chipKit Uno32/uC32:
// ----------------------
// DS3231:  SDA pin   -> Analog 4
//          SCL pin   -> Analog 5
// *** Please note that JP6 and JP8 must be in the I2C position (closest to the analog pins)
//
// chipKit Max32:
// ----------------------
// DS3231:  SDA pin   -> Digital 20 (the pin labeled SDA)
//          SCL pin   -> Digital 21 (the pin labeled SCL)
//
// The chipKit boards does not have pull-up resistors on the hardware I2C interface
// so external pull-up resistors on the data and clock signals are required.
//
// You can connect the DS3231 to any available pin but if you use any
// other than what is described above the library will fall back to
// a software-based, TWI-like protocol which will require exclusive access 
// to the pins used.
//

// ////// www.a-arduino.com  
#include <Keypad.h>

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display


#include <DS3231.h>


LiquidCrystal_I2C lcd(0x27, 16, 2);
// Init the DS3231 using the hardware interface
DS3231  rtc(SDA, SCL);


Time t;

int ValvePin = 10;
int relay2 = 11;
int relay3 = 12;
int relay4  = 13;
int motion = A0;
int light  = A1;

////////////////

//  set on/off time 1
const int OnHour1 = 6 ; //SET TIME TO ON ValvePin (24 HOUR FORMAT)
const int OnMin1 = 0;
const int OffHour1 = 6; //SET TIME TO OFF ValvePin
const int OffMin1 = 1;

//  set on/off time 2
const int OnHour2 = 17; //SET TIME TO ON ValvePin (24 HOUR FORMAT)
const int OnMin2 = 0;
const int OffHour2 = 17; //SET TIME TO OFF ValvePin
const int OffMin2 = 1;

//////////////keypad

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 







void setup()
{
  // Setup Serial connection
  Serial.begin(115200); 
  
  // Initialize the rtc object
  rtc.begin();
  pinMode(relay2,OUTPUT);
  pinMode(relay3,OUTPUT);
  pinMode(relay4,OUTPUT);
  pinMode(ValvePin, OUTPUT);
  pinMode(motion,INPUT);
  pinMode(light,INPUT);
  
  digitalWrite(ValvePin,HIGH);
   digitalWrite(relay2,HIGH);
  digitalWrite(relay3,HIGH);
  digitalWrite(relay4,HIGH);
  
  // The following lines can be uncommented to set the date and time
 //rtc.setDOW(FRIDAY);     // Set Day-of-Week to SUNDAY
 //rtc.setTime(10, 3, 0);     // Set the time to 12:00:00 (24hr format)
 //rtc.setDate(25, 10, 2019);   // Set the date to January 1st, 2014
lcd.begin(16,2);
//lcd.backlight();
for(int i=0;i<=16; i++)
{
  lcd.clear();
  lcd.setCursor(i,0);
  lcd.print("A-Future Farm");
delay(500);
}

for(int i=16;i>0; i--)
{
  lcd.clear();
  lcd.setCursor(i,0);
  lcd.print("A-Future Farm");
delay(500);
}
  lcd.setCursor(2,1);
  lcd.print("A-Arduino");
  delay(5000); 
  lcd.clear();



}

void loop()
{

autoLight ();  
keyPad ();
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");
  
  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());
  
  // Wait one second before repeating 🙂
//temp

 Serial.print("Temperature: ");
  Serial.print(rtc.getTemp());
  Serial.println(" C");

  //  LCD 
 //  LCD begin

   
  lcd.backlight();


  

if(t.hour == OnHour1 && t.min == OnMin1)

{


FirstOn ();
delay(1000);
 lcd.clear();  
}
else if(t.hour == OffHour1 && t.min == OffMin1)

{
 
FirstOff ();

 delay(1000);
 lcd.clear();  
}


//////////////////////////////////second time/////////////////////////////////

if(t.hour == OnHour2 && t.min == OnMin2)

{

SecondOn ();
//delay(1000);
lcd.clear();
}
else if(t.hour == OffHour2 && t.min == OffMin2)

{
 

SecondOff ();
//delay(1000);
lcd.clear(); 
   
}







}


void lcdClock ()  

{

 lcd.setCursor(0,0);
 lcd.print(rtc.getTemp());

lcd.setCursor(5,0);
lcd.print("C");

 lcd.setCursor(8,0);
 lcd.print(rtc.getTimeStr());
 
 lcd.setCursor(0,1);
 lcd.print("Date: ");
 lcd.print(rtc.getDateStr());

  t = rtc.getTime();
  Serial.print(t.hour);
  Serial.print(" hour(s), ");
  Serial.print(t.min);
  Serial.print(" minute(s)");
  Serial.println(" ");
  delay (1);
}

void FirstOn ()
{ 
    digitalWrite(ValvePin,LOW);
   delay(5000);
   digitalWrite(ValvePin,HIGH);
   delay(5000);
    digitalWrite(ValvePin,LOW);
   delay(5000);
   digitalWrite(ValvePin,HIGH);
    lcd.setCursor(0,0);    
    lcd.print("PUMP ON");
    Serial.println("PUMP ON");
    
 }
    
   

 void FirstOff ()
 
{   
    digitalWrite(ValvePin,HIGH);
    
    lcd.setCursor(0,0);
    lcd.print("PUMP OFF");
    Serial.println("PUMP OFF");
    
    

}


///////////////////////////////////////// second control

void SecondOn ()
{ 
    digitalWrite(ValvePin,LOW);
   delay(5000);
   digitalWrite(ValvePin,HIGH);
   delay(5000);
    digitalWrite(ValvePin,LOW);
   delay(5000);
   digitalWrite(ValvePin,HIGH);
    lcd.setCursor(0,0);
    lcd.print("FEED ON");
    Serial.println("FEED ON");
   
    }
    
   

 void SecondOff ()
 
{   
    digitalWrite(ValvePin,HIGH);
    
    lcd.setCursor(0,0);
    lcd.print("FEED OFF");
    Serial.println("FEED OFF");
    
    

}

void keyPad ()
{
  
  char customKey = customKeypad.getKey();

  if(customKey == NO_KEY){
    lcdClock ();
    
  }

  
   if(customKey == '1' ){
  lcd.clear();  
  digitalWrite(relay2,LOW);

  lcd.setCursor(7,0);
  lcd.print("P1:");
  lcd.setCursor(10,0);
  lcd.print("ON");

  delay(2000);
  }
  
   if(customKey == '2' ){
  lcd.clear();  
  digitalWrite(relay3,LOW);
  lcd.setCursor(0,1);
  lcd.print("P2:");
  lcd.setCursor(3,1);
  lcd.print("ON");
  delay(2000);
  }
   if(customKey == '3' ){
  lcd.clear(); 
  digitalWrite(relay4,LOW);
  lcd.setCursor(7,1);
  lcd.print("P3:");
  lcd.setCursor(10,1);
  lcd.print("ON");

  delay(2000);
  }

  


   if(customKey == '*' ){
  lcd.clear(); 
  digitalWrite(relay2,HIGH);
  digitalWrite(relay3,HIGH);
  digitalWrite(relay4,HIGH);

  

  lcd.setCursor(3,0);
  lcd.print("All Close");
   delay(2000);
  }
  
  if (customKey){
    Serial.println(customKey);
    
  }
}
  

void keyTimer ()
{
  
  
  //  set on/off time 1
const int OnHour1 = 16; //SET TIME TO ON ValvePin (24 HOUR FORMAT)
const int OnMin1 = 13;
const int OffHour1 = 16; //SET TIME TO OFF ValvePin
const int OffMin1 = 14;

//  set on/off time 2
const int OnHour2 = 17; //SET TIME TO ON ValvePin (24 HOUR FORMAT)
const int OnMin2 = 0;
const int OffHour2 = 17; //SET TIME TO OFF ValvePin
const int OffMin2 = 0;
}

void autoLight ()
{
  digitalRead(motion);
  digitalRead(light);
  if((motion == 1)&&(light == 0))
  {
    digitalWrite(relay3,LOW);
    Serial.print(" light on "); 
  }
}

Alcohol gel dispenser A4988 stepping motor + HC-SR04

 

 

 

 

Code

const int pingPin = 13;
int inPin = 12;

//////////////// step motor

#define dirPin 3
#define stepPin 4
#define stepsPerRevolution 800

void setup() {

Serial.begin(9600);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}

void loop()
{


long duration, cm;

pinMode(pingPin, OUTPUT);


digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(inPin, INPUT);
duration = pulseIn(inPin, HIGH);

cm = microsecondsToCentimeters(duration);

if (cm <= 15) { 
motorFeed();
}
else {
motorStop();
}
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);


}

long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}


void motorFeed() {
// Set the spinning direction clockwise:
digitalWrite(dirPin, HIGH);
// Spin the stepper motor 1 revolution slowly:
for (int i = 0; i < stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
//delay(500);
// Set the spinning direction counterclockwise:
digitalWrite(dirPin, LOW);
// Spin the stepper motor 1 revolution quickly:
for (int i = 0; i < stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}

}


void motorStop() {
// Set the spinning direction clockwise:
digitalWrite(dirPin, LOW);
// Spin the stepper motor 1 revolution slowly:
for (int i = 0; i < stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
}


}


Arduino MEGA 2560 Multiwii Drone :Bluetooth Telemetry

HC-05 โมดูลบลูทู ธ ไร้สายแบบอนุกรมรับส่งสัญญาณทาสและปริญญาโท

https://sea.banggood.com/custlink/mD33qYPZPb

FT232RL FTDI USB เป็น TTL โมดูลอะแดปเตอร์แปลงอนุกรม Geekcreit สำหรับ Arduino - ผลิตภัณฑ์ที่ทำงานร่วมกับบอร์ด Arduino อย่

https://sea.banggood.com/custlink/3K3v2h59Hw

 

Connect

FTDI                   Bluetooth

RX     >>>>        TX

TX     >>>>         RX

Open IDE Sketch the

Tool >  port > Com? (Select com port)

Type

AT enter for test OK mean good communication

 

 

 

 

 

 

 

Change Bluetooth Baud rate

Type

AT+BAUD8(change baud rate 115200)

 

Connect Bluetooth  to Mega2560

VDO

Arduino MEGA 2560 Multiwii Drone :Test GPS

Test VDO

All component

  1. Gyroscope + Accelerometer  (MPU6050)

https://sea.banggood.com/custlink/m3Gm23fm02

  • UBlox GPS + Magnetometer (HMC5883)
  • Magnetometer (HMC5883)

https://sea.banggood.com/custlink/GDKKkmuGgC

G-Model GPS/Compass

Compass

Orange =  SCL

White = SDA

 

GPS

Green = TX

Yellow = RX

 

https://sea.banggood.com/custlink/GmvKU31KSq

 

Code program

https://code.google.com/p/multiwii/

 

How to configuration

 

 

 

 

 

 

 

 

 

 

Arduino Drone : MEGA2560 Aititude Hold + GPS Hold EP1

 

 

https://en.wikipedia.org/wiki/Quadcopter#Applications

Flight dynamics

Each rotor produces both a thrust and torque about its center of rotation, as well as a drag force opposite to the vehicle’s direction of flight. If all rotors are spinning at the same angular velocity, with rotors one and three rotating clockwise and rotors two and four counterclockwise, the net aerodynamic torque, and hence the angular acceleration about the yaw axis, is exactly zero, which means there is no need for a tail rotor as on conventional helicopters. Yaw is induced by mismatching the balance in aerodynamic torques (i.e., by offsetting the cumulative thrust commands between the counter-rotating blade pairs).[82][83]

 

 

Equipment

Arduino Mega 2560

MPU6050 Gyro

GY-63 (MS5611) Baro

Remote Flysky FS i6X

GPS/Compass

Motor 1000KV + Propeller . x 4

 

Arduino Mega 2560

Geekcreit® MEGA 2560 R3 ATmega2560 MEGA2560 Development Board With USB Cable For Arduino

 

https://www.banggood.com/custlink/3vvKIRyDGN

Arduino Mega 2560 manual : https://drive.google.com/file/d/13i09MBBWXAa5Uu954PXWiCqSSYdmQ2QQ/view?usp=sharing

 

MPU 6050

6DOF MPU-6050 3 Axis Gyro With Accelerometer Sensor Module For Arduino

https://www.banggood.com/custlink/3mvK5s3Gz8

https://drive.google.com/file/d/1BYW_bjD6cxUSvv3vItt9JMjjXNmjxblO/view?usp=sharing

 

GPS

APM2.6 2.8 GPS Module High Precision GPS With Electronic Compass PIXHAWK

https://www.banggood.com/custlink/vKv38YdDd9

 

MS5611 GY-63 Atmospheric Pressure Sensor Module IIC/SPI Communication

https://www.banggood.com/custlink/DK33iYR3y0

Baro meter :  https://drive.google.com/file/d/1e7zeBpGc95ciLv3jVrbm9lfs_Dmjgq2T/view?usp=sharing

FlySky FS-i6 2.4G 6CH AFHDS RC Radion Transmitter With FS-iA6B Receiver for RC FPV Drone

https://www.banggood.com/custlink/mGGKiEYKrz

https://drive.google.com/file/d/1pOiHj9m0HxIeDRs6IpjiTVY0ntMojYiw/view?usp=sharing

 

XXD 2212 Motor+ZTW Beatles AL30A Brushless ESC+Propellers Set

https://www.banggood.com/custlink/mK3G5ChiQz

 

………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………….

Wiring

 

 

Code : https://github.com/QuadTinnakon/QuadX_2560GY86_PIDAuto_V5

Next step is :

Print out value for adjust

Select baud rate 57600

Map column left to right with serial print

 

Adjust remote

Min :1050  Max : 1950 all channel.

 

Calibrate sensor.

Magneto

Turn Quad copter by hand find Magneto value

Xmin Xmax

Ymin,Ymax

Zmin,Zmax  lay down quad   +/- 90

 

Adjust in Config.h

 

 

NANO DRONE EP3 : Connect +BARO+GYRO+GPS

 

Wiring

 

6DOF MPU-6050 3 Axis Gyro With Accelerometer Sensor Module For Arduino

MPU6050 :   https://www.banggood.com/custlink/3mvK5s3Gz8

 

GY-68 BMP180 Digital Barometric Pressure Sensor Board Module for for RC Drone FPV Racing Multi Rotor

BMP180 baro meter :  https://www.banggood.com/custlink/mvDvFNKK1d

GY GPS Module Board 9600 Baud Rate With Antenna For Arduino

GPS Module : https://www.banggood.com/custlink/DKvK5QKDfH

Code

This code not professional code for flight controller just example for learn how to add all sensor please under stand !!

Download from link below

https://drive.google.com/drive/folders/1LJNr3Zmuv7MkJ4mpGKmBya4CeUyqdhKT?usp=sharing

NANO DRONE EP1 : Hook up Flysky to Arduino NANO

 

FlySky FS-i6 2.4G 6CH AFHDS RC Radion Transmitter With FS-iA6B Receiver for RC FPV Drone

https://www.banggood.com/custlink/KKK3FoBbUO

Manual : https://drive.google.com/file/d/1pOiHj9m0HxIeDRs6IpjiTVY0ntMojYiw/view?usp=sharing

Wiring

Bind Remote ( Connect Transmitter and receiver )

 

 

Code for read data from Flysky receiver
int channel1 = 2; //   Pitch
int channel2 = 3;//    
int channel3 = 4; //  Throttle
int channel4 = 5;//    YAW
int SWA = 6;// SWA

int Channel1 = 0 ; // Used later to 
int Channel2 = 0 ; // store values
int Channel3 = 0 ; // Used later to 
int Channel4 = 0 ; // store values
int SWAstate = 0 ; // store values


void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
   pinMode (channel1, INPUT);// initialises the channels
   pinMode (channel2, INPUT);// as inputs
   pinMode (channel3, INPUT);// initialises the channels
   pinMode (channel4, INPUT);// as inputs
   pinMode (SWA,INPUT);// Switch A 


}

void loop() {
  // put your main code here, to run repeatedly:

   
  Channel1 = (pulseIn (channel1, HIGH)); // Checks the value of channel1
  Serial.print ("Channel1 :");
  Serial.println (Channel1); //Prints the channels value on the serial monitor

Channel2 = (pulseIn (channel2, HIGH)); // Checks the value of channel1
  Serial.print ("Channel2 :");
  Serial.println (Channel2); //Prints the channels value value on the serial monitor

Channel3 = (pulseIn (channel3, HIGH)); // Checks the value of channel1
    Serial.print ("Channel3 :");
  Serial.println (Channel3); //Prints the channels value value on the serial monitor

Channel4 = (pulseIn (channel4, HIGH)); // Checks the value of channel1
    Serial.print ("Channel4 :");
  Serial.println (Channel4); //Prints the channels value value on the serial monitor
int SWAState = (pulseIn (SWA,HIGH)); // Checks the value of channel1
    Serial.print ("SWAState :   ");
  Serial.println (SWAState); //Prints the channels value value on the serial monitor

delay(2000);
}

Quad copter Arduino NANO : Test and Calibration ESC

https://en.wikipedia.org/wiki/Aircraft_principal_axes

 

https://en.wikipedia.org/wiki/Quadcopter

 

Remote control FlySky   FS-I6C  TX , FS-IA6B RX

 

500px-FlySky_IA6B_pinout-f89eed4f

https://www.dronetrest.com/t/connecting-a-matek-f405-ctr-to-fs-ia6b-receiver/7081

Flysky FS-I6 TX   remote control manual

https://drive.google.com/file/d/1pOiHj9m0HxIeDRs6IpjiTVY0ntMojYiw/view?usp=sharing

 

reference

http://www.electronoobs.com/eng_robotica_tut5_3.php

 

 

Test ESC and MOTOR and Direction

 

 

 

/*
        Arduino Brushless Motor Control
     by Dejan, https://howtomechatronics.com

and Modify by A-Arduino  :    www.a-arduino.com

*/
#include <Servo.h>
Servo ESC1;     // create servo object to control the 4 ESC
Servo ESC2;
Servo ESC3;
Servo ESC4;
int potValue;  // value from the analog pin
void setup() {
  // Attach the ESC on pin 9
  ESC1.attach(A1,1000,2000); // (pin A1, min pulse width, max pulse width in microseconds) 
  ESC2.attach(A2,1000,2000); // (pin A2, min pulse width, max pulse width in microseconds) 
  ESC3.attach(A3,1000,2000); // (pin A3, min pulse width, max pulse width in microseconds) 
  ESC4.attach(A4,1000,2000); // (pin A4, min pulse width, max pulse width in microseconds) 
}
void loop() {
  potValue = analogRead(A0);   // reads the value of the potentiometer (value between 0 and 1023)
  potValue = map(potValue, 0, 1023, 0, 180);   // scale it to use it with the servo library (value between 0 and 180)
  ESC1.write(potValue);    // Send the signal to the ESC
  ESC2.write(potValue);    // Send the signal to the ESC
  ESC3.write(potValue);    // Send the signal to the ESC
  ESC4.write(potValue);    // Send the signal to the ESC
}