A0 drawing current because of code

here is the code with tabs this should make it a little bit easier.

tab-1 (defenitions):

 /*
  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;

//
tab-2 (radio):

/*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;   
}  

//
tab-3 (fan control):

//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

}

//
tab-4 (head lights):

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));  
}
}

//
tab-5 (H-bridge Modes):

/*****************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));
}

//
tab-6 (blinkers):

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;   
}

//
tab-7 (power sensing):

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()
{
  float CurrentSenseVoltage = analogRead(CurrentSense) * (5.0 / 1023.0);
  MotorCurrent = (CurrentSenseVoltage - 2.46) / 0.066;
}

void readMotorPower()
{
  readBatVoltage();
  readMotorCurrent();
  MotorPower = MotorCurrent * Voltage;
}

//
tab-7 (OLED):

#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.print(Percentage); display.println("%");
  display.print(Voltage); display.println("V"); 
  display.print(MotorPower); display.println("W"); 
  display.display();
}

//
tab-8 (setup):

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();
}

//
tab-9 (loop):

void loop()
{
 readBatVoltage();
 readBatProcentage();
 readMotorPower();
 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();
  {
  //Serial.print(Voltage);
  //Serial.println("V");
  //Serial.print(MotorCurrent);
  //Serial.println("A");
}
}

aha thanks a lot i honestly never even knew the difference in between those 2 :joy:

(ive corrected my for this code now :grin:);

no it's drawing about 12Amps because its running on a 12.6v battery

if you still believe this problem has anything to do with my circuit/schematic gust upload this code to a bear Arduino. when you connect a voltage source (for example 1V) to A0 with a current meter in between you should see a current draw.
if you want to test this the safe /proper way connect the voltage source to a 10k resistor that goes to A0. then measure the voltage on A0 with a voltage meter. if the meter reads 0V (this means A0 is draining all the current) you are having the same issue as me.
schematic for this test:
(note that the Arduino is powered by USB 5V)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

(i know that this code won't get to the loop if you don't connect any of the modules, but this shouldn't matter because A0 still behaves the same weird way)

 /*
  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  A6
#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()
{
  float CurrentSenseVoltage = analogRead(CurrentSense) * (5.0 / 1023.0);
  MotorCurrent = (CurrentSenseVoltage - 2.46) / 0.066;
}

void readMotorPower()
{
  readBatVoltage();
  readMotorCurrent();
  MotorPower = MotorCurrent * Voltage;
}
#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.print(Percentage); display.println("%");
  display.print(Voltage); display.println("V"); 
  display.print(MotorPower); display.println("W"); 
  display.display();
}
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();
 readMotorPower();
 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();
  {
  //Serial.print(Voltage);
  //Serial.println("V");
  //Serial.print(MotorCurrent);
  //Serial.println("A");
}
}

I'm very interested if I'm the only one experiencing this with my Arduino boards, so I would appreciate it if someone else could test this too.

thanks, Maurice :grinning:

i got it from github: https://codeload.github.com/xreef/PCF8575_library/zip/master

Well here is your schematic sir:

(this is my last replies for today because I've reached the maximum amount.)

If your code really does this, then I stand by my earlier remark that you somehow make the erroneous combination of applying a voltage from a low impedance source to a pin that you then force low from your code. It is still relevant to see your schematic because it's a combination of your code and the hardware interface. I find it odd that with your confessed minimal experience you keep sidestepping the hardware issue brought forth by more experienced colleagues.

Hi,
I tried to compile your code in your first post.
It won't compile.
UNO selected.

Is that your entire code that is supposed to compile and upload to a UNO?

Thanks.. Tom... :smiley: :coffee: :coffee: :australia:

This part is interesting; it's not the cause of the problem, but it is risky business - earlier in your sketch you imply that the horn is connected to port 6 of the expander, but you do write to this port (which maps to pin 6 / PD6 on your Arduino according to your various indirect #defines etc.) Now, this should only muck up the functioning of H-motor as you're essentially addressing its 2nd pin of it without being aware of it. But it does bring up the possibility that you have something similar going on elsewhere in your code spaghetti where you're inadvertently writing a logic 0 to your A0 pin. This combined with unsafe/poor hardware design may result in the behavior you're reporting.

BTW: I just did a quick test with a Nano here on my desk, which proves something we all know already - when read properly, the A0 pin draws less current than any of my multimeters can measure. Nano powered from USB, A0 pin directly (through multimeter leads) connected to Vin.
Obviously I'm not going to compile and upload your code to it just to risk a perfectly fine 328p uC that I will use at some point later on.

We'll be seeing you around with more 'inexplicable' problems, I suppose. ALWAYS make a schematic, no matter how incredibly simple the circuit is. I think all of us, without exception, have had these forehead-slap moments when we though we were doing something too simple to bother getting a pencil out for it only to burn up some components due to a silly mistake.

The word is "just" not "gust".

Your code has a lot of libraries included that I don't use.

Why should I run potentially harmful code on my hardware, just because you are refusing to post a schematic?

I am beginning to wonder if you are worthy of help, because you certainly don't seem to want to learn.

Hi,
Your code in post#23 doesn't compile for Nano.

Where did you get the PCF8575 library?

Thanks.. Tom... :smiley: :coffee: :coffee: :coffee: :australia:

Well I had just decided to rewire the voltage divider on the RC car to the spare analog pin(A6). Now everything on the RC car works fine. It drives smoothly and gives reasonably accurate voltage, current and power measurements. but A0 still is behaving the same weird way (with nothing connected to it and no direct mention in the code that I know of). I would still be very interested to hear the cause of this weird behavior of pin (A0), because technically this should be impossible, right?

Maybe you blew up that pin in an earlier experiment and it keeps malfunctioning now.

1 Like

I don't believe this is the case because I have tried this code on 2 other Arduino's and they had the same issue. also, note that when I upload the default analog read sketch on the Arduino's A0 works fine.
I'm guessing that the problem has something to do with the pfc8575 library, because it is reasonably unknown and the pin numbers in the library dont match all the pins on the I/O extender, so I had to remap them,

greetings, maurice

The only thing you can do is go through all the code (including all libraries used) of your project and note all instances where digitalWrite is used and on which pins. At some point you would have to run into a digitalWrite(0) to the A0 pin. A quicker way of course is to comment out libraries one by one until you find the culprit.

Hi,

Where did you get the PCF8575 library from?

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

A digitalWrite (0, x) is a digitalWrite to pin zero not A0. A digitalWrite to 14 is a digitalWrite to A0.

Sorry, meant a digitalwrite assigning low/0 to pin 14/a0.

1 Like

i got it from github: GitHub - xreef/PCF8575_library: Library to use i2c digital expander with arduino, esp8266 and esp32. Can read write digital value with only 2 wire (perfect for ESP-01).

(direct download): https://codeload.github.com/xreef/PCF8575_library/zip/master