Just getting started with my Arduino and trying to inspire an interest in my two boys. This is my first post here and I tried to search for a solution without success. My apologies if I missed it.
I have the Arduino UNO R3
I have written a simple sketch to power on the motor that comes in the Starter Kit using the MOSFET. I am using the photoresistor as a sensor and the sketch sends an analogWrite to the motor when the light source is interrupted.
Everything appears to be working properly but there is something odd about how the UNO uses the power sources.
If I run the sketch with the USB connected, everything works as expected.
If I run the sketch with the USB and 9 volt external connected, I can hear the motor engage for approximately 500ms, and then jump to a higher RPM. To be clear, it begins running at a similar speed to the USB only connection, then jumps to the higher RPM. Its not clear to me why. I thought that when you connected the external power supply, the UNO was supposed to use that and not use the USB.
If I unplug the USB, leaving only the external power supply, the two on board LED's begin blinking and the motor revs and stops in sync with the blinking. The reset button has no affect.
I have read a number of posts here and elsewhere about swapping resistors on board and applying a 10K resistor between the Rx and Tx pins. I tried the latter without any change.
Thanks for your assistance and sorry if this has been answered before. I couldnt find it.
Do you have a meter that will measure the battery voltage while all this happening.
If the battery voltage is varying even down to 8volts, then the 9V battery is not supplying enough current, it sounds like you are using the standard 9V transistor battery and I don't think it will do the job.
Tom.
I think you are using 9v battery which will not work.
you should make use of a 9v wall adapter or you should make a power supply for breadboard and the connect your arduino.
check this link if you wish to make power supply for breadboard.
Thanks for the replies. I am using the 9v wall adaptor that came with the starter kit and plugs into the arduino. I have a couple arduinos (bought a kit each for me and my two boys). I have tried again with one OT the other 9v adaptors and get the same result...
Goal: a robot that will run away when it detects something approaching.
Robot structure: LEGO frame
Robot sensor: Photo resistor
Motor: 9V motor switched with MOSFET
Thoughts: detect initial light and set this is safe level (no movement)
*/
int motorPin = 3; // Set pin number for motor output
int sensorPin = 1; // Set pin number for controller input
int flag = 0; // Set the starting flag - 0 is safe, 1 is in danger
int light = 0; // Define LDR variable
int safe = 0; // Define safe variable.
void setup()
{
pinMode(motorPin, OUTPUT);
pinMode(sensorPin, INPUT);
safe = analogRead(sensorPin) - 20; // Set initial "Safe" light level to a bit darker than current
}
void loop()
{
light = analogRead(sensorPin);
if (light < safe) {
flag = 1;
} else {
flag = 0;
}
if (flag == 1) {
analogWrite(motorPin, 150);
} else {
analogWrite(motorPin, 0);
}
}
Schematic - My apologies about the lack of proper symbols...
Thanks for the schematics, but, I am getting a eye strain trying to look at them. First they show up side ways, second, your hand writing is like a doctors. LOL .. If you could do those again, with better hand writing, and turn the upright, maybe I or someone else here could detect the problem.
I see one problem, your powering a 4.5V motor with a 9V. The Vin pin is connected to the input voltage before the regulator. With just the USB connected to the Arduino, the Vin pin is 5V. When you connect the 9V, the Vin pin will be 9V. This would not explain your problem but it may shorten the life of your motor.
9V batteries do not last long powering the Arduino with any load on it. Check the voltage of your Vin pin with the USB connected and disconnected. If your 9V is supplying less then 7 volts with the Arduino on, you need a new battery. It's possible when the motor starts, your battery voltage drops too low and the Arduino shuts down and restarts. It will start without the motor load, but shuts down again when the motor tries to start. I have a project that will drop a fresh 9V to 7V when it's under load, so you need to check the voltage when it's under load.
I suggest to power your motor with a separate power supply of the proper voltage. 9V batteries do not work well for motors. AA and AAA batteries have much more mAH to power a motor. You can power your Arduino with the 9V. You are using a MOSFET so it would be easy to do this. Both power supplies should share a common ground.