But even if I use Arduino IDE, I get the same error message.
sketch_jul25b.cpp: In function ‘void setup()’:
sketch_jul25b.cpp:14:14: error: no match for ‘operator!’ in ‘!Serial’
sketch_jul25b.cpp:14:14: note: candidate is: operator!(bool)
When I comment
// while (! Serial);
line like this it compiles fine.
But if I enter a value between 0 and 255 motor does not turn. Instead it makes a whispering sound.
I updated IDE to the latest version 1.0.5. This time program compiles fine but still motor does not turn. I use a 2N2222A transistor instead of 2N2222.
As written the program needs something to be entered into the serial monitor in order for the motor to be turned on, though heaven knows why. Try this simplified program.
You should be driving your motor from an external power supply, not the Arduino (you may damage the Arduino if you don't).
Also if your transistor is not saturating you should try a power MOS FET or high gain power transistor.
If you place a HIGH on o/p D3, what is the voltage from the collector to the emitter of the 2N2222?
I changed my circuit like this. I used a 9 volts DC wall adapter to power the DC motor. I changed the resistor value to 1K and put a 1uF capacitor between VCC and transistor's collector.
LarryD:
If you place a HIGH on o/p D3, what is the voltage from the collector to the emitter of the 2N2222?
LarryD:
What do you measure on the Arduino pin 3 ?
I measure 4.86 volts.
But when I plug DC wall adapter I measure voltage about 8 volts between VCC and ground. If I plug Arduino to the USB cable it drops to 2,51 volts. Isn't it odd?
Here is the actual circuit on the breadboard.
LarryD:
IRF540 MOS FET
I bought an IRF540 MOSFET. Which changes should I need in the circuit to drive the DC motor using MOSFET.
I think for the first motion it needs a lot of power. So if I enter a value below 150 still it doesn't turn. But if I enter 150 and when motors starts to move than it is possible to slow down the motor by entering smaller values.