Ibrahim Alzoubi

Fab Academy 2020 - "How to make almost anything"
Project Development

Using borad that I made for my final project using atmega 328

Firstly, before writing the code completely, I tested the code in parts, so I started writing the code for the humidity sensor with the pump

                
int motor =6; int sensor_pin =13; void setup() { pinMode(motor, OUTPUT); pinMode(sensor_pin, INPUT); } void loop() { if(digitalRead(13) == HIGH) { digitalWrite(6, HIGH); } else { digitalWrite(motor, LOW); } }



And now, to test the code, the entire humidity sensor with the pump with the LED strip

Where the principle of its work will be as follows. The humidity sensor will read the humidity level in the turbo. If the soil has reached a certain degree of humidity, the LED strip will start to light in the green balloon and at the same time the pump will start working to water the plant and when it reaches the required humidity level, the pump will stop working and the LED tape will start to switch Its color is like the color of the rainbow for a continuous 40 seconds from a moment the pump stops, then stops, and the process of measuring the moisture content and when it decreases it starts again and so




   
int nn =10;
int r,g,b;

int motor =6;
int sensor_pin =13;
#include
#ifdef __AVR__
#include
#endif #define PIN 11
#define NUMPIXELS 45
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 50

void setup() {

pinMode(motor, OUTPUT);
pinMode(sensor_pin, INPUT);

#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}

void loop() {
pixels.clear();
if(digitalRead(sensor_pin) == HIGH)
{
digitalWrite(motor, HIGH); //to let motor go on

for(int i=0; i {
pixels.setPixelColor(i, pixels.Color(0, 150, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL); // Pause before next pass through loop

if(digitalRead(sensor_pin) == LOW) // this part to interrupt the current for loop
return 0;
}
}
else
{
pixels.clear(); // Set all pixel colors to 'off'
digitalWrite(motor, LOW);
}
if(digitalRead(sensor_pin) == HIGH)
return 0;
pixels.clear();


// Coloring Part

for(int i=0; i pixels.setPixelColor(i, pixels.Color(255,0,0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(nn);

}

if(digitalRead(sensor_pin) == HIGH)
return 0;

for(int i=0; i pixels.setPixelColor(i, pixels.Color(255,255,0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(nn);
}

if(digitalRead(sensor_pin) == HIGH)
return 0;

for(int i=0; i pixels.setPixelColor(i, pixels.Color(0,255, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(nn);
}


if(digitalRead(sensor_pin) == HIGH)
return 0;

for(int i=0; i pixels.setPixelColor(i, pixels.Color(0,255,255));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(nn);
}

if(digitalRead(sensor_pin) == HIGH)
return 0;

for(int i=0; i pixels.setPixelColor(i, pixels.Color(0,0, 255));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(nn);
}

if(digitalRead(sensor_pin) == HIGH)
return 0;

for(int i=0; i pixels.setPixelColor(i, pixels.Color(255,0, 255));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(nn);
}

if(digitalRead(sensor_pin) == HIGH)
return 0;

for(int i=0; i pixels.setPixelColor(i, pixels.Color(255,255, 255));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(nn);
}

}






for download my code check here