Self Monitoring Plant

Engineer

Raimi b

Area of Interest

Bioengineering

School

Saint Anns High School

Grade

Incoming Softmore

THE FINAL PROJECT! (3rd milestone.)

Water pump

water pump

so the pump itself is actually just a dc motor that is connected to an impeller. Now this impeler’s blades are angled downward so that when the impeller whips around the centrifugal force pushes the water against theses

Tilted blades and off in a streamlined jet out of the end of the tube. As previously said this impeller is powered by a D.C motor and in order to control it with my arduino I needed the motor driver.

Motor driver

Motor driver

So a motor driver is basically a voltage amplifier and there are a few reasons it is necessary in order to control a motor, for my project the most important of which being that an arduino just doesn’t give enough power in order to control a 12 volt motor like the one in the pump. The motor driver is able to increase this voltage by having ports that can connect a battery pack to the circuit in addition to the 5v supplied by the arduino.  It is made up of 4 mosfets that I like to think of as switches, they are organized in a square around the motor and if two in a diagonal from each other are switched on by the code a current will flow between them and through the motor on a diagonal- therefore making the motor spin. This mosfet motor setup is called a h-bridge and my L298N motor driver is special it actually has two of them- but I only needed one for this project. There are three pins on the motor driver needed to control the pump, the enable A pin is used to enable the current to flow the motor driver so basically the speed of the motor.  The input 1 and 2 pins control the mosfets on for the left hand motor, (which is the side I am using.) All these pins connect to my arduino in order to be activated by my code.

CODE

code

There are two sections of new code I used for the water pump.  The first is a function called demo two it runs the motor up to full speed waits three seconds and then turns it off.  

The second piece of code is an if statement that checks if the moisture sensors has the moisture of the plant below 30% – which is the ideal water percentage there should be in the soil. and does demo two if it is.

There are two sections of new code I used for the water pump.  The first is a function called demo two it runs the motor up to full speed waits three seconds and then turns it off.  

The second piece of code is an if statement that checks if the moisture sensors has the moisture of the plant below 30% – which is the ideal water percentage there should be in the soil. and does demo two if it is. 

 

Hints:  I originally had the final piece of code as a while statement rather than an if.  This didn’t work because if it was below 30 the pump would keep pumping but never get to checking whether the water sensor had gone above 30.  The solution I have is turning the while to an if but you could also just put the sensor reading inside the while statement!

cool code click here

if (percent < 30) {

demoTwo();
delay(1000);
}

// lcd.print(“%”);

}

void demoTwo()
{
// this function will run the motors across the range of possible speeds
// note that maximum speed is determined by the motor itself and the operating voltage
// the PWM values sent by analogWrite() are fractions of the maximum speed possible
// by your hardware
// turn on motors
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(3000);
// decelerate from maximum speed to zero

// now turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
delay(100);

First and second Milestone

 My 1st  milestone was getting the sensors and the LCD display to  work independently witch turned out to be kind of homogeneous with my second mile stone to get the sensors displaying their information on the LCD so this is kind of san overview of both milestones.

LCD Display

-Lcd display: The lcd display works pretty much like a flat screen T.V. It has a ton of little lights or pixels that turn on and off in order to create the words.  I decided to use the LCD display so that I could show the data without having to open up the serial monitor on my computer!

Moisture sensor

-Moisture sensor:

The moisture sensor has two probes on it and they are each lined with copper plates now copper is conductive with water so when the probs are put into the moist soil an electrical circuit is completed and current is able to flow between the probes. The more the current is able to flow- the less resistance there is- and the more water there must be in the soil. By this logic if there is more resistance than there must be less moisture in the soil.  The sensor is able to take this resistance and convert it into an integer to represent the amount of water – or lack there of- in the soil! This number is on a scale from about 0- no moisture to 1023- a lot of moisture. The arduino takes that number and maps onto a scale of 0 to 100 – basically making a percentage for us to look at- that percentage is then displayed on the lcd display screen. 

humidity sensor

-Humidity sensor     

The humidity sensor works in a very similar way to the moisture sensor! Inside of it one will find two plates with a moisture substrate pad between them. The plates are electrodes meaning that they can conduct electricity through/with the moisture. As the humidity rises the moisture substate accumulates more moisture and the current is able to flow. the resistance this current faces is taken in by an IC pin witch is able to translate that hindrance into a number that the microcontroller is able to read. The arduino code puts that number into a float and displays on the LCD display. 

What I learned:  When I first started putting together the project I throw every piece onto the breadboard and arduino upload the code, crossed my fingers and just hoped that it would work。 Evidently that jumbled mess of wires and sensors didn’t do a thing and I was essentially at the same place I had  been at at the beginning but now just with a big mess in front of me. At this point I took out all the sensors and other unneeded wires and I restarted but this time only with the lcd screen I went through very carefully and connected each wire exactly the way my schematic told me to. Finally after doing this more careful method my screen worked. I did the same method with the other sensors and eventually they all worked. I learned that being precise in such a way  from the beginning not only saves time but also confusion and stress. I was also able to implement this lessons when writing my code as I took one sensor at a time and put their information into the combined document individually and into exactly the write place.

 

Hints:

So when the sensors update on the serial monitor they state their readings on the one line below. However on the LCD display this isn’t possible and when the readings update all the words on the screen jumble and become unreadable. My solution was to create a loop that has  the screen clears every time between checks so that the updates are re-written in the same spot each time.

Click for code

//int resval = 0; // holds the value
//int respin = A5; // sensor pin used

int sensorPin = A0;
int sensorValue = 0;
int percent = 0;
/*
LiquidCrystal Library – Hello World

Demonstrates the use a 16×2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.

This sketch prints “Hello World!” to the LCD
and shows the time.

The circuit:
LCD RS pin to digital pin 12
LCD Enable pin to digital pin 11
LCD D4 pin to digital pin 5
LCD D5 pin to digital pin 4
LCD D6 pin to digital pin 3
LCD D7 pin to digital pin 2
LCD R/W pin to ground
LCD VSS pin to ground
LCD VCC pin to 5V
10K resistor:
ends to +5V and ground
wiper to LCD VO pin (pin 3)

Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
modified 7 Nov 2016
by Arturo Guadalupi

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld

*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
// REQUIRES the following Arduino libraries:
// – DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// – Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
#include “DHT.h”
#define DHTPIN 13 // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 —
// Pin 15 can work but DHT must be disconnected during program upload.
// Uncomment whatever type you’re using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);

// start the serial console

dht.begin();
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
// lcd.print(“hello!”);
}
void loop() {

// resval = analogRead(respin); //Read data from analog pin and store it to resval variable
//
// if (resval <= 100) {
// lcd.print(“Water Level: Empty”);
// }
// else if (resval > 100 && resval <= 300) {
// lcd.print(“Water Level: Low”);
// }
// else if (resval > 300 && resval <= 330) {
// lcd.print(“Water Level: Medium”);
// }
// else if (resval > 330) {
// lcd.print(“Water Level: High”);
// }
delay(1000);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
// lcd.setCursor(0, 1);
// // print the number of seconds since reset:
// lcd.print(millis() / 1000);
// Wait a few seconds between measurements.
delay(5000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
lcd.print(F(“Failed to read from DHT sensor!”));
return;
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
// lcd.print(“hello!”);
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);

lcd.print(F(” Humidity:”));
lcd.print(h);

sensorValue = analogRead(sensorPin);
percent = convertToPercent(sensorValue);
printValuesToSerial();
delay(1000);
}

int convertToPercent(int value)
{
int percentValue = 0;
percentValue = map(value, 1023, 465, 0, 100);
return percentValue;
}

void printValuesToSerial()
{
// lcd.print(“\n\nAnalog Value: “);
// lcd.print(sensorValue);
lcd.print(” wp:”);
lcd.print(percent);
delay(3000);
lcd.clear();
lcd.print(” wp:”);
lcd.print(percent);

// lcd.print(“%”);

}

Starter Project

My starter project was the T.V.B.gone- a really cool futuristic  gadget that could turn off any tv’s in the surrounding area. Now I can annoy my family and enjoy my newly learned knowledge on how to solder, desolder, and all the electrical components on the kit.

DOES HE EVEN KNOW HOW IT WORKS?!!!!!

Demonstration

how the TV.B.Gone works

All TVs and tv remotes communicate through infrared light. Now this pretty crazy,infrared light is all around us the sun emits tons of it how can a remote interact with the tv using IR if there is already all this IR around it in the first place? that seems like trying to hit a dart board with a dart made out of air. Well here’s the answer: the tv has sensors on it now these sensors have been programmed to ignore all surrounding ir except for some important exceptions. You see when engineers are as creating the tv and remote they code in certain IR sequences that the remote can  shine at the TVs sensors the TV picks up these specific codes and understands what function to do. So for example if you want to put up the volume then when you press the volume button on the remote is really shining the infrared code for volume at the TVs sensor. The T.v b.gone doesn’t have ir codes for every button on a remote but has the on off codes for a ton of televisions! However it still is unclear how the circuit gives power to these pulsing it led. So let investigate first of all there is micro controller it is basically a small computer that has all the code programmed in it and that code has the pulse times for the leds in it! Next there are 5 transistors 4 of them act as switches for  the led that turn them on and off in time with the micro controller’s code. There is one more transistor that communicates with the button and allows any charge enter the transistor led system. The ceramic oscillator acts as a clock and is used to keep the time of the chow fast the current is moving.it is used to sync up the rest of the board with the microcontrollers speed.Finally The 2 Capacitors are energy storers. Meaning that if any other particles such as sound were in the circuit that energy would be taken in by them. And with all those parts working harmoniously the TV.B.Gone is able to operate. 

Things I struggled with and hints:

 

The major lesson I learned during this project was the importance of being diligent. Solder is extremely difficult to undue once it’s solidified around a component and desoldering is made even more difficult with the TV.B.Gone because the wholes are so small! In my haste I didn’t read the instructions carefully enough and ended up soldering the ceramic oscillator into the wrong three holes. The component was extremely hard to get out and once I did all of the legs fell off.  I had to get another oscillator from another kit! The holes were still full of solder because they were so small and the whole mess was inconvenient pain and something that could have been easily avoidable if I had been just a little bit more cautious.

Start typing and press Enter to search