From design to manufacturing, we support every stage, including software development, hardware, and CAD design. Our expertise spans scalable IoT solutions, embedded software & microcontroller programming, networks & servers, smart device integration, production automation, hardware-software integration, mobile app development and web services. Whether you need custom IoT systems, connected devices, or specialized development services, we bring your ideas to life!
Leobot Electronics South Africa - Electronic Component Supplier & Development Service Provider
Leobot Electronics Online Shop
These tutorials & guides are intended to help beginners in the field of electronics get started or provide some insight into a specific component.
The information in these guides will be updated as often as possible!
A simple but practical Arduino project to automatically water your plants, showing the usage of a 7-Segment Display, a Soild Moisture Sensor, a Temperature Sensor and a Relay.
Arduino Automated Plant Watering Project
This is a simple project aimed at those new to the world of Arduino. The aim is to build a complete project using multiple modules. This will hopefully serve as a guide & tutorial for the usage of various modules available at Leobot Electronics (https://leobot.net).
First let us define the goal of the project:
I want to automate the watering of a plant in a container, gain information on how moist the soil is and what the temperature is where the plant is located.
Next we need to break this objective down into the actual components that will be required.
Now a quick overview on how to connect everything up.
The connections are fairly straight forward but I did notice one or two things worth pointing out.
At this point you will be left with only the data pins that needs to be connected to the Arduino’s IO pins. You can choose any pins but I chose to wire up the modules to the Arduino. For this project I arbitrarily chose the following pins:
This concludes the essentials of wiring up the project. Next, let us take a look at the source code.
First, we need to consider what code libraries are available from the Internet for us to use. Not only does it save development time, valuable examples to learn from often accompany the code libraries. In other cases, the usage is straightforward & simple enough to not need a library. It all depends on what module you are using.
In our project, the most ‘complicated’ module is the 7-segment display. Therefore, after scouring the internet, using the keywords from the Leobot Electronics site, I came across a library named “TM1637Display”. It does all the I2C communication implementation for you (more information on Arduino I2C is available at Arduino.cc).
The TM1637Display library can be downloaded at https://github.com/avishorp/TM1637
The next code consideration is to convert the reading from the Thermistor to something relatable. The Thermistor module will provide a reading between 0 and 1024 (integer) on the Arduino, but we want to know the Degrees Celcuis. Luckily this is only a simple math conversion to be done. This can be best explained with the actual code:
double Temp; Temp = log(10000.0 * ((1024.0 / RawADC - 1))); Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp )) * Temp ); Temp = Temp - 273.15; return Temp;
To keep this discussion simple, I will not explain the four constants involved in this function. We are simply converting the relative 0-1024 value to Kelvin, then converting the Kelvin value to Degrees Celsius.
Reading the soil moisture value is just as easy except I am not that interested in converting the reading into an absolute value. The reason for this has to do with how the soil moisture sensor operates. The sensor reads the dielectric constant of the material. The dielectric constant is the ratio (a relative value) of permittivity (the ability of a material to store an electric field) relative to the permittivity of a vacuum. Because this value does not have an easy-to-relate-to unit such as Degrees Celsius, and because the permittivity of water can vastly differ depending on what has been diluted in the water (such as salt), it makes more sense to use the direct relative value between 0-1024 for me at least.
The Relay module is also very simple to use as it only requires a digital signal to turn the relay on or off. Because the relay is wired up so that the pump/valve is connected to the Normal Open (NO) pins on the relay it means that we would need to send a 1 (or HIGH) to turn our pump on and a 0 (or LOW) to turn it off.
#include <Arduino.h> #include <TM1637Display.h>
// Module connection pins (Digital Pins)
#define CLK 2 //CLK Input Pin from 7Segment #define DIO 3 //DIO Input Pin from 7Segment #define TI A0 //Thermistor Analogue Input Pin #define MI A1 //Moisture Analogue Input Pin #define RO 4 //Relay Output Pin
#define RelayThreshold 500 //Moisture Level to reach before turning on the pump or valve. #define TEST_DELAY 500 // The amount of time (in milliseconds) between tests
TM1637Display display(CLK, DIO);
void setup() { pinMode(RO, OUTPUT); display.setBrightness(0x0f); }
void loop() { int readVal = analogRead(TI); // Get the Temperature double temp = Thermistor(readVal); // Convert to Celsius display.showNumberDec(temp, false); //Display on 7-Segment delay(TEST_DELAY); //Wait for some time readVal = analogRead(MI); //Read the moisture level int soil= readVal; //Save it in its own variable display.showNumberDec(soil, false); //Display on 7-segment delay(TEST_DELAY); //Wait for some time if(readVal>RelayThreshold) //Take action depending on the level of moisture { display.showNumberDec(999, false); //Display state digitalWrite(RO,1); //Turn on the Relay }else { display.showNumberDec(111, false); //Display state digitalWrite(RO,0); //Turn off the Relay } delay(TEST_DELAY); }
double Thermistor(int RawADC) { double Temp; Temp = log(10000.0 * ((1024.0 / RawADC - 1))); Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp )) * Temp ); Temp = Temp - 273.15; // convert from Kelvin to Celsius return Temp; }
18650 Lithium Battery Charging Module (5V Micro USB 1A)
R25.80
2-Chanel Logic Level Converter (LLC/IIC I2C) Bi-Directional Module 5V to 3.3V (DIY Soldering Needed)
4 Channel LLC I2C/IIC Logic Level Converter Bi-Directional Module 5V to 3.3V (DIY Soldering Needed)
R15.48
4 Channel Remote (315Mhz) + Receiver Module (315Mhz)
R58.05
4.0 Bluetooth Module (CC2540/CC2541 HM-10)
R189.00
5A Single-Phase Micro Current Transformer Module (AC Active Output, ZMCT103C)
R86.00
5mm RGB LED Module (KY-016 FZ0455)
R23.01
5V 1A Ultra-small Li-ion Lithium Battery Charger Module (DD08CRMB)
R90.72
Capacitive Touch Switch Button Self-Lock Module (11.5mm x 8mm)
R22.14
CH340G USB to Serial module (5V, 3.3V)
R51.60
DC 400W 15A Constant Current Power Supply & Step-Up Boost Converter (8.5V-50V to 10V-60V range)
R264.60
DC-DC 3.5V-30V To 4V-40V Step Up Power Supply Module LM2587 (80W Adjustable 5A Boost Converter Voltage Regulator)
R151.20
DS1302 RTC Real Time Clock Module
R34.40
DS1307 RTC Real Time Clock Module
DS3231 AT24C32 Precision Real Time Clock (RTC) Module
ESP01 Serial WiFi Power Regulator Adapter (ESP8266 compatible)
HC-SR04 Ultrasonic Distance Measuring Sensor Module
High Precision Laser Distance Range Finder Module (3.3V-5V, TTL)
R1769.04
IR Infrared Receiver Module
R43.00
LilyPad 328 Main Board (ATmega328P 16M)
R353.43
LM7805 5V Voltage Regulator Module
MAX3232 Mini RS232 to TTL Converter (3-5V)
R39.20
MICRO USB-B POWER SWITCH MODULE
R24.45
MOSFET Relay Module (0-24V Mosfet IRF520)
NE555 Adjustable Pulse Frequency Generator Module
Passive Buzzer Module
RFID Proximity Card Kit (RFID Reader/Writer Module + RFID Keyring Tag + RFID Card)
RS232 Serial Port Module (MAX3232CSE)
R89.00
Serial Micro-SD Card Module
R50.96
Serial SD Card Module
Serial Wifi Transceiver Module (Arduino)
Single Row 40 Pin Male 2.54 Breakable Pin Header Connector Strip
R4.06
SX1308 DC-DC Adjustable Step Up Power Booster Module (2-24V to 2-28V 1.2MHz 2A)
TCS3200 Color Recognition/Detector Module
R340.20
TLP281 4-Channel Opto-isolator
R68.80
Transparent Arduino Uno Enclosure Box
TTL to RS485 Converter Module (Arduino)
R29.80
TTP223 Capacitive Touch Sensor Module
R29.89
Universal LiPo Charger (4.2V/7.4V 2A)
USB - TTL SERIAL USART MODULE (PL2303/YP-01)