int val = 0; // variable to store the value read void setup() { //4051 digital control pins pinMode(13, OUTPUT); // s0 pinMode(12, OUTPUT); // s1 pinMode(11, OUTPUT); // s2 Serial.begin(9600); } void loop() { //Read Value of 4051 analog-in 0 by setting the values of s0,s1 and s2 (motor 01) digitalWrite(13, LOW); digitalWrite(12, LOW); digitalWrite(11, LOW); delay(10); //not sure if this delay is strictly necessary val = analogRead(0); // read the arduino input pin the 4051 is using val = map(val, 0, 1023, 100, 300); val = val * 100 + 1; Serial.println(val); //use the result //Read Value of 4051 analog-in 1 by setting the values of s0,s1 and s2 (motor 02) digitalWrite(13, HIGH); digitalWrite(12, LOW); digitalWrite(11, LOW); delay(10); //not sure if this delay is strictly necessary val = analogRead(0); // read the arduino analog input pin val = map(val, 0, 1023, 100, 300); val = val * 100 + 2; Serial.println(val); //use the result //Read Value of 4051 analog-in 2 by setting the values of s0,s1 and s2 (motor 03) digitalWrite(13, LOW); digitalWrite(12, HIGH); digitalWrite(11, LOW); delay(10); val = analogRead(0); val = map(val, 0, 1023, 100, 300); val = val * 100 + 3; Serial.println(val); //use the result //Read Value of 4051 analog-in 3 by setting the values of s0,s1 and s2 (motor 04) digitalWrite(13, HIGH); digitalWrite(12, HIGH); digitalWrite(11, LOW); delay(10); val = analogRead(0); val = map(val, 0, 1023, 100, 300); val = val * 100 + 4; Serial.println(val); //use the result //Read Value of 4051 analog-in 4 by setting the values of s0,s1 and s2 (motor 05) digitalWrite(13, LOW); digitalWrite(12, LOW); digitalWrite(11, HIGH); delay(10); val = analogRead(0); val = map(val, 0, 1023, 100, 300); val = val * 100 + 5; Serial.println(val); //use the result //Read Value of 4051 analog-in 5 by setting the values of s0,s1 and s2 (motor 06) digitalWrite(13, HIGH); digitalWrite(12, LOW); digitalWrite(11, HIGH); delay(10); val = analogRead(0); val = map(val, 0, 1023, 100, 300); val = val * 100 + 6; Serial.println(val); //use the result //Read Value of 4051 analog-in 6 by setting the values of s0,s1 and s2 (motor 07) digitalWrite(13, LOW); digitalWrite(12, HIGH); digitalWrite(11, HIGH); delay(10); val = analogRead(0); val = map(val, 0, 1023, 100, 300); val = val * 100 + 7; Serial.println(val); //use the result //Read Value of 4051 analog-in 7 by setting the values of s0,s1 and s2 (motor 08) digitalWrite(13, HIGH); digitalWrite(12, HIGH); digitalWrite(11, HIGH); delay(10); val = analogRead(0); val = map(val, 0, 1023, 100, 300); val = val * 100 + 8; Serial.println(val); //use the result //Read Value from Analig pin 1 (motor 09) delay(10); val = analogRead(1); val = map(val, 0, 1023, 100, 300); val = val * 100 + 9; Serial.println(val); //use the result //Read Value from Analig pin 2 (motor 10) delay(10); val = analogRead(2); val = map(val, 0, 1023, 100, 300); val = val * 100 + 10; Serial.println(val); //use the result //Read Value from Analig pin 3 (motor 11) delay(10); val = analogRead(3); val = map(val, 0, 1023, 100, 300); val = val * 100 + 11; Serial.println(val); //use the result //Read Value from Analig pin 4 (motor 12) delay(10); val = analogRead(4); val = map(val, 0, 1023, 100, 300); val = val * 100 + 12; Serial.println(val); //use the result }