Dear all,
I am newcomer in arduino programmer, i have got little trouble with my code here
I have code arduino leonardo and soil moisture, i want to arduino take data from sensor soil with values 0 - 950.
values of sensor soil I set as setPoint1 = 300 and setPoint2 =800.
I want to when the arduino read values of sensor 300 increase until 800, arduino will send to coordinator the data like "324 On" will show on coordinator.
when the arduino read value sensor > 800, arduino will send to coordinator the data like "850 Off"
when the arduino read value sensor and get decrease from 850 until > setPoint1(300) the arduin will send data like "302 Off"
an the when the arduino read values sensor <= setPoint1 (300) the arduino will send data like "299 On"
simple like this
when arduino read sensor from setPoint1 until setPoint2, coordinator will receive "301 On, 323 On, 430 On, 750 On etc until 799 On"
when the arduino read values sensor from value sensor >setPoint2 got decrease until setPoint1, the coordinator will receive data "830 Off, 810 Off, 750 Off, 530 Off, and so on until 301 Off" when valuen sensor <300, coordinator will receive "299 On, 280 On and so on
after this looping from above
thanks for your pay attention
rozikien@gmail.com
my code like this
const int analogPin = A0; // pin that the sensor is attached to
int setPoint1=300;
int SetPoint2=800;
void setup() {
// initialize serial communications:
Serial.begin(115200);
Serial1.begin(115200);
}
void loop() {
int analogValue = analogRead(analogPin);
// if the analog value is high enough, turn on the LED:
if (analogValue < setPoint1){
Serial1.print(' ');
Serial1.print(analogValue);
Serial1.print(' ');
Serial1.print("On");
delay(1000);
}
if ((analogValue > setPoint1) && (analogValue <= setPoint2)) {
//Serial1.print('A');
Serial1.print(' ');
Serial1.print(analogValue);
Serial1.print(' ');
Serial1.print("On");
delay (1000);
}
else if (analogValue>setPoint1){
Serial1.print(' ');
Serial1.print(analogValue);
Serial1.print(' ');
Serial1.print("Off");
delay(1000);
}
}
}

