Okay so basically I am trying to make an app for my school group project I'm using an Arduino uno for a smart green house and I'm using a water level sensor, gas sensor ,temperature sensor and a servo motor. i want the data I'm receiving from my sensors to show on the app and when I click a button the servo motor activates. I also plan on making the app send alerts to the phone when the water level is too low and when the co2 increases in the greenhouse.
this is my code in the Arduino so far:
// Define the pin connections
#define MOISTURE_SENSOR_PIN A0 // Analog pin for soil moisture sensor
#define PUMP_RELAY_PIN 7 // Digital pin for controlling the water pump via relay
// Define the moisture threshold
#define MOISTURE_THRESHOLD 500 // Adjust this value according to your soil moisture sensor
#include <SoftwareSerial.h>
const int waterSensorPin = 8; // Analog pin connected to the water level sensor
const int bluetoothTx = 3; // Arduino's TX pin connected to HC-05's RX pin
const int bluetoothRx = 2; // Arduino's RX pin connected to HC-05's TX pin
SoftwareSerial bluetoothSerial(bluetoothTx, bluetoothRx);
int sensorPin = A5; // Analog input pin connected to the MQ-2 sensor
float sensorValue = 0; // Variable to store sensor value
#include "Servo.h"
Servo myservo;
#define servoPin 5
void setup() {
// Initialize the pump relay pin
pinMode(PUMP_RELAY_PIN, OUTPUT);
digitalWrite(PUMP_RELAY_PIN, LOW); // Make sure the pump is initially off
pinMode(waterSensorPin, INPUT);
pinMode(bluetoothTx, OUTPUT);
pinMode(bluetoothRx, INPUT);
myservo.attach(servoPin);
Serial.begin(9600); // Start serial communication for debugging
bluetoothSerial.begin(9600); // Start Bluetooth serial communication
}
void loop() {
// Check soil moisture level
int moistureLevel = analogRead(MOISTURE_SENSOR_PIN);
// Check if moisture level is below threshold
if (moistureLevel < MOISTURE_THRESHOLD) {
// Activate the pump
digitalWrite(PUMP_RELAY_PIN, HIGH);
delay(5000); // Run the pump for 5 seconds (adjust as needed)
digitalWrite(PUMP_RELAY_PIN, LOW); // Turn off the pump
}
int waterLevel = analogRead(waterSensorPin);
float voltage = waterLevel * (5.0 / 1023.0); // Convert analog reading to voltage
float waterPercentage = map(voltage, 0.0, 5.0, 0, 100); // Map voltage to percentage
Serial.print("Water Level: ");
Serial.print(waterPercentage);
Serial.println("%");
// Send data to Bluetooth module
bluetoothSerial.print("Water Level: ");
bluetoothSerial.print(waterPercentage);
bluetoothSerial.println("%");
delay(1000); // Delay for stability
sensorValue = analogRead(sensorPin); // Read analog value from sensor
float Voltage = sensorValue * (5.0 / 1023.0); // Convert analog value to voltage
// Convert voltage to CO2 concentration (you may need to adjust these values)
// The MQ-2 sensor is not specifically calibrated for CO2, so this will be an approximation
// You may need to calibrate it using known CO2 concentration levels
float ppm = map(Voltage, 0.2, 4.0, 0, 2000);
Serial.print("CO2 Level: ");
Serial.print(ppm);
Serial.println(" ppm");
bluetoothSerial.print("CO2 Level: ");
bluetoothSerial.print(ppm);
bluetoothSerial.println(" ppm");
delay(1000); // Delay before next reading (adjust as needed)
}
and here is on the app:
note: I'm using HC-05 Bluetooth module
I don't understand much about coding so if someone could help me finish this i would appreciate it.