Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Arduino ADC channels reading approach

Status
Not open for further replies.

imranahmed

Advanced Member level 3
Advanced Member level 3
Joined
Dec 4, 2011
Messages
817
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Karachi,Pakistan
Activity points
6,493
Please let me know that I want to display sensors reading, 6 sensors 3 for Voltage sensing and 3 for current sensing CT.

I recently write a code for reading ADC data, please let me know what is good approach for making code.

I mean, code with good sequence for controller, not hanging and not take extra memory.

Please make your valuable suggestions.

Code:
int sensorPinV1 = A0;    // select the input pin for the potentiometer
int sensorPinV2 = A1;    // select the input pin for the potentiometer
int sensorPinV3 = A2;    // select the input pin for the potentiometer
int sensorPinA1 = A3;    // select the input pin for the potentiometer
int sensorPinA2 = A4;    // select the input pin for the potentiomete
int sensorPinA3 = A5;    // select the input pin for the potentiomete

int sensorValueV1 = 0;  // variable to store the value coming from the sensor
int sensorValueV2 = 0;  // variable to store the value coming from the sensor
int sensorValueV3 = 0;  // variable to store the value coming from the sensor
int sensorValueA1 = 0;  // variable to store the value coming from the sensor
int sensorValueA2 = 0;  // variable to store the value coming from the sensor
int sensorValueA3 = 0;  // variable to store the value coming from the sensor



void setup() {
  // declare the ledPin as an OUTPUT:
  Serial.begin(9600);
 }

void loop() {
  // read the value from the sensor:
  sensorValueV1 = analogRead(sensorPinV1);
  delay(1);
  sensorValueV2 = analogRead(sensorPinV2);
  delay(1);
  sensorValueV3 = analogRead(sensorPinV3);
  delay(1);
  sensorValueA1 = analogRead(sensorPinA1);
  delay(1);
  sensorValueA2 = analogRead(sensorPinA2);
  delay(1);
  sensorValueA3 = analogRead(sensorPinA3);
  
  
  
  float V1 = sensorValueV1 * (5.0 / 1023.0);  
  Serial.print("V1 VALUE IS = ");
  Serial.println(V1);
  
  float V2 = sensorValueV2 * (5.0 / 1023.0);  
  Serial.print("V2 VALUE IS = ");
  Serial.println(V2);

  float V3 = sensorValueV3 * (5.0 / 1023.0);  
  Serial.print("V3 VALUE IS = ");
  Serial.println(V3);

  float A1 = sensorValueA1 * (5.0 / 1023.0);  
  Serial.print("A1 VALUE IS = ");
  Serial.println(A1);

  float A2 = sensorValueA2 * (5.0 / 1023.0);  
  Serial.print("A2 VALUE IS = ");
  Serial.println(A2);

  float A3 = sensorValueA3 * (5.0 / 1023.0);  
  Serial.print("A3 VALUE IS = ");
  Serial.println(A3);
  
  delay(3000);
  

  
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top