0

I have connected my arduino according to the schematics in the image, with a few additions.

The setup

  1. A DC motor (water pump) drawing power from Vin, going to ground via a transistor based in A0 analog output. Between the transistor and A0 is a 270 ohm resistor. In parallel to the motors poles is a diode, for protection.

  2. A 3,1" (4x20) LCD screen with an I^2C chip (draws 5V, A4 and A5 and GND)

  3. A Potentiometer directly on the I^2C chip LED pins (replacing the jumper) - for control of the light intensity. (Vin and middle pin of pot, gnd unconnected)

  4. A Potentiometer connected to A1, 3,3V and GND.

Code description: Using the Timer and the LiquidCrystal_I2C library, Once every other second the LCD is refreshed Once every day the water pump is started with an analogWrite(A0, HIGH) and it runs for 1-60 seconds based on the potentiometer setting.

The issue.

It seems the output of A0 does not deliver enough voltage to trigger the pump. This is a new error, before I got the screen, it ran the pump fine.

I suspect one of three things. 1: I have broken something in the arduino power regulator, and the voltage outputs on analog pins are lower than they should be (or their ability to supply current) -> Must get new arduino. 2: I have somehow saturated the ground pin or there is a connection issue. 3: The LCD display is drawing too much current. (Leading to either 2 or 1, but won't be fixed by getting a new arduino)

What have I already tried

I have tried, with the arduino connected via mains to short it between 3,3V and the transistor base, and then it runs. So the transistor is OK, the pump is OK. I have tried to map the output to another analog pin to display the value of this pin while the program is running, and it does display a value while the pump is supposed to be running, so it is doing something. I have used a multimeter to measure the pins, but I really don't know what "normal" is so I decided to stop fiddling around with that. I have also tried using other analog outputs (excepting 4 and 5, they are claimed by the lcd I^2C logics)

Can anyone of you please give me some pointers in the right direction, to help me to determine the error in question? What should I try?

Disclaimer, due to having the normal issues of life, love and the fact that a day only has 1440 minutes, I usually only have time to work on my pet projects during weekends...

If this question is not relevant or poorly written, please let me know, I'll try to clarify (or delete it).

enter image description here

  • Looks to me like your transistor is wired backwards... – Majenko Aug 28 '17 at 13:17
  • @majenko It is drawn backwards then. I am not entirely sure which side of the icon is e and c.... The circuit works. – Stian Yttervik Aug 28 '17 at 18:34
  • The arrow is on the emitter. It should be flipped left/right. – Majenko Aug 28 '17 at 18:34
2

The analog pins are for analog input not output. You can only use them for digital output.

Change

analogWrite(A0, HIGH)

to:

digitalWrite(A0, HIGH)

analogWrite() can only be used on PWM capable pins (the ones marked with ~). On any other pin it sets the pin HIGH if the analog value > 127 and LOW if the analog value <= 127.

Since you are writing HIGH, which is equal to 1, the output is LOW because 1 < 127.

  • Thanks for the clarification. I was under the illusion that digitalwrite only produced a pulse. I will test this at the earliest possibility and report back. – Stian Yttervik Aug 29 '17 at 15:54
  • No, digitalWrite sets a HIGH or LOW output. To send a pulse you have to use two digitalWrite calls - one to set it HIGH and then one to set it LOW. Where did you get the idea that digitalWrite creates a pulse? – Majenko Aug 29 '17 at 15:55
  • Confirmed as solution, thank you to both juraj and @Majenko. I learned something new and useful! (and let's not mention eff'ing obvious, slightly shameful about it ;-) – Stian Yttervik Sep 1 '17 at 14:35
  • Don't be. There's nothing wrong with being wrong or lacking some knowledge. Unless you're wrong sometimes how can you learn how to be right in the future? – Majenko Sep 1 '17 at 14:37
  • Shameful because such an error, I should have found while researching, not asking high skilled people to answer a low skill question. But thank you again, it is all the more appreciated. – Stian Yttervik Sep 1 '17 at 14:42
2

why analogWrite? analogWrite parameter values are 0 to 255 (or 1023) so analogWrite(pin, 1) is close to 0.

analogWrite is PWM on digital ports and doesn't work on analog ports analogWrite reference

use digitalWrite

  • I thought digitalwrite was only a single pulse... I will try that asap, if my mistake is this silly I am going to feel ashamed... Thanks for the info in any case! – Stian Yttervik Aug 28 '17 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.