A0 drawing current because of code

the problem:
why does this code make pin A0 on the Arduino NANO and UNO draw alot of current?
(20mA)

I am building an RC car with Arduino NANO, nrf 24 lo1 module, pcf8575 io expander, and Adafruit OLED (128x64). I am already done with the core functions of the program. witch is the driving and the steering. and I have added a few extra functions such as cooling for the motor, cooling for the H-bridge, adresible LEDs for headlights with built-in blinkers and reverse light, automatic mode for the headlights with a photodiode, and a lightbar with 2 brightness modes. all of this code seems to work perfectly. but now I want to read the 12Vlion battery voltage with a voltage divider on pin A0. this is the code that I made for measuring the 12.6V battery

( </> )
float Voltage;

float percentage;

void readBatVoltage()

{

int VoltageValue = analogRead(A0);

// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 14.582 V):

Voltage = VoltageValue * (14.582 / 1023.0);

//BatVoltage = Voltage;

}

void readBatProcentage()

{

percentage = (Voltage - 6) / 6.6 * 100;

}

void setup() {

Serial.begin(9600);

pinMode(A0, INPUT);

}

void loop() {

readBatVoltage();

readBatProcentage();

delay(100);

Serial.print(Voltage);

Serial.println("V");

Serial.print(percentage);

Serial.println("%");

delay(100);

}
( </> )

(I've tested this code and it seems to works perfectly) , but when I tried to add it to the code of my RC car it reads 0.04V, this is because A0 drawing a lot of current. (20mA at 1V on the ADC) this problem doesn't actually seem to have anything to do with the code above, because when I removed the code I measured that pin A0 was still drawing a lot of current. and because of this pulling the voltage divider to 0V.

  1. the ADC is not broken because when i upload the bear voltage reading sketch it seems to work fine again without any problems.

  2. if I upload the code to an Arduino UNO it seems to have the same issue.

  3. the problem is not in the wiring of the car because I'm still having the problem with the Arduino completely disconnected from the car and all of its modules. (for this test I fed the ADC 1V with a bench power supply and it drew (20mA again)

problem code:

( **</>** )
/*

  Module // Arduino NANO   

    GND    ->   GND

    Vcc    ->   3.3V

    CE     ->   D9

    CSN    ->   D10

    CLK    ->   D13

    MOSI   ->   D11

    MISO   ->   D12  

 */

#include <SPI.h>

#include <Wire.h>

#include <nRF24L01.h>             

#include <RF24.h>

#include <FastLED.h>

#include "PCF8575.h"

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

/*//////////////////////////////////////////////////////*/

//-------------------------Arduino ADC

#define VoltageSense  A0

#define currentSense  A1

#define photoSense    A2

#define motorTemp     A3

//i²c   sda           A4

//i²c   scl           A5

#define resistorTemp  A6

#define H_bridgeTemp  A7

//-------------------------Digital I/O

#define red-LED       2

#define lightBar      3

#define H_motor_1     5

#define H_motor_2     6

//-------------------------I/O expander

#define H_bridgeFAN   out1

#define motorFAN      out2

#define resistorFAN   out3

#define horn          out6

#define highVoltage   out7

#define green-LED     out11

#define H_steering_1  out15

#define H_steering_2  out16

//io xpander remap

const int out0  = P0;

const int out1  = P1;

const int out2  = P2;

const int out3  = P3;

const int out4  = P4;

const int out5  = P5;

const int out6  = P6;

const int out7  = P7;

//const int out8  = X;

//const int out9  = X;

//const int out10 = X;

const int out11 = P9;

const int out12 = P10;

const int out13 = P11;

const int out14 = P12;

const int out15 = P13;

const int out16 = P14;

const int out17 = P15;

//i2c

PCF8575 pcf8575(0x20);

//Fast_LED 

#define NUM_LEDS 14

#define DATA_PIN 4

CRGB leds[NUM_LEDS];

//millis-timer

unsigned long previousTime = 0;

int blinkerSpeed = 20;

/*Create a unique pipe out. The receiver has to 

  wear the same unique code*/  

const uint64_t pipeIn = 0xE8E8F0F0E1LL; //IMPORTANT: The same as in the receiver!!!

/*//////////////////////////////////////////////////////*/

/*Create the data struct we will send

  The sizeof this struct should not exceed 32 bytes

  This gives us up to 32 8 bits channals */

RF24 radio(9, 10); // select  CSN and CE  pins

struct MyData {

  byte steering;

  byte forward; 

  byte reverse;

  byte brake;   

  byte lighting; 

  byte current;   

  byte voltage;

  byte horn; 

  byte lock;   

};

MyData data;

/*//////////////////////////////////////////////////////*/

//This function will only set the value to X if the connection is lost...

void resetData() 

{

  data.steering = 0;

  data.forward = 255;

  data.reverse = 255;

  data.brake = 0; 

  data.lighting = 0;

  data.current = 0;

  data.voltage = 0;

  data.horn = 0; 

  data.lock = 0;   

}  

/******Reset the received data to 0 if connection is lost******/

unsigned long lastRecvTime = 0;

void recvData()

{

  while ( radio.available() )

  {

    radio.read(&data, sizeof(MyData));

    lastRecvTime = millis(); //here we receive the data

  }

}
//startCooling..........

//const int start_resistor_temp = 35;//c 

const int start_motor_temp = 40;//c 

const int start_Hbridge_temp = 30;//c 

//temp sensors

float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

/*

//------resistor

float R1 = 9780;

int Vo;

float logR2, R2, T, Tc;

*/

//------motor

float R1B = 9920;

int VoB;

float logR2B, R2B, TB, TcB;

//------Hbridge

float R1C = 9910;

int VoC;

float logR2C, R2C, TC, TcC;

void fanControl(){

/*  

//------------------------------------------------resistor temp controll  

  Vo = analogRead(resistorTemp);

  R2 = R1 * (1023.0 / (float)Vo - 1.0);

  logR2 = log(R2);

  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));

  Tc = T - 273.15;

  if (Tc > start_resistor_temp) pcf8575.digitalWrite(resistorFAN, HIGH);

  if (Tc < start_resistor_temp - 3) pcf8575.digitalWrite(resistorFAN, LOW);

*/

//-------------------------------------------------motor temp controll

  VoB = analogRead(motorTemp);

  R2B = R1B * (1023.0 / (float)VoB - 1.0);

  logR2B = log(R2B);

  TB = (1.0 / (c1 + c2*logR2B + c3*logR2B*logR2B*logR2B));

  TcB = TB - 273.15;

  if (TcB > start_motor_temp) pcf8575.digitalWrite(motorFAN, HIGH);

  if (TcB < start_motor_temp - 3) pcf8575.digitalWrite(motorFAN, LOW);

//-------------------------------------------------H-bridge temp

  VoC = analogRead(H_bridgeTemp);

  R2C = R1C * (1023.0 / (float)VoC - 1.0);

  logR2C = log(R2C);

  TC = (1.0 / (c1 + c2*logR2C + c3*logR2C*logR2C*logR2C));

  TcC = TC - 273.15;

  if (TcC > start_Hbridge_temp) pcf8575.digitalWrite(H_bridgeFAN, HIGH);

  if (TcC < start_Hbridge_temp - 3) pcf8575.digitalWrite(H_bridgeFAN, LOW);

//-----------------------------------------------------------------------------------------test point temp sensors  

// Serial.println(Tc);  //resistorTemp

// Serial.println(TcB); //motorTemp

// Serial.println(TcC); //H_bridgeTemp

}
unsigned long previousTimephotoSense1 = 0;

unsigned long previousTimephotoSense2 = 0;

void autoLights()

{

  unsigned long currentTimephotoSense = millis();

  if (analogRead(photoSense) > 23 && currentTimephotoSense - previousTimephotoSense1 > 1000)

    {

      previousTimephotoSense2 = millis();

      dayLights();

    }

  

  if (analogRead(photoSense) < 23 && currentTimephotoSense - previousTimephotoSense2 > 1000)

    {

      previousTimephotoSense1 = millis();

      nightLights();      

    }  

}

void lightsOFF()

{

 fill_solid(leds, 14, CRGB(0,0,0));

}

void dayLights()

{

  fill_solid(leds, 2, CRGB(25, 0, 0));

  fill_solid(leds+2, 10, CRGB(0, 0, 0));

  fill_solid(leds+10, 2, CRGB(25, 0, 0)); 

  digitalWrite(lightBar,LOW);

  

  //LEFT steering headlights

  if(data.steering == 1){

  leds[13] = CRGB(8, 8, 8);

  leds[12] = CRGB(25, 25, 25);

  }

  //RIGHT steering headlights  

  if(data.steering == 2){

  leds[13] = CRGB(25, 25, 25);

  leds[12] = CRGB(8, 8, 8);

  }

  //no steering headlights

  if(data.steering == 0){

  fill_solid(leds+12, 2, CRGB(25, 25, 25));

  } 

}

void nightLights()

{

//  fill_solid(leds, 2, CRGB(150, 0, 0));

//  fill_solid(leds+2, 10, CRGB(0, 0, 0));

//  fill_solid(leds+10, 2, CRGB(150, 0, 0));

  fill_solid(leds, 12, CRGB(50, 0, 0));

//fill_solid(leds+12, 2, CRGB(255, 255, 255));

  digitalWrite(lightBar,LOW);

  //LEFT steering headlights

  if(data.steering == 1){

  leds[13] = CRGB(8, 8, 8);

  leds[12] = CRGB(255, 255, 255);

  }

  //RIGHT steering headlights  

  if(data.steering == 2){

  leds[13] = CRGB(255, 255, 255);

  leds[12] = CRGB(8, 8, 8); 

  }

  //no steering headlights

  if(data.steering == 0){

  fill_solid(leds+12, 2, CRGB(255, 255, 255));   

}

}

void lightbar_1()

{

  analogWrite(lightBar,100);

  //  fill_solid(leds, 2, CRGB(150, 0, 0));

//  fill_solid(leds+2, 10, CRGB(0, 0, 0));

//  fill_solid(leds+10, 2, CRGB(150, 0, 0));

  fill_solid(leds, 12, CRGB(50, 0, 0));

//fill_solid(leds+12, 2, CRGB(255, 255, 255));

  //LEFT steering headlights

  if(data.steering == 1){

  leds[13] = CRGB(8, 8, 8);

  leds[12] = CRGB(255, 255, 255);

  }

  //RIGHT steering headlights  

  if(data.steering == 2){

  leds[13] = CRGB(255, 255, 255);

  leds[12] = CRGB(8, 8, 8); 

  }

  //no steering headlights

  if(data.steering == 0){

  fill_solid(leds+12, 2, CRGB(255, 255, 255));   

}

}

void lightbar_2()

{

  analogWrite(lightBar,255);

  //  fill_solid(leds, 2, CRGB(150, 0, 0));

//  fill_solid(leds+2, 10, CRGB(0, 0, 0));

//  fill_solid(leds+10, 2, CRGB(150, 0, 0));

  fill_solid(leds, 12, CRGB(50, 0, 0));

//fill_solid(leds+12, 2, CRGB(255, 255, 255));

  //LEFT steering headlights

  if(data.steering == 1){

  leds[13] = CRGB(8, 8, 8);

  leds[12] = CRGB(255, 255, 255);

  }

  //RIGHT steering headlights  

  if(data.steering == 2){

  leds[13] = CRGB(255, 255, 255);

  leds[12] = CRGB(8, 8, 8); 

  }

  //no steering headlights

  if(data.steering == 0){

  fill_solid(leds+12, 2, CRGB(255, 255, 255));  

}

}
/*****************steering H-bridge modes*************************/

void left()

{

  pcf8575.digitalWrite(H_steering_1, LOW);

  pcf8575.digitalWrite(H_steering_2, HIGH);

}

void right()

{

  pcf8575.digitalWrite(H_steering_1, HIGH);

  pcf8575.digitalWrite(H_steering_2, LOW); 

}

void straight()

{

  pcf8575.digitalWrite(H_steering_1, LOW);

  pcf8575.digitalWrite(H_steering_2, LOW); 

}

/*****************motor H-bridge modes*************************/

void neutral()

{

  digitalWrite(H_motor_1, HIGH);

  digitalWrite(H_motor_2, HIGH);

}

void brake()

{

  digitalWrite(H_motor_1, LOW);

  digitalWrite(H_motor_2, LOW);

  //brake-lights

  fill_solid(leds, 12, CRGB(255, 0, 0));

}

void forward()

{

  analogWrite(H_motor_1, data.forward);

  digitalWrite(H_motor_2, HIGH);

}

void reverse()

{

   digitalWrite(H_motor_1, HIGH);

   analogWrite(H_motor_2, data.reverse);   

   //reverse-lights

   fill_solid(leds+4,4, CRGB(255, 255, 255));

}
void blinkerLeft()

{

  //direction lights LEFT     

  unsigned long currentTime = millis();

  if(currentTime - previousTime >= 200-blinkerSpeed)

  {

  leds[3] = CRGB(255, 81, 0);

  }     

  if(currentTime - previousTime >= 400-blinkerSpeed)

  {

  leds[2] = CRGB(255, 81, 0);

  leds[13] = CRGB(255, 81, 0);

  }     

  if(currentTime - previousTime >= 600-blinkerSpeed)

  {

  leds[1] = CRGB(255, 81, 0);

  }

  if(currentTime - previousTime >= 800-blinkerSpeed)

  {

  leds[0] = CRGB(255, 81, 0);

  }

  if(currentTime - previousTime >= 1050-blinkerSpeed) previousTime = currentTime;    

}

  

void blinkerRight()

{

  //direction lights RIGHT     

  unsigned long currentTime = millis();

  if(currentTime - previousTime >= 200-blinkerSpeed){

  leds[8] = CRGB(255, 81, 0);

  }     

  if(currentTime - previousTime >= 400-blinkerSpeed){

  leds[9] = CRGB(255, 81, 0);

  leds[12] = CRGB(255, 81, 0);

  }     

  if(currentTime - previousTime >= 600-blinkerSpeed){

  leds[10] = CRGB(255, 81, 0);

  }

  if(currentTime - previousTime >= 800-blinkerSpeed){

  leds[11] = CRGB(255, 81, 0);

  }

  if(currentTime - previousTime >= 1050-blinkerSpeed) previousTime = currentTime;  

}

void hazardLights()

{

  unsigned long currentTime = millis();

  if(currentTime - previousTime >= 200-blinkerSpeed){

  leds[8] = CRGB(255, 81, 0);

  leds[3] = CRGB(255, 81, 0);

  }     

  if(currentTime - previousTime >= 400-blinkerSpeed){

  leds[9] = CRGB(255, 81, 0);

  leds[12] = CRGB(255, 81, 0);

  leds[2] = CRGB(255, 81, 0);

  leds[13] = CRGB(255, 81, 0);

  }     

  if(currentTime - previousTime >= 600-blinkerSpeed){

  leds[10] = CRGB(255, 81, 0);

  leds[1] = CRGB(255, 81, 0);

  }

  if(currentTime - previousTime >= 800-blinkerSpeed){

  leds[11] = CRGB(255, 81, 0);

  leds[0] = CRGB(255, 81, 0);

  }

  if(currentTime - previousTime >= 1050-blinkerSpeed) previousTime = currentTime;   

}
float Voltage;

float Percentage;

float MotorCurrent;

float MotorPower;

void readBatVoltage()

{

  int VoltageValue = analogRead(VoltageSense);

  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 14.582 V):

  Voltage = VoltageValue * (14.582 / 1023.0);

  //BatVoltage = Voltage;

}

void readBatProcentage()

{

  Percentage = (Voltage - 6) / 6.6 * 100; 

}

void readMotorCurrent()

{

 MotorCurrent = (Voltage - 2.48) / 0.66 * 10;

}

void readMotorPower()

{

  readBatVoltage();

  readMotorCurrent();

  MotorPower = MotorCurrent * Voltage;

}
void setup()

{ 

 //inputs:

  pinMode(VoltageSense, INPUT);

  pinMode(currentSense, INPUT);

  pinMode(photoSense, INPUT);

//  pinMode(resistorTemp, INPUT);

  pinMode(motorTemp, INPUT);

  pinMode(H_bridgeTemp, INPUT);

   

  //outputs:

  pinMode(H_motor_1, OUTPUT);

  pinMode(H_motor_2, OUTPUT);  

  pinMode(H_steering_1, OUTPUT);

  pinMode(H_steering_2, OUTPUT);

  pinMode(lightBar, OUTPUT); 

  pinMode(resistorFAN, OUTPUT);

 //IO XPANDER

  pcf8575.pinMode(P0, OUTPUT);

  pcf8575.pinMode(P1, OUTPUT);

  pcf8575.pinMode(P2, OUTPUT);

  pcf8575.pinMode(P3, OUTPUT);

  pcf8575.pinMode(P4, OUTPUT);

  pcf8575.pinMode(P5, OUTPUT);

  pcf8575.pinMode(P6, OUTPUT);

  pcf8575.pinMode(P7, OUTPUT);

  pcf8575.pinMode(P8, OUTPUT);

  pcf8575.pinMode(P9, OUTPUT);

  pcf8575.pinMode(P10, OUTPUT);

  pcf8575.pinMode(P11, OUTPUT);

  pcf8575.pinMode(P12, OUTPUT);

  pcf8575.pinMode(P13, OUTPUT);

  pcf8575.pinMode(P14, OUTPUT);

  pcf8575.pinMode(P15, OUTPUT);

  pcf8575.digitalWrite(out0, LOW); // p0

  pcf8575.digitalWrite(out1, LOW); // p1

  pcf8575.digitalWrite(out2, LOW); // p2

  pcf8575.digitalWrite(out3, LOW); // p3

  pcf8575.digitalWrite(out4, LOW); // p4

  pcf8575.digitalWrite(out5, LOW); // p5

  pcf8575.digitalWrite(out6, LOW); // p6

  pcf8575.digitalWrite(out7, LOW); // p7

  //....NON EXISTING/WORKING OUTPUSTS: 8,9,10

  pcf8575.digitalWrite(out11, LOW); // p11

  pcf8575.digitalWrite(out12, LOW);// p12

  pcf8575.digitalWrite(out13, LOW);// p13

  pcf8575.digitalWrite(out14, LOW);// p14

  pcf8575.digitalWrite(out15, LOW);// p15

  pcf8575.digitalWrite(out16, LOW);// p16

  pcf8575.digitalWrite(out17, LOW);// p17

  //START IO XPANDER

  pcf8575.begin();

 

 //FAST_LED

 FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);

  //OLED   

   if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64

    Serial.println(F("SSD1306 allocation failed"));

    for(;;);

  }

  

  display.clearDisplay();

  //starting radio

  Serial.begin(9600); 

  resetData();

  radio.begin();

  radio.setAutoAck(false);

  radio.setDataRate(RF24_250KBPS);  

  radio.openReadingPipe(1,pipeIn);

  //we start the radio comunication

  radio.startListening();

}
void loop()

{

 readBatVoltage();

 readBatProcentage();

 oled();

  

  recvData();

  unsigned long now = millis();

  //if signal lost reset the values 

  if ( now - lastRecvTime > 1000 ) {

    // Signal lost?

    resetData();

   }

  if (data.lock == 0) pcf8575.digitalWrite(highVoltage, LOW);

  if (data.lock == 1) pcf8575.digitalWrite(highVoltage, HIGH);

//-------------------------------------------------fan control 

  fanControl();

 

//------------------------------------------horn

  if (data.horn = 0) digitalWrite(horn, LOW);

  if (data.horn = 1) digitalWrite(horn, HIGH);

//---------transmit--------

//data.current = map (analogRead(currentSense),0 ,1024 ,0 ,255);

//data.current = map (analogRead(currentSense),0 ,1024 ,0 ,255);

//------------------------------------------------------lights  

  if (data.lighting == 0)

  {

    autoLights();  

  }

   

  if (data.lighting == 1)

  {

    lightsOFF();

  }

  

  if (data.lighting == 2)

  {

    dayLights();

  }

  

  if (data.lighting == 3)

  {

    nightLights();

  }

  

  if (data.lighting == 4)

  {

    lightbar_1();  

  }

  if (data.lighting == 5)

  {

    lightbar_2();  

  }

//---------------------------------steering:

  if (data.steering == 0) 

  {

    straight();

  }

  

  if (data.steering == 1) 

  {

    left();

    blinkerLeft();

  }

  if (data.steering == 2) 

 {

  right();

  blinkerRight();

 }

 

 if (data.steering == 4) 

 {

  hazardLights();

 }

//forward

 if (data.forward < 255) 

  {

    forward();

  }

 

 //reverse

 if (data.reverse < 255)

  {

    reverse();

  }

  

  //break

 if (data.brake == 1) 

 {

    brake(); 

 }

 

 //neutral

 if (data.reverse == 255 && data.forward == 255)

  {

    neutral();

  }

    FastLED.show();

  {

  readBatVoltage();

  readBatProcentage();

  Serial.print(Voltage);

  Serial.println("V");

  Serial.print(Percentage);

  Serial.println("%");

}

}
#define SCREEN_WIDTH 128 // OLED display width, in pixels

#define SCREEN_HEIGHT 64 // OLED display height, in pixels

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void oled()

{

  display.setTextSize(2);

  display.setTextColor(WHITE);

  display.clearDisplay();

  display.setCursor(0, 8);

  //display.setCursor(0, 30);

  display.print(Percentage); display.println("%");

  //display.setCursor(0, 30);

  //display.print(MotorPower); display.println("W");

  //display.setCursor(0, 8); 

  display.print(Voltage); display.println("V"); 

  display.display(); 

}

( **</>** )

--------------------------------------------------------------------------------------------------------------------------------------------


the nrf 24 library i used can be found here: Download NRF24 library Arduino

Code tags, please.
Schematic, please.

sp. "a lot"

i dont have a scematic for the pcb, but i dont think there is a problem with the wiring bicous the problem still ocures when i take the arduino off the pcb.
(all outputs are conected to a 2n7000 signal FET)

how can code make A0 draw current????

The code can’t make A0 take current !

What value resistors do you have in your divider ? If you overvoltage the analog input , it will take current via its internal protection diodes .

Run a simple example analog input example and check your voltages , as your code has a few errors in it too …. ( you can’t multiply a int with numbers with decimal points or multiply with big numbers without it overflowing .The analog inputs always need calibrating and if you don’t use the internal reference , then your reading will change with variations in Vcc.)
When I’ve done voltmeters like this , I’ve stuck with integers and give the output in mV , just using the map function, stick a decimal where you want on the display to read volts .

A schematic is needed, if there is a fault with the way your inputs are connected ( eg I see volts and amps measured ) that could be a problem .

I would be using the internal voltage ref ~ 1.1v and something like 1-1k2 ( you do the maths) and 15k in the divider .

All the more reason to believe it is in fact related to your schematic and/or pcb. Come on, let's have a look. I'm going to hazard a very conservative guess that the odds are 99% you have a little electrical engineering bug going on there. Forget about your code for now; fix the hardware first.

PS: how can you make a pin draw current with code? Easy - apply voltage to it from a low impedance source, set the pin as output and digitalWrite LOW to it. On an atmega this will typically halt any other code execution and the chip will heat up. It may or may not work after correcting the situation.

1 Like

that is really confusing me 2, but it is really happening.

this problem doesn't have anything to do with wiring, because it still occurs even if I completely disconnect the Arduino from all circuitry like in the picture below.

and the voltage dvider is: R1=9,85k R2=5.14K

and keep in mind that if i upload a regular analog read sketch this arduino works totaly fine.

i don't have a schematic because i kinda freewheeled it :grin:
(its on a perfboard)

, but even if I disconnect everything and test it without a voltage divider I'm still having the same issue.

note that I'm having the same issue with the Arduino NANO and that these Arduino's works fine with a normal analog or voltage read sketch. (the problem is only on A0 other pins work properly)

NEVER connect a voltage source capable of supplying current (battery or power supply) directly to a pin. Always use a (10k) current limiting resistor in series. Because you could damage the pin if the voltage applied to the pin is outside the safe range of the pin (VCC +0.3 and GND -0.3).
That means maximum 0.3volt if you forget to power the Arduino (VCC= 0volt).
Leo..

out16 is defined as p14 which is the same actual pin as A0

1 Like

Hi, @

Well this is the time you draw a schematic, even if your circuit is "working".

Did you write this code, or is it from another source?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

1 Like

Dear, TomGeorge

I proudly coded this project myself :grin:, but I'm very much a beginner. I just started with the default sketch from the nrf 24 library. and expanded on that. then I began writing this code I didn't even know the millis function yet so I was still struggling with the delay function :joy: i gust learned everything on the go and copied the key commands for modules from demo sketches.

I don't really feel like making a schematic for this casual project because sometimes i find it a lot more fun to just make things up on the go and not spending half of the time making a schematic. another reason I didn't make a schematic is that i didn't expect RC car to handle all the abuse I've been putting it through. it used to be powered by a 9V battery now the motor is drawing 150Watt from my lion battery pack. :joy:
if you want to make a proper product or devise you should probably make a schematic tho :upside_down_face:

I wasn't planning on putting all of this on a perfboard either but I kinda had to after burning down 2 breadboards by driving into walls. :joy:

if you really want me to make a schematic for you I can do that though.

it already has some minor damages but there is nothing a big glob of hot glue cant fix :joy:

greetings... Maurice... :grinning: :+1::cheese: :netherlands:

I've tried to un quoting

const int out16 = P14;

pcf8575.pinMode(P14, OUTPUT);

pcf8575.digitalWrite(out14, LOW);// p14

but sadly this didn't change the behavior of pin A0.

are you sure these lines of code change the behavior of A0. because it does say pfc875. in front of it. and I'm not even using p14 for anything.

does this mean that I cant use the PCF8575.h library and use A0 at the same time?

thank you very much for your response. im hoping you can give me a bit more explanation of how I can solve this likely problem with p14.

greetings, Maurice :grinning:

Hi,
if p14 is the analog input, why are you declaring it an OUTPUT?

Why use p14 and not A0 in your code.
Hang on I see, p14 is on the expander, you may need to rename some expander variable names.
What are you measuring with A0 input?
Some decent descriptive variable names for input and output pins would help.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

What do you measure for current draw of the voltage divider? I bet the voltage divider is drawing a lot lot more current than A0

Well something is. You present a problem that to anyone who knows anything about hardware is actually impossible. The only explanation of what you are seeing is that some other part of the code is using that same pin and changing its configuration. Pin 14 is the same pin as A0, this pin can be used as an analogue input but can also be used as a normal digital input and output.

And it shows. That is not how you should write code, it needs a plan. Now that is something that you could do in your head, with enough experience but you code clearly shows you haven got there yet.

So it is all in your head. I am not good enough to do this and I have had 50 years experience in electronics so what makes you think that you are good enough to do that? But the biggest thing is that how do you expect us, on this forum, to know what is in YOUR head? My crystal ball is on the blink at the moment.

An embedded project is the interaction between hardware and software, to show only half that only shows half the problem. You need to know what is in the hardware to make any sense of the software.

So yes we need to see a schematic but more important that this you need to see a schematic. Not thinking you need a schematic is a typical beginners mistake.

When I was at school in the 1960s I had a metal work teacher who said "if you can't draw it, you can't make it". That is very good advise.

That is over 16 Amps, that is ridiculous.

So your horn is permanently HIGH?

1 Like

p14 is the name of output 16 on the pfc8575 io extender.

no

byte horn / data.horn

is one of the transmitted values from the remote controller. if horn button is pressed on the remote it wil transmit:

data.horn = 1;

and if the horn button is not presed or the remote is disconected:

data.horn = 0; 

I think you have missed @Whandall's hint.

Look again at the question, and the code.

(@Whandall has much more scrolling stamina than I - there's an awful lot of code there)

The value of an assignment is the assigned value.

You have assignments in your if statements,
where I think you should (and wanted) to use a comparison.

'=' is for assignment, '==' is for comparison.

1 Like