Greetings to the Arduino fam,
As a newcomer to modifying and tinkering micro-controlers i would like to share my problem with the community and get some ideas or tips on this one.
Im having an Arduino Uno which i want to get readings from 16 soil humidity sensors when i command to**, while i can also manually turn on/off 16 12v micro liquid pumps for a gardening system. Finally the whole system has to be connected to the internet through the RasPi 3 B which is already comes with WiFi on it. That means i need to code a GUI through Tkinter (or else) which sounds to be the easiest method all over the internet (but i still don't have any success by using it following the first tutorial).
Till now i have manage to run this system with one pump, which is getting power from Vin pin on Arduino, as for a relay im using a 240ohm resistor and a 2N2222 transistor to make a switch and a N4001 diode on pump's pins to kill any "spikes". (probably soon i will post scheme etc.) Finally the transistor is grounded to the Arduino GND.
One soil hum. sensor, w. fixed code which let me get continuous measurements (2sec) from a DHT11 RH/temp. sensor, **but i choose to command my soil humidity sensor when to get readings because cheap soil sensors are the worst quality, means that, as electricity runs through them to get the electric conductivity measurements, electrolysis destroying the probes. So i found two ways to control that, by letting the arduino counting(which proved that burned my mind while i was trying to include more commands and actions) or w. serial commands.
(*all readings are printed on serial port so i can get the readings to my pc or RasPi)
Then its time to get all the readings on my screen and by looking at the measurements, to start or not the water pump. The pump is coded to start for 5 seconds after my command and stop immediately, that is to prevent possible bug which may cause flooding (this can be change based on each installation e.g. pot size, growing medium etc.).
Well the whole thing is that i want to expand this automation for more plants.
I brought from a local store a 5V 16-Channel Relay Module for Arduino
SPECS
Working voltage: 5V
Channel: 16 channel
This relay module is 5V active low.
It is an 16-channel relay interface board, which can be controlled directly by a wide range of microcontrollers such as Arduino, AVR, PIC, ARM, PLC, etc.
It is also able to control various appliances and other equipments with large current.
Relay output maximum contact is AC250V 10A and DC30V 10A.
Standard interface can be directly connected with microcontrollers.
Red working status indicator lights are conducive to the safe use.
Widely used for all MCU control, industrial sector, PLC control, smart home control.
The next days I'm going to get a Mux Shield II from Mayhew Labs, a shield which seems to let me expand the analogue reading pins to 16 (which connected to the soil hum. sensors). Im also thinking that i can use an Arduino nano (that i already have) which hold some analogue pins that can do the job, but this is up for discussion.
At the end I'm coming up with some questions
-How to connect the relay module?
-Do i really need the Mux shield?(i need opinions)
-Is there any useful thread about GUI which running on Raspbian and allowing control over the arduino? i tried with pyfirmata but no luck yet.
-Is there any way to control the speed of the pumps i should look or time dripping seems better?
-The addition of RTC will be a good idea, as it can store real time measurements for later analysis, is that a complicated action for the arduino an holds enough space or it is easier for the RasPi to get and store readings?
Here's the sketch im using as prototype with 1 pump, 1 DHT11, 1 YL38+YL69
Please take your time and advice!
#include <dht.h>
#define DHT11_PIN 7
dht DHT;
int userStart = 0;
//define the pump
int motorPin = A0; // pin that turns on the motor
int blinkPin = 13; // pin that turns on the LED
int watertime = 5; // how long to water in seconds
int waittime = 60; // how long to wait between watering, in minutes
// Define our pins.
const int soil = A1;
const int power = 12;
int output_value;
void setup() {
pinMode(soil, INPUT);
pinMode(power, OUTPUT);
// Start with sensor OFF
digitalWrite(power, LOW);
pinMode(motorPin, OUTPUT); // set A0 to an output so we can use it to turn on the transistor
pinMode(blinkPin, OUTPUT);
digitalWrite(motorPin, LOW);
digitalWrite(blinkPin, LOW);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
switch(Serial.read())
{
case '1':
// Turn sensor ON and wait a moment.
digitalWrite(power, HIGH);
Serial.print("Reading the Sensors ...");
Serial.print('\n');
delay(2000);
output_value = analogRead(soil);
output_value = map(output_value,1003,141,0.00,100.00);
Serial.print("Food ");
Serial.print(output_value);
Serial.println("%");
// Turn sensor OFF again.
digitalWrite(power, LOW);
break;
case '2':
Serial.flush();
Serial.print("pump is ON");
digitalWrite(motorPin, HIGH); // turn on the motor
digitalWrite(blinkPin, HIGH); // turn on the LED
delay(watertime*1000); // multiply by 1000 to translate seconds to milliseconds
digitalWrite(motorPin, LOW); // turn off the motor
digitalWrite(blinkPin, LOW); // turn off the LED
Serial.print('\n');
Serial.print("pump is OFF");}
}
//RH & temp
int chk = DHT.read11(DHT11_PIN);
Serial.print("Room Temp. c");
Serial.println(DHT.temperature);
Serial.print("RH %");
Serial.println(DHT.humidity);
delay(2000);
}
