Hello. For some time working on a project with Arduino measuring moisture in the soil, which involves a humidity sensor placed on the pin (A0) and a Nokia5110 LCD that shows the percentage of zero to one hundred soil moisture. All want this project to also add a solenoid valve, scheduled to irrigate, put on digital pin = 4. My question is, what to write more code to open the solenoid it reaches 15% up to 100% percent, and stay closed from 100% to 15%. I’m beginner with programming help me. This is the code I have.
#include <LCD5110_Graph.h> // THE LIBRARY I AM USING IS THIS: LCD5110_Graph - Rinky-Dink Electronics
LCD5110 lcd(8,9,10,12,11);
extern unsigned char BigNumbers;
extern uint8_t ui;
int sensorPin = A0;
int sensorValue = 0;
int percent = 0;
String percentString =“0”;
int stringLength = 0;
void setup() {
lcd.InitLCD();
lcd.setFont(BigNumbers);
delay(1000);
}
void loop() {
lcd.clrScr();
lcd.drawBitmap(0, 0, ui, 84, 48);
sensorValue = analogRead(sensorPin);
percent = convertToPercent(sensorValue);
percentString = String(percent);
stringLength = percentString.length();
displayPercent(stringLength);
lcd.update();
delay(1000);
}
int convertToPercent(int value)
{
int percentValue = 0;
percentValue = map(value, 1023, 350, 0, 100);
if(percentValue>100)
percentValue = 100;
return percentValue;
}
void displayPercent(int length)
{
switch(length)
{
case 1: lcd.print(percentString,38,19); break;
case 2: lcd.print(percentString,24,19); break;
case 3: lcd.print(percentString,10,19); break;
default: lcd.print(percentString,0,19); break;
}
}