The Arduino Uno runs the code correctly when connected to the computer via USB. However, when I disconnect the USB and rely on the DC jack (9V, 700mA) for power, the code doesn't seem to execute. The Power LED remains on when connected to the DC jack. The "L" LED initially blinks (for about 10 seconds) and then turns off when powered by the DC jack. There is no flash from the TX/RX LEDs after disconnecting the USB. I have checked the DC jack connection, and all wires are secure. The Arduino board shows no visible damage or burnt components. The code works flawlessly when connected to the USB. I've tried resetting the board and uploading a simple "Blink" test, which works when connected to the USB but not with the DC jack. (I'm trying to build a automated plant watering system)
Here is the code:
** [code] **
int soilMositure = A0; //Sensor Pin
int relayPin = 7; //Relay Pin
So first you declare a global variable called soilMositure, and assign it the value A0.
Then you declare a local variable of exactly the same name (taking the global variable out of the picture entirely), and assign it the value of whatever analogRead() returns when faced with its uninitialized value.
Whatever it is you think that's going to do, it isn't going to do it.
Can you measure the voltage on the jack and the 5V referencing ground when connected both ways? I expect about 0 on the jack when it is not powered and the 5V to be about the same either way.
I didn't realize that i had used the same name for the global variable as for the local variable, but this specific naming issue isn't the cause of the problem with the code not running when disconnected from USB. (the code works fine and as intended when connected to the computer). However, I'll optimize the code. Thanks.
Unfortunately I don't have a multimeter to measure the voltage directly. However, I'm using a 9V, 700mA DC jack to power the Arduino Uno. When the DC jack is connected, all the power LEDs on the components light up, indicating that there is power.
I recommend you purchase one multimeter, they can be gotten for just a few dollars for a cheap one to over 1K$ for a high end one. The inexpensive one should do what you need for the present time. You can search on line for "multimeter".