Here is the MATLAB code for the code you gave:
% Define pins
SENSOR_PIN = 'A0';
Motor_PIN = 'D7';
% Create arduino object
a = arduino();
% Initialize LCD
lcd = addon(a, 'ExampleAddon/LiquidCrystal', 'D13', 'D12', 'D11', 'D10', 'D9', 'D8');
begin(lcd, 20, 4);
setCursor(lcd, 0, 0);
print(lcd, " THE BRIGHT LIGHT ");
setCursor(lcd, 0, 1);
print(lcd, "SMART PLANT WATERING ");
pause(2.5);
% Main loop
while true
% Read sensor value
Sensor_Val = readVoltage(a, SENSOR_PIN);
% Map sensor value to moisture level
Moisture = (Sensor_Val/5)*100;
% Display moisture level
setCursor(lcd, 0, 2);
print(lcd, "MOISTER: " + Moisture + "% ");
% Control motor based on moisture level
if Moisture < 30
setCursor(lcd, 0, 3);
print(lcd, "MOTOR: ON ");
writeDigitalPin(a, Motor_PIN, 1);
else
setCursor(lcd, 0, 3);
print(lcd, "MOTOR: OFF ");
writeDigitalPin(a, Motor_PIN, 0);
end
% Delay before next reading
pause(0.1);
end
You need to have the MATLAB's Arduino support package and you need to have to necessary add-ons to use this.
