Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 37 - RoboGenius Pro C7
P. 37

    STEP - 19   Click on the Start Simulation button to test the Smart Irrigation System.

                     Text based programming:

                      STEP - 20   Click on the EDIT MODE dropdown button and select Text option. The code you
                                  created will be displayed here.

                     Here’s an explanation of the code you created:
                        int soil_moisture = 0: Declares a variable to store the soil moisture sensor value, initially set
                        to 0.

                        void setup(): A built-in function that runs once at the start to initialise the pin modes.
                        pinMode(A0, INPUT): Sets pin A0 as input for reading the soil moisture sensor value.

                        Serial.begin(9600): Starts serial communication at 9600 baud rate for debugging.
                        pinMode(8, OUTPUT), pinMode(7, OUTPUT), pinMode(6, OUTPUT): Sets pins 8, 7 and 6 as
                        outputs to control the pump and LEDs.

                        void loop(): Continuously runs after setup() to read sensor data and control components.

                        soil_moisture = analogRead(A0): Reads the soil moisture sensor value from pin A0.
                        Serial.println(soil_moisture): Prints the moisture level to the serial monitor for monitoring.

                        if (soil_moisture < 100): If the soil is dry, the water pump and red LED are turned on.
                        Ÿ  digitalWrite(8, HIGH): Turns ON the water pump.

                                                                         Getting Started with Arduino in Tinkercad
                                                                                                                        35

| 32 33 34 35 36 37 38 39 40 41 42 |