details
Project : This project shows how to monitor the condition of plant using temperature sensor, illumination sensor, and soil sensor and water the plant using water pump.
Components:
- Arduino Pro Mini
- Ethernet Shield R3
- Breadboard
- CdS Sensor (light sensor)
- Temperature Sensor (LM61)
- Servomotor
- Resistor(220Ω)
- Nail x2
- Pump nozzle
Step1 : Read content of SD card
SDpin Specification to use Ethernet Shield:
code:
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include <SPI.h> #include <SD.h> Sd2Card card; SdVolume volume; SdFile root; const int chipSelect = 4; // set to pin 4 if using Ethernet void setup() { Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.print(“\nInitializing SD card…”); pinMode(4, OUTPUT); // set to pin 4 if using Ethernet if (!card.init(SPI_HALF_SPEED, chipSelect)) { Serial.println(“initialization failed. Things to check:”); Serial.println(“* is a card is inserted?”); Serial.println(“* Is your wiring correct?”); Serial.println(“* did you change the chipSelect pin to match your shield or module?”); return; } else { Serial.println(“Wiring is correct and a card is present.”); } Serial.print(“\nCard type: “); switch (card.type()) { case SD_CARD_TYPE_SD1: Serial.println(“SD1”); break; case SD_CARD_TYPE_SD2: Serial.println(“SD2”); break; case SD_CARD_TYPE_SDHC: Serial.println(“SDHC”); break; default: Serial.println(“Unknown”); } if (!volume.init(card)) { Serial.println(“Could not find FAT16/FAT32 partition.\nMake sure you’ve formatted the card”); return; } uint32_t volumesize; Serial.print(“\nVolume type is FAT”); Serial.println(volume.fatType(), DEC); Serial.println(); volumesize = volume.blocksPerCluster(); // clusters are collections of blocks volumesize *= volume.clusterCount(); // we’ll have a lot of clusters volumesize *= 512; // SD card blocks are always 512 bytes Serial.print(“Volume size (bytes): “); Serial.println(volumesize); Serial.print(“Volume size (Kbytes): “); volumesize /= 1024; Serial.println(volumesize); Serial.print(“Volume size (Mbytes): “); volumesize /= 1024; Serial.println(volumesize); Serial.println(“\nFiles found on the card (name, date and size in bytes): “); root.openRoot(volume); root.ls(LS_R | LS_DATE | LS_SIZE); } void loop( void ) {} |
Result:
Step2: 온도데이터와 조도센서 데이터를 기록해 보자
hardware2 :
code2 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include <SPI.h> #include <SD.h> const int chipSelect = 4; void setup() { Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.print(“Initializing SD card…”); pinMode(4, OUTPUT); if (!SD.begin(chipSelect)) { Serial.println(“Card failed, or not present”); return; } Serial.println(“card initialized.”); } void loop() { String dataString = “”; for (int analogPin = 0; analogPin < 2; analogPin++) { int sensor = analogRead(analogPin); if (analogPin == 0) { dataString += String(sensor); dataString += “,”; } else if(analogPin == 1){ dataString += String(modTemp(sensor)); } } File dataFile = SD.open(“DATALOG.TXT”, FILE_WRITE); // file name if (dataFile) { // confirms the SD card file was successfully opened (creates a new one if not) dataFile.println(dataString); // writes the contents from dataString dataFile.close(); //closes the file after writing data Serial.println(dataString); } else { Serial.println(“error opening datalog.txt”); } } // convert the temperature sensor data to Celsius float modTemp(int analog_val){ float tv = map(analog_val,0,1023,0,5000); // convert the sensor data to voltage float temp = map(tv,300,1600,–30,100) ; return temp; } |
result2:
Step3: Observe the condition of the flowerpot through soil sensor.
hardware3:
Arrangement:
Result3:
Step4: Make water supply system
hardware4:
code4:
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #include <SPI.h> #include <SD.h> #include <Servo.h> const int chipSelect = 4; Servo myservo; int pos = 0; int sensorValue = 0; // variable to store the value coming from the sensor int sensorPin = A0; void setup() { myservo.attach( 9 ); Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.print(“Initializing SD card…”); pinMode(4, OUTPUT); if (!SD.begin(chipSelect)) { Serial.println(“Card failed, or not present”); return; } Serial.println(“card initialized.”); } void loop() { String dataString = “”; for (int analogPin = 0; analogPin < 3; analogPin++) { int sensor = analogRead(analogPin); if (analogPin == 0) { //光センサの値 dataString += “Light:”; dataString += String(sensor); dataString += “,Temp:”; } else if(analogPin == 1){ //温度センサの値 dataString += String(modTemp(sensor)); dataString += “,Ground:”; } else if(analogPin == 2){ //soil sensor value sensorValue = analogRead(sensorPin); dataString += String(sensorValue); // pump 5 times whenever the soul resistance value is above 700 if(sensorValue > 700){ for(int u=0;u<5;u++){ pos = 180; myservo.write( pos ); delay(1500); pos = 0; myservo.write( pos ); delay(1500); pos = 180; myservo.write( pos ); } } } } File dataFile = SD.open(“datalog.txt”, FILE_WRITE); if (dataFile) { dataFile.println(dataString); dataFile.close(); Serial.println(dataString); } else { Serial.println(“error opening datalog.txt”); } } // Change the temperature sensor value to Celsius float modTemp(int analog_val){ float tv = map(analog_val,0,1023,0,5000); // Change the sensor value to voltage float temp = map(tv,300,1600,–30,100) ; return temp; } |
Result movie: http://www.deviceplus.com/how-tos/arduino-guide/an-arduino-plant-monitoring-watering-device/
URL: http://www.deviceplus.com/how-tos/arduino-guide/an-arduino-plant-monitoring-watering-device/
COMMENTS