Hey! I'm brand new to Arduino. I'm not new to electronics, but I haven't done a lot of board level stuff and I have limited knowledge when it comes to coding.
That said, I've decided that I want to make a small semi-automated garden. It's going to have two phases. The first is the indoor phase. I want to control a couple grow lights and log the temperature, humidity, and soil moisture on my laptop with a WiFi module. Phase two is going to be the outdoor phase. I want to control the grow lights based on BOTH time and exposure to natural light, automatically water the plants based on soil moisture, and log temperature, light exposure, soil temp, and humidity.
I bought an Uno R3. I have no idea if this has enough I/O or compute power for my application. If it doesn't, that's fine. At least I have something to start with.
I also bought a dual 5V relay board that can switch 15A 125VAC (the grow lights TOTAL under 150W), a pair of soil moisture meters, a WiFi module, a light sensor, and a temp/humidity sensor. The products that I purchased will be linked at the end of this post.
I really don't know where to start. Basically, the only thing I've done is install the Arduino software and verify that the Arduino works with the relay module.
I feel that this is a pretty decent sized project for an Arduino/coding newbie. That's what I wanted, though. A reasonable sized project for me to learn on.
I really don't know where to start, so I'm not sure what questions to ask, yet.
Hello 52_Ford
My advice design a blockdiagram to identify all componets and interfaces are used.
In the second step run some tutorials for the hardware components selected and you can merge all together if you are happy with the results of pretesting.
Have a nice day and enjoy programming in C++ and learning.
Дайте миру шанс!
p.s.
You may use this project template as kick off:
This is one of the most common problems that comes up on the forum. Beginners that freely admit they don't know enough for the project they want to work on, but were temporarily convinced they did know enough at the moment when they hit those "add to basket"/"place order" buttons!
For example
is a classic error.
Uno is for using with "shields". Shields are ready-made PCBs with components fitted to them to perform a specific function. They are the same shape as an Uno and fit in top of the Uno. But you don't seem to plan to use a shield. I imagine you will need to use a breadboard or stripboard/protoboard to prototype, test and build your circuit. Using an Uno is going to be messy and painful because it is not compatible with breadboards, stripboard etc.
Uno is a 5V device and esp8266 is a 3.3V device, so they are incompatible without extra circuits/components to adapt between the voltage levels.
What exactly is this esp-12 module? You posted links to other components, but not that one, and it could be one of many things.
So I appeal to beginners coming across this topic: by all means make a shopping list, but post it on the forum (links to the specs/details of each item) before you buy. Choosing the right components is key to a successful start to your project, so please don't assume you know enough to know which to choose.
Sorry for any confusion. There's a "2 link limit" for new members on the Arduino forum. I originally linked to everything I bought. I guess it's some sort of anti-spam sorta thing... anyway, ESP is "extra-sensatory perception". The ESP-12 is the 12th version of a sensor designed to predict the weather.
I didn't expect to order all of the right parts the first go-around. I was hoping to get at least 25% of them, that way I have SOMETHING to play with and learn C++ while (Whilst) I'm waiting on the rest of the proper components. The prices were reasonable enough that I was willing to take a shot in the dark. Frankly, the water pump and the lights cost a LOT more than all of the Arduino stuff. I already have all of that, which operates just fine without Arduino. Again, I just think it'd be a fun way to get into Arduino coding and whatnot. I also plan on building a couple projects with some 6/7 YO that involve Arduino.
Edit: Considering I got a working Arduino and it was able to make the relays go "click", I'm going to call the 25% right thing a success
You need attachments to program it. You can program it with a UNO (or clone) with some care. Be interested in the link to the "UNO" you have to see if it is legit.
The reference to MicroPython and NodeMCU in that link sounds spurious as i doubt the module is preprogrammed with either.
@PaulRB is now singing my tune - the UNO (genuine or otherwise) is not a very practical format for anything else but the matching "shields".
And since the ESP is a substantially more capable microcontroller, so it makes sense to ignore the Arduino and just connect everything to the ESP. It is a bit "short" on pins, so you use various "port expanders" and I²C interface devices to connect whatever you need. I²C devices allow you to connect many things (dozens potentially) to the same two pins.
The bare ESP-12 is somewhat inconvenient, notably for programming. You might be better to go and buy one or (highly recommended) more WeMOS D1 Minis which include a regulator to provide 3.3 V from the more common 5 V, and a complete programming interface.
Around 10~12 years ago I wanted to get into electronics for a small project, having done no electronics since university in the 1980s. I looked around at the various hobby development kits. Discounted PIC because the programmers were expensive, discounted Arduino because of the wierd Breadboard-incompatible board shapes and settled on picAXE. That got me into the hobby, but, oh, the horror that is picAXE BASIC... what a mistake. A little more research and I would have found that not all Arduino models are breadboard/PCB unfriendly.
Since you have electronics experience, I would recommend going with an ESP32 board, example listed below.
It has plenty of power, can multitask if needed, has WiFi and can be programmed using the Arduino IDE and PlatformIO. Can also run sim on Wokwi.
The boards used to be $3 or so in the old days. Now $9-10.
But, you don't have to go with any of the fancy options to start with. Just use it as if it is an Uno and do soldered/breadboard connections as needed. Keep in mind its a 3.3V part, but can be powered by USB. @paulpaulson recommendation is a great place to start.
Umm... I can see that you didn't mention any motor that you'll use to water your plant. You can use 6V micro pump motor or DC 12V submersible motor for this purpose.
I have a 12V positive displacement pump. A Fimco chemical sprayer pump, actually. It does a couple GPM at something like 60PSI (or more? I forgot). Way overkill, but I already have it on hand. I WAS going to use a small 12V diaphragm pump out of a Keurig, but I burned the motor up when I was testing it.
I'm going to use one of the relay modules to switch the 120VAC power on and off going to the 12V power supply.
Ok, so I have the Arduino hooked up to one of my relay modules and the the TSL2591 light sensor.
I've been able to make both of them work independently of one another. Now, what I'm hoping to do is actuate the relay based on light level.
What I'm thinking, is having the relay close (light on) below a certain Lux and then open (light off) above a certain Lux and have some sort of differential between the two light levels to avoid flickering (as opposed to OR in conjuction with a time delay). The Lux sensor is going to be placed above the grow lights, so that it'll be sensing mostly just the sun light getting to the plants.
Keep in mind, that I want the plants to primarily be getting sun light. The grow lights are just their to augment natural light on overcast days or during hours of the day when the plants are shaded.
I don't trust the Lux sensor to be calibrated, so I'm not sure what light levels I'm going to want to set as the thresholds, yet. For certain plants, you want a certain amount of light. For LED growlights, it's generally measured in "actual watts per square foot" (or square meter, those with metric proclivities). Bascially, just the amount of watts the light actually draws. A better metric to go by is the PPFD... photosynthetic photon flux density... I don't have a fancy PPFD meter. They're expensive. What I plan on doing is sticking the TSL2591 the appropriate distance below the growlights and see what the sensor reads and use that as my ideal Lux. The lights that I bought have a diagram that shows the PPFD based on distance below the light fixture, so that's my reference (maybe it's not accurate, either, but I have to draw a line in the sand somewhere.)
TL;DR Here's what I wanna know: How do go about switching the relay on and off based on a the reading from the light sensor? I'm VERY new to C++
I would suggest combining light levels with a time delay. Basically, add some hysteresis.
Code could be:
long currentTime = 0;
long threshholdTime = 10000; // 10 sec delay
if (( lightLevel < lowLevel ) and ( millis() - currentTime > threshholdTime){
turnOnLights();
currentTime = millis();
}
The opposite for turning lights off.
This is just an idea to get you started. Not tested, and recommend testing this segment with your light sensor just by itself. Be sure to throw in plenty of print statements
I'll say it again - I'm VERY new to C++. so please be patient with me. This is my first attempt at programming anything.
All I've done as far as making the relay work was confirm function by changing the output of the "blink" example in the Arduino IDE to the digital port that my relay was hooked up to (8, in my case). I changed the on and off durations to 10,000ms, so the clicking wouldn't be as annoying.
The code for the TSL2591 is a stock example from Adafruits library.
* TSL2591 Digital Light Sensor */
/* Dynamic Range: 600M:1 */
/* Maximum Lux: 88K */
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TSL2591.h"
// Example for demonstrating the TSL2591 library - public domain!
// connect SCL to I2C Clock
// connect SDA to I2C Data
// connect Vin to 3.3-5V DC
// connect GROUND to common ground
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)
/**************************************************************************/
/*
Displays some basic information on this sensor from the unified
sensor API sensor_t type (see Adafruit_Sensor for more information)
*/
/**************************************************************************/
void displaySensorDetails(void)
{
sensor_t sensor;
tsl.getSensor(&sensor);
Serial.println(F("------------------------------------"));
Serial.print (F("Sensor: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F(" lux"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F(" lux"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution, 4); Serial.println(F(" lux"));
Serial.println(F("------------------------------------"));
Serial.println(F(""));
delay(500);
}
/**************************************************************************/
/*
Configures the gain and integration time for the TSL2591
*/
/**************************************************************************/
void configureSensor(void)
{
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
//tsl.setGain(TSL2591_GAIN_LOW); // 1x gain (bright light)
tsl.setGain(TSL2591_GAIN_MED); // 25x gain
//tsl.setGain(TSL2591_GAIN_HIGH); // 428x gain
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
//tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS); // shortest integration time (bright light)
// tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);
tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);
// tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); // longest integration time (dim light)
/* Display the gain and integration time for reference sake */
Serial.println(F("------------------------------------"));
Serial.print (F("Gain: "));
tsl2591Gain_t gain = tsl.getGain();
switch(gain)
{
case TSL2591_GAIN_LOW:
Serial.println(F("1x (Low)"));
break;
case TSL2591_GAIN_MED:
Serial.println(F("25x (Medium)"));
break;
case TSL2591_GAIN_HIGH:
Serial.println(F("428x (High)"));
break;
case TSL2591_GAIN_MAX:
Serial.println(F("9876x (Max)"));
break;
}
Serial.print (F("Timing: "));
Serial.print((tsl.getTiming() + 1) * 100, DEC);
Serial.println(F(" ms"));
Serial.println(F("------------------------------------"));
Serial.println(F(""));
}
/**************************************************************************/
/*
Program entry point for the Arduino sketch
*/
/**************************************************************************/
void setup(void)
{
Serial.begin(9600);
Serial.println(F("Starting Adafruit TSL2591 Test!"));
if (tsl.begin())
{
Serial.println(F("Found a TSL2591 sensor"));
}
else
{
Serial.println(F("No sensor found ... check your wiring?"));
while (1);
}
/* Display some basic information on this sensor */
displaySensorDetails();
/* Configure the sensor */
configureSensor();
// Now we're ready to get readings ... move on to loop()!
}
/**************************************************************************/
/*
Shows how to perform a basic read on visible, full spectrum or
infrared light (returns raw 16-bit ADC values)
*/
/**************************************************************************/
void simpleRead(void)
{
// Simple data read example. Just read the infrared, fullspecrtrum diode
// or 'visible' (difference between the two) channels.
// This can take 100-600 milliseconds! Uncomment whichever of the following you want to read
uint16_t x = tsl.getLuminosity(TSL2591_VISIBLE);
//uint16_t x = tsl.getLuminosity(TSL2591_FULLSPECTRUM);
//uint16_t x = tsl.getLuminosity(TSL2591_INFRARED);
Serial.print(F("[ ")); Serial.print(millis()); Serial.print(F(" ms ] "));
Serial.print(F("Luminosity: "));
Serial.println(x, DEC);
}
/**************************************************************************/
/*
Show how to read IR and Full Spectrum at once and convert to lux
*/
/**************************************************************************/
void advancedRead(void)
{
// More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum
// That way you can do whatever math and comparisons you want!
uint32_t lum = tsl.getFullLuminosity();
uint16_t ir, full;
ir = lum >> 16;
full = lum & 0xFFFF;
Serial.print(F("[ ")); Serial.print(millis()); Serial.print(F(" ms ] "));
Serial.print(F("IR: ")); Serial.print(ir); Serial.print(F(" "));
Serial.print(F("Full: ")); Serial.print(full); Serial.print(F(" "));
Serial.print(F("Visible: ")); Serial.print(full - ir); Serial.print(F(" "));
Serial.print(F("Lux: ")); Serial.println(tsl.calculateLux(full, ir), 6);
}
/**************************************************************************/
/*
Performs a read using the Adafruit Unified Sensor API.
*/
/**************************************************************************/
void unifiedSensorAPIRead(void)
{
/* Get a new sensor event */
sensors_event_t event;
tsl.getEvent(&event);
/* Display the results (light is measured in lux) */
Serial.print(F("[ ")); Serial.print(event.timestamp); Serial.print(F(" ms ] "));
if ((event.light == 0) |
(event.light > 4294966000.0) |
(event.light <-4294966000.0))
{
/* If event.light = 0 lux the sensor is probably saturated */
/* and no reliable data could be generated! */
/* if event.light is +/- 4294967040 there was a float over/underflow */
Serial.println(F("Invalid data (adjust gain or timing)"));
}
else
{
Serial.print(event.light); Serial.println(F(" lux"));
}
}
/**************************************************************************/
/*
Arduino loop function, called once 'setup' is complete (your own code
should go here)
*/
/**************************************************************************/
void loop(void)
{
//simpleRead();
advancedRead();
// unifiedSensorAPIRead();
delay(500);
}
Here's the "blink" code that I used to test the relay.
/*
Blink
Turns an LED on for one second, then off for one second, repeatedly.
Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
the correct LED pin independent of which board is used.
If you want to know what pin the on-board LED is connected to on your Arduino
model, check the Technical Specs of your board at:
https://www.arduino.cc/en/Main/Products
modified 8 May 2014
by Scott Fitzgerald
modified 2 Sep 2016
by Arturo Guadalupi
modified 8 Sep 2016
by Colby Newman
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(8, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(8, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(8, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Could you please clarify for us what light levels you want to measure. And what level is going to be your low cutoff value.
The advancedRead() gives a couple of options. Lets say you want to use full.
Please run the sensor program and find out what it gives you for your low level cutoff value.
long currentTime = 0;
long threshholdTime = 10000; // 10 sec delay
int lowLevel = 0;
const int Light_Relay = 8; // this is your pin for the relay. Always better to use a good name instead of the pin number
// put this line in setup()
pinMode (Light_Relay, OUTPUT);
// This goes in loop
if (( full < lowLevel ) and ( millis() - currentTime > threshholdTime){
digitalWrite (LIGHT_Relay, HIGH);
currentTime = millis();
}
Now, this is just a start. It will only trigger the relay on. And, not tested
I suggest looking this over and trying it out.
Hopefully, you'll be able to write the part that turns the relay off.
It looks like you have a whole line of projects.
First a project for every part, make each one work by itself.
Then, put them together and make them work.
That last bit will be an education but there are 2 old EE techniques that makes it easier by far.
If you're not ready to mess with the code, think about the ideas to soak them in.
Code with delay() can be converted to use a clock and not block. It's okay to start out using delay, but it limits the things you can do at once to 1. Other than that....
I'll do that right now. I just had "a moment"... I went to unplug something I wasn't using so that I could plug one of those lights in to get some light measurements. Well, I unplugged my computer instead. LOL