Commit 9b643dfe authored by Ravindu Dolawatta's avatar Ravindu Dolawatta

initi-2

parent 04ffbb35
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <LoRa.h>
#include <Wire.h>
#include <BH1750.h>
#include <AHT10.h>
#define ss 53
#define rst 11
#define dio0 8
#define CJMCU101 A0
#define soil A1
#define ONE_WIRE_BUS 2
int counter = 0;
float CJM, soildata, Leaf_temp, lux, h, t;
String msg;
unsigned long lastTime = 0;
unsigned long timerDelay = 10000;
BH1750 lightMeter;
AHT10Class AHT10;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
Wire.begin();
lightMeter.begin();
sensors.begin();
while (!Serial);
LoRa.setPins(ss, rst, dio0);
Serial.println("LoRa Sender");
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
if (AHT10.begin(eAHT10Address_Low)) {
Serial.println("Init AHT10 Success!");
} else {
Serial.println("Init AHT10 Failed!");
}
}
void loop() {
counter++;
CJMCU101Read();
soilRead();
probe18b20Read();
BH1750luxRead();
AHT10Read();
if ((millis() - lastTime) > timerDelay) {
msg = "" + (String) CJM + ";" + (String)soildata + ";" + (String)Leaf_temp + ";" + (String)lux + ";" + (String)h + ";" + (String)t + "";
Serial.print("msg Data: ");
Serial.println(msg);
LoRa.beginPacket();
LoRa.print(msg);
LoRa.endPacket();
lastTime = millis();
}
}
void CJMCU101Read() {
CJM = analogRead(CJMCU101);
Serial.print("CJMCU101 Read : ");
Serial.println(CJM);
}
void soilRead() {
soildata = analogRead(soil);
Serial.print("Soil Read : ");
Serial.println(soildata);
}
void probe18b20Read() {
sensors.requestTemperatures();
Leaf_temp = sensors.getTempCByIndex(0);
Serial.print("Leaf temperature: ");
Serial.println(Leaf_temp);
}
void BH1750luxRead() {
lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
}
void AHT10Read() {
h = AHT10.GetHumidity();
t = AHT10.GetTemperature();
Serial.println(String("") + "Humidity(%RH):\t\t" + AHT10.GetHumidity() + "%");
Serial.println(String("") + "Temperature(℃):\t" + AHT10.GetTemperature() + "℃");
}
#include <SPI.h>
#include <LoRa.h>
#define ss 5
#define rst 14
#define dio0 2
void setup() {
Serial.begin(9600);
while (!Serial);
LoRa.setPins(ss, rst, dio0);
Serial.println("LoRa Receiver");
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop() {
int packetSize = LoRa.parsePacket();
if (packetSize) {
Serial.print("Received packet '");
while (LoRa.available()) {
Serial.print((char)LoRa.read());
}
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
}
#define turbidity A0
#define SENSOR 3
float turbiditydata;
long currentMillis = 0;
long previousMillis = 0;
int interval = 1000;
boolean ledState = LOW;
float calibrationFactor = 4.5;
volatile byte pulseCount;
byte pulse1Sec = 0;
float flowRate;
unsigned long flowMilliLitres;
unsigned int totalMilliLitres;
float flowLitres;
float totalLitres;
int sensorValue = 0;
void pulseCounter() {
pulseCount++;
}
void setup() {
Serial.begin(9600);
pinMode(turbidity, INPUT);
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
previousMillis = 0;
attachInterrupt(digitalPinToInterrupt(SENSOR), pulseCounter, FALLING);
}
void loop() {
turbidityRead();
flowRead();
}
void turbidityRead() {
turbiditydata = analogRead(turbidity);
Serial.print("Turbidity Data : ");
Serial.println(turbiditydata);
}
void flowRead(){
currentMillis = millis();
if (currentMillis - previousMillis > interval) {
pulse1Sec = pulseCount;
pulseCount = 0;
flowRate = ((1000.0 / (millis() - previousMillis)) * pulse1Sec) / calibrationFactor;
previousMillis = millis();
flowMilliLitres = (flowRate / 60) * 1000;
flowLitres = (flowRate / 60);
totalMilliLitres += flowMilliLitres;
totalLitres += flowLitres;
Serial.print("Output Liquid Quantity: ");
Serial.print(totalMilliLitres);
Serial.print("mL / ");
Serial.print(totalLitres);
Serial.println("L");
}
}
import cv2
import numpy as np
def nothing(x):
pass
# cap = cv2.VideoCapture(0)
while True:
# _, frame = cap.read()
frame = cv2.imread('licensed.jpg')
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
l_h =0
l_s =88
l_v =0
u_h =255
u_s =255
u_v =255
l_b = np.array([l_h,l_s,l_v])
u_b = np.array([u_h,u_s,u_v])
mask = cv2.inRange(hsv, l_b, u_b)
res = cv2.bitwise_and(frame, frame, mask=mask)
cv2.imshow('Original Image', frame)
cv2.imshow('Filtered Object', mask)
key = cv2.waitKey(1)
if key==27:
break
# cap.release()
cv2.destroyAllWindows()
\ No newline at end of file
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
///////////////////Connections///////////////////////
#define PIN_UVLDR A0
#define PIN_SOILMOIST A1
#define PIN_DHT11 A2
#define POUT_UVLIGHT 2
#define POUT_ROOFCURTAIN_STEPPER_IN1 3
#define POUT_ROOFCURTAIN_STEPPER_IN2 4
#define POUT_ROOFCURTAIN_STEPPER_IN3 5
#define POUT_ROOFCURTAIN_STEPPER_IN4 6
#define POUT_WATERPUMP 7
#define POUT_FANS 8
//////////////////Libraries////////////////////////////////
#include <DHT.h>
#define DHTYPE DHT11
DHT dht(PIN_DHT11, DHTYPE);
#include <AccelStepper.h>
// Define the AccelStepper interface type; 4 wire motor in half step mode:
#define MotorInterfaceType 4 //8
//const int stepsPerRevolution = 2038; // steps per revolution //Length of Curtain - 20 Inches
// number of steps per revolution = 360 / 1.8 = 200
// Creates an instance of stepper class
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
AccelStepper roofcurtain = AccelStepper(MotorInterfaceType,
POUT_ROOFCURTAIN_STEPPER_IN1,
POUT_ROOFCURTAIN_STEPPER_IN3,
POUT_ROOFCURTAIN_STEPPER_IN2,
POUT_ROOFCURTAIN_STEPPER_IN4);
////////////////////input_data //////////////////////
int AVGTEMP;
int AVGHUMIDITY;
int AVGCO2;
int AVGSOILMOIST;
String FERTILIZINGTIME;
int FERTILIZINGDURATION;
String SUNRISETIME;
int AVGLIGHTDURATION;
int AVGUVINDEX;
int UVINDEX_UPLIMIT;
///////////////output_data///////////////////////////
int TEMP;
int HUMIDITY;
int eCO2;
bool FANS;
bool HUMIDIFIER;
float SOILMOIST;
int WATERLVL;
bool WATERING, NO_WATER;
int FERTLVL;
bool FERTILIZING, NO_FERTILIZER, FERTILIZED;
int UVINDEX;
bool UVLIGHT_ON;
bool LIGHT_EXPOSE;
bool ROOF_CURTAIN_WORKING;
bool ROOF_CURTAIN_OPEN;
void get_data(){
//when api is available, all variables must be updated using that
//use date to call the variable and get data
//int day_num; // *** used to retrieve data from the api
AVGTEMP = 27; //d celcius
AVGHUMIDITY = 90; //30% //20-90% RH
AVGSOILMOIST = 870;//870; //15%
//<717 More Soil Moistue
//>717 Less Soil Moisture
AVGUVINDEX=2; //0-12
ROOF_CURTAIN_OPEN = false;
Serial.println("++++++++++++++++++++++++INPUT DATA+++++++++++++++++++++++++++++");
Serial.print("AVGTEMP = ");
Serial.print(AVGTEMP);
Serial.print(" °C, AVG HUMI = ");
Serial.print(AVGHUMIDITY);
Serial.println(" %");
Serial.print("AVG SOILMOIST = ");
Serial.print(AVGSOILMOIST);
Serial.print(" or ");
Serial.print((1024-AVGSOILMOIST)/10.24);
Serial.print("%, AVG UVIDX = ");
Serial.print(AVGUVINDEX);
Serial.println(" /12");
}
void set_data(){
//send data to google sheet using api
//api call = TIME+VARIABLE_A+VARIABLE_B+VARIABLE_C;
//Serial.print("++++++++++++++++OUTPUT DATA: %s++++++++++++++++++\n", logtime.c_str());
Serial.println("++++++++++++++++OUTPUT DATA: ++++++++++++++++++");
Serial.print("TEMP = ");
Serial.print(TEMP);
Serial.print(" °C, HUMI = ");
Serial.print(HUMIDITY);
Serial.print(" %, FANS ON = ");
Serial.println(FANS ? "Yes" : "No");
Serial.print("SOILMOIST = ");
Serial.print(SOILMOIST);
Serial.print(" or ");
Serial.print(((1024-SOILMOIST)/10.24));
Serial.print("%, WATERING = ");
Serial.println(WATERING ? "Yes" : "No");
Serial.print("UVINDEX = ");
Serial.print(UVINDEX);
Serial.print(" /12, UVLIGHT = ");
Serial.println(UVLIGHT_ON ? "On" : "Off");
Serial.print("ROOF CURTAIN WORKING = ");
Serial.print(ROOF_CURTAIN_WORKING ? "Yes" : "No");
Serial.print(", ROOF CURTAIN = ");
Serial.println(ROOF_CURTAIN_OPEN ? "Open" : "Closed");
}
//////////////////////////////////////////////////
void atmospheric_control_setup(){
pinMode(POUT_FANS,OUTPUT);
dht.begin();
}
void atmospheric_control_loop(){
/***************************SENSING***************************/
TEMP = dht.readTemperature();
HUMIDITY = dht.readHumidity();
if (isnan(HUMIDITY) || isnan(TEMP)) {
TEMP = 28;
HUMIDITY = 90;
}
/***************************ACTUATING***************************/
if ( TEMP > AVGTEMP){
digitalWrite(POUT_FANS, HIGH);
FANS = true;
}
else if ( TEMP < AVGTEMP){
digitalWrite(POUT_FANS, LOW);
FANS = false;
}
}
void irrigation_fertigation_control_setup() {
pinMode(POUT_WATERPUMP, OUTPUT);
}
void irrigation_fertigation_control_loop(){
//SOILMOIST = (analogRead(PIN_SOILMOIST)/1024)*100;
SOILMOIST = analogRead(PIN_SOILMOIST);
if (SOILMOIST > AVGSOILMOIST){
digitalWrite(POUT_WATERPUMP, HIGH);
WATERING = true;
}
else if (SOILMOIST < AVGSOILMOIST){
digitalWrite(POUT_WATERPUMP, LOW);
WATERING = false;
}
}
void ROOF_CURTAIN_CURLOUT(){
ROOF_CURTAIN_WORKING = true;
unsigned long starttime = millis();
unsigned long endtime = starttime;
while ((endtime - starttime) <=70000)
{
roofcurtain.setSpeed(700);
roofcurtain.runSpeed();
endtime = millis();
}
ROOF_CURTAIN_WORKING = false;
ROOF_CURTAIN_OPEN = true;
}
void ROOF_CURTAIN_CURLIN(){
ROOF_CURTAIN_WORKING = true;
unsigned long starttime = millis();
unsigned long endtime = starttime;
while ((endtime - starttime) <=60000)
{
roofcurtain.setSpeed(-700);
roofcurtain.runSpeed();
endtime = millis();
}
ROOF_CURTAIN_WORKING = false;
ROOF_CURTAIN_OPEN = false;
}
void light_exposure_control_setup(){
pinMode(POUT_UVLIGHT,OUTPUT);
roofcurtain.setMaxSpeed(1000);
}
void light_exposure_control_loop(){
/***************************SENSING***************************/
int uv_read = analogRead(PIN_UVLDR);
float uv_volt = uv_read *(5.0/1024);
UVINDEX = (uv_volt/.1); //ceiling roundup function
/***************************ACTUATING*************************/
if (UVINDEX < AVGUVINDEX){ //Lower
digitalWrite(POUT_UVLIGHT, HIGH);
UVLIGHT_ON = true;
if(ROOF_CURTAIN_OPEN == false) {
ROOF_CURTAIN_CURLIN();
}
}
else if (UVINDEX > AVGUVINDEX){
digitalWrite(POUT_UVLIGHT, LOW);
UVLIGHT_ON = false;
if(ROOF_CURTAIN_OPEN == true){
ROOF_CURTAIN_CURLOUT();
}
}
}
void setup() {
Serial.begin(9600);
Serial.println("----------------NTP Project-----------------");
get_data();
atmospheric_control_setup();
irrigation_fertigation_control_setup();
light_exposure_control_setup();
}
void loop() {
atmospheric_control_loop();
irrigation_fertigation_control_loop();
light_exposure_control_loop();
set_data();
delay(2000);
}
/*
12:16:42.431 -> ----------------NTP Project-----------------
12:16:42.478 -> ++++++++++++++++++++++++INPUT DATA+++++++++++++++++++++++++++++
12:16:42.572 -> AVGTEMP = 27 °C, AVG HUMI = 90 %
12:16:42.619 -> AVG SOILMOIST = 15%, AVG UVIDX = 2 /12
12:17:42.649 -> ++++++++++++++++OUTPUT DATA: ++++++++++++++++++
12:17:42.696 -> TEMP = 25 °C, HUMI = 95 %, FANS ON = No
12:17:42.743 -> SOILMOIST = 851.00 or 16.89%, WATERING = No
12:17:42.790 -> UVINDEX = 0 /12, UVLIGHT = On
12:17:42.837 -> ROOF CURTAIN WORKING = No, ROOF CURTAIN = Closed
12:18:44.906 -> ++++++++++++++++OUTPUT DATA: ++++++++++++++++++
12:18:44.953 -> TEMP = 25 °C, HUMI = 95 %, FANS ON = No
12:18:45.000 -> SOILMOIST = 848.00 or 17.19%, WATERING = No
12:18:45.046 -> UVINDEX = 0 /12, UVLIGHT = On
12:18:45.046 -> ROOF CURTAIN WORKING = No, ROOF CURTAIN = Closed
*/
/* Example sketch to control a 28BYJ-48 stepper motor with ULN2003 driver board, AccelStepper and Arduino UNO: continuous rotation. More info: https://www.makerguides.com */
// Include the AccelStepper library:
#include <AccelStepper.h>
// Motor pin definitions:
#define motorPin1 3 // IN1 on the ULN2003 driver
#define motorPin2 4 // IN2 on the ULN2003 driver
#define motorPin3 5 // IN3 on the ULN2003 driver
#define motorPin4 6 // IN4 on the ULN2003 driver
// Define the AccelStepper interface type; 4 wire motor in half step mode:
#define MotorInterfaceType 4 //8
// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper library with 28BYJ-48 stepper motor:
AccelStepper stepper = AccelStepper(MotorInterfaceType, motorPin1, motorPin3, motorPin2, motorPin4);
void setup() {
// Set the maximum steps per second:
stepper.setMaxSpeed(1000);
}
void CurtainAction(int sign){
uint32_t interval = 10000;
static uint32_t nextTime;
// check if it's time
if (millis() - nextTime >= interval)
{
// update next time
nextTime += interval;
stepper.setSpeed(sign * 700);
stepper.runSpeed();
}
}
void loop() {
// CurtainAction(-1);
//delay(1000);
//CurtainAction(1);
//delay(1000);
stepper.setSpeed(700);
stepper.runSpeed();
}
//Curl Up Time = 60Sec
//Curl Down Time = 70Sec
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment