Motor keeps running |
您所在的位置:网站首页 › kxd摩托车中国官网 › Motor keeps running |
Thank you all so much for prompt replies, really do appreciate all the input, some of you have stated that the "Fritzing schematic is rather unprofessional and difficult to look", I do accept your input, this short tutorial was design for people with no background in electronics and is picture driven. A student who suffer from a condition call "Dyslexia" find pictures and clear lines easy to follow. any example of how I should merge this type of teaching into Industry standard would be very much appreciated. I am not an electronic student as such; I can not construct a PCB board yet or design an electronic circuit. any tutorial on beginner would also be well come other comments such as "code is obfuscated" am afraid I would disagree with this point all of my code are well commented and this what I believe the industry also requires. here is my sketch code: //******************************************************* // Autor: Waheed Rafiq Research Student Birmingham City University // Date Written: 27/06/2016 // Project: iPot (c) (TM) 2001 , Plant Pot that water itself , // able to tell user Humidity within the pot dome. // Version : 1.1 // All CopyRight Reserve (c) 1988 //Copyright (C) 2007 Free Software Foundation, Inc. //Everyone is permitted to copy and distribute verbatim copies of this //license document, Modification is allowed please do credit the autor. // Happy Coding , Keep the Peace , Love Technology // www.waheedrafiq.net #include "dht.h" #include "U8glib.h" // for the OLED screen //************************************************************** U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); //************************************************************** #define DHTPIN 2 // what pin we're connected to digital pin //#define DHTTYPE DHT22 // DHT 22 (AM2302 #define DHTTYPE DHT11 // DHT 11 dht DHT; #define DHT11_PIN 2 // Initialize DHT sensor for normal 16mhz Arduino //DHT dht(DHTPIN, DHTTYPE); //Variables int chk; float hum; // Stores humidity value float temp; // Stores temperature value const int soilSensorPin=0; // intialise soil A0 pin int sensorValue = analogRead(soilSensorPin); //2-Way motor control int motorPin =9; // Pin that motor is connected to int x=0; void draw(void) { // graphic commands to redraw the complete screen should be placed here u8g.setFont(u8g_font_unifont); //************************************************************ // Soil sensor / Humminity sensor data //*********************************************************** // Read data and store it to variables hum and temp int chk = DHT.read11(DHT11_PIN); // hum= dht.readHumidity(); // temp= dht.readTemperature(); hum = (DHT.humidity); temp =(DHT.temperature); // Serial.println("Humidity: "); // Serial.println(DHT.humidity,1); // Serial.println("Temparature: "); // Serial.println(DHT.temperature,1); //map the value to a percentage sensorValue = map(soilSensorPin, 485, 1023, 100, 0); delay(1000); // delay for one second // Print temp and humidity values to serial monitor // print out the soil water percentage you calculated: Serial.println("Soil M : ");// output to serial monitor for testing purpose. Serial.println(sensorValue); delay(1000);// wait for one second... //******************************************** // OLED Soil screen OUTPUT //******************************************** u8g.drawStr( 0, 49, "Soil M: "); // leave this at postion 0 , 30 u8g.setPrintPos(78,49); // move soil postion back if you want to 0,50 u8g.print(sensorValue); delay(5000);// delay for 5 second to allow OLED screen to refresh Serial.print("Humidity: ");// output to serial monitor for testing purpose. Serial.println(hum); delay(1000); // delay for one second ... //******************************************** // OLED Humidity screen //******************************************** u8g.drawStr( 0, 28, "Humidity:"); // leave this at postion 0 , 30 u8g.setPrintPos(78,26); // move soil postion back if you want to 0,50 u8g.print(hum); delay(3000); //********************************************* // NO space on OLED Screen code not included //********************************************* Serial.print(" %, Temp: ");// output to serial monitor for testing purpose. Serial.println(temp); Serial.println(" Celsius "); delay(2000); // if soilSensorPin value is less than 35 in soil moist then // trigger the water pump keep checking until above 35 in soil moist. if(! isnan(sensorValue)) // this code deals with nan values { sensorValue = sensorValue +1; //soilSensorPin = soilSensorPin +1; Serial.println("New value soil: "); Serial.print(sensorValue); } if(sensorValue > 35 ) { Serial.println(" Soil dry : "); Serial.print(sensorValue); //******************************************** // OLED OUTPUT "soil dry" + value //******************************************** u8g.drawStr( 0, 46, " Soil dry: "); // leave this at postion 0 , 30 u8g.setPrintPos(78,49); // move soil postion back if you want to 0,50 u8g.print(sensorValue); digitalWrite(motorPin, HIGH); // turn motor on delay(6000); // delay 5 seconds Serial.println("motor off"); // test purpose only digitalWrite(motorPin,LOW); // turn motor off delay(10000); // delay 10 second before turning to the top of the code. } else if(sensorValue < 35) { Serial.println("Soil not dry"); Serial.println("Soil M: "); Serial.print(sensorValue); Serial.println(""); // do nothing to OLED screen } } void setup() { Serial.begin(9600); // dht.begin(); // initialize the digital pins as an output: pinMode(motorPin, OUTPUT); // initialize motor mode //************************************************************** // OLED Code below //************************************************************** // flip screen, if required // u8g.setRot180(); // set SPI backup if required //u8g.setHardwareBackup(u8g_backup_avr_spi); // assign default color value if ( u8g.getMode() == U8G_MODE_R3G3B2 ) { u8g.setColorIndex(255); // white } else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) { u8g.setColorIndex(3); // max intensity } else if ( u8g.getMode() == U8G_MODE_BW ) { u8g.setColorIndex(1); // pixel on } else if ( u8g.getMode() == U8G_MODE_HICOLOR ) { u8g.setHiColorByRGB(255,255,255); } pinMode(8, OUTPUT); } // General Loop continue to check void loop() { //************************************************ // OLED code below //************************************************ u8g.firstPage(); do { draw(); } while( u8g.nextPage() ); }// end of loopanother comment about NPN transistor it is used in the project to control the "On / Off " device As well as being used as a semiconductor switch to turn load currents “ON” or “OFF” by controlling the Base signal to the transistor in ether its saturation or cut-off regions, Bipolar NPN Transistors can also be used in its active region to produce a circuit which will amplify any small AC signal applied to its Base ... found on here I believe the diode is there to ensure the current flow is going in the correct direction Thank you all so much for your replies and comments all of which have been noted. |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |