Introduction: AI on Arduino (learning Irrigation Station)

Picture of AI on Arduino (learning Irrigation Station)

Artificial Intelligence of my Arduino consists so far of a single soft (programmed) neuron, which I can teach and leave my pot flowers' irrigation in the trust of.

In this instructable we are going to implement an artificial neuron into Arduino. I visited a whole class :) of neurology course, so I can explain it's functioning to you in detail.

A neuron is a unit making decision on the basis of synapse signal (input 0-1) and a weight (importance) of this signal. Say we have a neuron whose synapse is coming from a soil moisture sensor. Weight (excitation threshold) is the level of the signal by which a neuron knows that the soil is dry enough and needs watering.

But every flower has its own comfortable moisture level. That's where a backpropagation can be implemented. By manually watering the flower pot we instruct our neuron what should be the weight of the signal or excitation threshold.

Now you know almost everything a certified neurologist knows about your brains.

Step 1: ​How Can We Put This in Practice?

Picture of ​How Can We Put This in Practice?

Simple. We use quantum computing of the neuron coherent state linear superposition...

Just kidding! No, we use:

You just wire everything to Arduino's pins according to the diagram in this step.

I added 4 digit LED inicator to show current moisture level

  • pin SCLK = 7; // CLOCK
  • pin RCLK = 6; // LATCH
  • pin DIO = 5; // DATA and GND

*I modified a soil moisture sensor by replacing it's copper probes with 5cm long stainless steel rods to prevent them from decay due to galvanizing (see pic).

Step 2: Arduino Sketch

Picture of Arduino Sketch

Upload the sketch into your Uno and power it up.

To make the process more obvious I added a 7 segment 4 digit LED indicator.

It is indicating current moisture level in relative units (0-255, actually about 40-150). Learned threshold is indicated to COM port monitor of Arduino IDE.

Step 3: ​Learning

Picture of ​Learning

When you assembled the station you need to teach it the moisture level it should maintain. Learning is the most crucial for this project!

I upgraded my neuron so it can learn anytime. Anytime when the pot had been watered not by the neuron itself, it understands that that was teaching and remembers the moisture threshold.

You should find the exact soil moisture the flowers must be watered at. And simply add water. Teaching done!

If you need to re-teach the neuron, just pour some water into the pot again manually. I mean let the soil dry to the condition you (or you think your flower) desire and add water. In some cases you will have to disconnect the water tank if you want to teach it drier threshold.

It was one neuron with two synapses. Imagine our brain with 86 billion neurons each having 1000 to 10 000 synapses!


maxou74300 made it! (author)2017-12-11

Hello, your project is very cool but I don't understand how the Arduino know the value's reference of the humidity sensor. Is it when we feed the Arduino that it retains the first reference value? If it's not that, when is it?

We haven't plugged the LEDs into the picture yet.

Thank you

minimeccanica (author)2017-01-21

Cool! I'm running a similar project (early stage) but would like to use latching solenoid to limit wiring in my garden. Has anyone any idea where can I find a latching 1/2-3/4" plastic valve for a reasonable price?

Maybe something like this one:

Will it do?

paul_chany (author)2016-07-28

Very interesting project. In code the #define can be replaced with const, right? But can uint8_t be replaced with byte?

AlexanderTRU (author)paul_chany2016-07-28

As far as I understand you're right. I'm not a C++ artisan, so I can't judge which way is more memory/processor efficient. If you explained the difference I would appreciate it indeed. Thank you!

paul_chany (author)AlexanderTRU2016-07-29

I'm not a guru and just ask this because I can't find in the Arduino Reference command: uint8_t.

Does it mean that that in this project we want to store into EEPROM a data that occupies just one byte?

AlexanderTRU (author)paul_chany2016-07-31

Exactly. uint8_t

u - unsigned

int - integer

8 - number of bits

_t - means it's not macros, not function, not procedure, but type

coyayes (author)2016-07-25

Hi, I´ve built the project, however I don´t really understand the meaning of the sounds and color led.

Can you also explain a bit more, the modification you did the the moisture probe, mine has GND, VCC and SIGNAL however in the picture only two wires are shown,

AlexanderTRU (author)coyayes2016-07-25

The color led. In current version of the sketch color indicates the moisture level

- Bluish - moist

- Yellow and orange - average

- Red - dry

The more blue - the more moist the soil, the more red - the drier.


It makes sounds when pumping water - you can always disable it, I used it for debugging. Just place two slashes (//) in the beginning of line 134 ( playPump(pump); // pumping for seconds) or just delete the line.

It makes descending alarm sound when water tank is empty. You'd better leave it, it will remind you to fill the tank.

Moisture sensor was once like on picture here, but in my previous project it's probe was eaten out by galvanization within one week (see pic.2). What I did after. I replaced a probe having hieroglyphs with hand-made you can see in the article. It only has two wires which go to the small board with another 4 pins. They are VCC, GND, DO (digital), AO (analogue). I used analogue output along with VCC and GND.

coyayes (author)AlexanderTRU2016-07-29

thank you!!!

paul_chany (author)2016-07-29

Thanks for the upgraded neuron!

paul_chany (author)2016-07-28

Also, I do not understand this line:

if (soilValue > setValue) // current < eeprom, run the pump

If setValue is the value stored in eeprom, then the code

is not it supposed to be:

if (soilValue < setValue) // current < eeprom, run the pump


AlexanderTRU (author)paul_chany2016-07-28

You're right. The comment (after //) to this line is ambiguous. It should better be:

// if current (dryness) > eeprom value, run the pump

AlexanderTRU (author)paul_chany2016-07-28

Actually soilValue is a dryness parameter not moisture. The sensor is made that way. The more dry the soil the higher the value. That's why when it becomes more than set value we have to start the pump.

РудК (author)2016-07-27

Отлично. Думаю ардуино нано полойдет?

AlexanderTRU (author)РудК2016-07-27


Raphango (author)2016-07-25

Great! Congratulations!!

AlexanderTRU (author)Raphango2016-07-25

Thanks :)

tjoepar (author)2016-07-11

Great project - what software did you use for neuron emulation?

arvevans (author)tjoepar2016-07-24

He provided the software as downloadable code.


tjoepar (author)2016-07-11

Great project - what software did you use for neuron emulation?

arvevans (author)tjoepar2016-07-24

He provided the software as downloadable code.


afshimono (author)2016-07-12

Nice work! I am planning to implement something similar, using ESP8266 to log humidity in a raspi server, and also try to implement some level control for the tank to warn me when it is empty and need a refill. Congratulations!

AlexanderTRU (author)afshimono2016-07-13

It's also a great idea. I made something of a kind in my previous instructable Wireless Home cloud. ESP8266 with DHT sensor is sending parameters to mysql server on OpenWRT router. Then I display them on the graphs.

tjoepar (author)2016-07-11

Great project - what software did you use for neuron emulation?

AlexanderTRU (author)tjoepar2016-07-11

Thank you!

Arduino IDE utilizes C++. The sketch is enclosed with the instructable.

carlosdelfino (author)2016-07-11

Estou muito interessado na rede Neural Usada para dar inteligência ao seu sistema.

AlexanderTRU (author)2016-07-10

Thanks! I installed this one at the bottom of the tank:

gada888 (author)2016-07-10

Nice project,what is the model of water level sensor module?

gada888 (author)2016-07-10

Nice project,what is the model of water level sensor module?

About This Instructable




More by AlexanderTRU:Remote Controlled Floor LampDistant boiler temperature monitoringAI on Arduino (learning Irrigation Station)
Add instructable to: