Author Topic: Arduino code  (Read 8695 times)

Mecini

  • Newbie
  • *
  • Posts: 1
Arduino code
« on: April 11, 2018, 06:30:59 PM »
Hello Piotr,

I am very happy to find your product. Now the goods is on its way - so I expect outstanding results, congratulation!

Can you or somebody experienced help with the code for Arduino if there will be 4-7 sensors + 4-7 pumps connected to relays. I plan to use Nano or Uno. I am absolutely beginner with Arduino...

The pump is: DC 12V 3M 240L/H Brushless Motor Submersible Aquarium Fish Tank Water Pump

I try to do myself the code for up to 8 pumps, need to help with connection - I mean if I will need also transistors and resistors if I want to use 8 channell relay...try to add Fritzing scheme as well later.

Code works not correctly, so I delete it.
« Last Edit: July 05, 2018, 01:01:40 PM by Mecini »

pinolec

  • Administrator
  • Jr. Member
  • *****
  • Posts: 99
Re: Arduino code
« Reply #1 on: May 04, 2018, 08:48:07 PM »
Hi Mecini,

Sorry for slow replay. Hope it's not too late  ;)

Your code looks good. Didn't try it but looks like it will work.
Is there any reason to use thresholdUp other than to turn off the pump?

Code: [Select]
if (sensorValue1 <= setMoistureValue)
    digitalWrite(2, HIGH);
else
    digitalWrite(2, LOW);

This way as soon as moisture level gets high enough the pump will turn off. It depends how you set up the system. If you bury sensor in soil at 5cm it will take some time till the water gets to the sensor.
As always it is a good idea to think what if the sensor gets disconnected by accident or someone takes it out of the soil. It's good to pull-down with 1M or so resistor to ground ADC inputs. So we can check if sensor reads 0 then we know that something is wrong.

Code: [Select]
if (sensorValue1 <= setMoistureValue && sensorValue1 > 0)
    digitalWrite(2, HIGH);
else
    digitalWrite(2, LOW);

Hope this will help a little.

Piotr