Quantcast
Channel: Comments for miscellanea.com || andrew burrell
Viewing all articles
Browse latest Browse all 11

Comment on how to get more arduino analog inputs by andrew

$
0
0

hi..

There were some syntax errors in your code, but the following, assuming your hardware is wired up correctly, should work for you to read all 8 analog inputs of the 4051 from analog pin 0 on the arduino. If you wanted to read from 3 4051s then you just need to repeat the process in the loop, but using two other analog pins on the arduino..


void setup()

{
//4051 digital control pins

pinMode(8, OUTPUT); // s0
pinMode(9, OUTPUT); // s1
pinMode(10, OUTPUT); // s2

Serial.begin(9600);
}

void loop()

{

//Read Value of 4051 analog-in 0 by setting the values of s0,s1 and s2
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
delay(10); //not sure if this delay is strictly necessary
int readInZero = analogRead(0); // read the arduino input pin the 4051 is using
Serial.println(readInZero); //use the result

//Read Value of 4051 analog-in 1 by setting the values of s0,s1 and s2
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
delay(10); //not sure if this delay is strictly necessary
int readInOne = analogRead(0); // read the arduino analog input pin
Serial.println(readInOne); //use the result

//Read Value of 4051 analog-in 2 by setting the values of s0,s1 and s2
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
delay(10);
int readInTwo= analogRead(0);
Serial.println(readInTwo); //use the result

//Read Value of 4051 analog-in 3 by setting the values of s0,s1 and s2
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
delay(10);
int readInThree= analogRead(0);
Serial.println(readInThree); //use the result

//Read Value of 4051 analog-in 4 by setting the values of s0,s1 and s2
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
delay(10);
int readInFour= analogRead(0);
Serial.println(readInFour); //use the result

//Read Value of 4051 analog-in 5 by setting the values of s0,s1 and s2
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
delay(10);
int readInFive= analogRead(0);
Serial.println(readInFive); //use the result

//Read Value of 4051 analog-in 6 by setting the values of s0,s1 and s2
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
delay(10);
int readInSix= analogRead(0);
Serial.println(readInSix); //use the result

//Read Value of 4051 analog-in 7 by setting the values of s0,s1 and s2
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
delay(10);
int readInSeven= analogRead(0);
Serial.println(readInSeven); //use the result

}


Viewing all articles
Browse latest Browse all 11

Trending Articles