digitalRead() works when powered from 5v USB but not from 12v barrel jack

Hi,

I am working on reading the voltage from a car backup sensor system. The backup control box sends voltages between about 1-4.2v depending on whether the sonic sensor detects an object.

I am reading this voltage with digitalRead() and using the tone() command with a speaker connected to my Arduino Uno to create a beep when the sensor detects an object.

All of this works perfectly when I am powering the Arduino from my computer's 5v usb cable but as soon as I use a 12v power source (from the 12v DC cigarette lighter of the car) the digitalRead() always returns HIGH.

What do I need to do to get the digital read to work the same way as when I power the Arduino through the 5v USB port?

Thanks for your time.

Does the sensor give variable voltage or switch between HIGH and LOW?

To read a variable voltage you need to connect your input to an analogue input and do an analogueRead().

digitalRead() will only give a HIGH or LOW logic level.

Weedpharma

Hi, Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks... Tom... :)

@weedpharma,

I also confirmed these values by doing an analogRead() of the input voltage. However when I switch to the 12v power the analogRead() always reads ~4.9, event when the sensor should be reading a negative value. I know this because I can simply unplug the 12v power with the usb plugged in and I immediately see the analogRead() drop to about 1 volt.

Please give us a picture showing clearly how you have connected the power to the Arduino.

If you load “blink” into the Arduino, does it work on the 12v?

What voltage do you have on the 5v pin when 12v is supplied to the Arduino?

Weedpharma

@WeedPharma

Looks like blink works when 12v is supplied. The voltage of the sensor varies between about 1.0 and 4.9.

I’ve attached an image of how I’ve connected the board. You should be able to see voltage is going into A0 and the speaker out is on the right connected to ground and pin 12.

Do not cross-post. Threads merged.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you measure the voltage between the vehicle chassis and the arduino gnd, in both cases?

Thanks... Tom.... :)

I've attached an image of how I've connected the board.

No you have attached an image of a mass of wires and an Arduino. There is no way to see where anything is connected. Now please draw a diagram if you want help. What you are describing simply will not happen if everything is wired correctly so we have to find out what mistakes you have made. Rather than guess, if we know how it is wired we can spot your errors.

LucasBest: The backup control box sends voltages between about 1-4.2v depending on... I am reading this voltage with digitalRead()

and using the tone() command with a speaker connected to my Arduino Uno...

All of this works perfectly when I am powering the Arduino from my computer's 5v usb cable but as soon as I use a 12v power source (from the 12v DC cigarette lighter of the car) the digitalRead() always returns HIGH.

What do I need to do to get the digital read to work the same way as when I power the Arduino through the 5v USB port?

Thanks for your time.

1) You can't read an ANALOGUE voltage with DIGITALread.

2) You can't connect a common (4- or 8ohm) speaker directly to an Arduino pin. That's almost a dead short to ground.

3) 12volt on the DC socket I hope. DigitalRead returns HIGH if the input pin is higher than 0.6*VCC and LOW if below 0.3*VCC. VCC might be 4.7volt on USB and 5.2volt on external 12volt.

4) Post a proper diagram. Leo..