Livella Elettronica – Arduino – Electronic Level

 

Come promesso nel video postato su youtube ecco lo schema per programmare Arduino.

As promised… This is the code for the arduino electronic level.

int sensorPin1 = A0; // select the input pin for the potentiometer
int sensorPin2 = A1; // select the input pin for the potentiometer
int ledPin1 = 3;
int ledPin2 = 4;
int ledPin3 = 5;
int ledPin4 = 6;
int ledPin5 = 7;
int ledPin6 = 8;
int ledPin7 = 9;
int ledPin8 = 10;
int ledPin9 = 11;
int ledPin10 = 12;

int sensorValueX = 0; // variable to store the value coming from the sensor
int sensorValueY = 0; // variable to store the value coming from the sensor
int outputValueX = 0; // value output to the PWM (analog out)
int outputValueY = 0; // value output to the PWM (analog out)

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);

//Test the ledPins
for (int i=3; i for (int j=8; j digitalWrite(i, HIGH);
digitalWrite(j, HIGH);
delay(100);
digitalWrite(i, LOW);
digitalWrite(j, LOW);
}
}

// initialize serial communications at 9600 bps:
Serial.begin(9600);
}

void loop() {
// read the value from the sensor:
sensorValueX = analogRead(sensorPin1);
sensorValueY = analogRead(sensorPin2);

if (sensorValueX {
outputValueX=0;
digitalWrite(ledPin1, HIGH);
}
else if (sensorValueX > 440 && sensorValueX {
outputValueX=1;
digitalWrite(ledPin2, HIGH);
}
else if (sensorValueX > 480 && sensorValueX {
outputValueX=2;
digitalWrite(ledPin3, HIGH);
}
else if (sensorValueX > 500 && sensorValueX {
outputValueX=3;
digitalWrite(ledPin4, HIGH);
}
else
{
outputValueX=4;
digitalWrite(ledPin5, HIGH);
}

if (sensorValueY {
outputValueY=0;
digitalWrite(ledPin6, HIGH);
}
else if (sensorValueY > 440 && sensorValueY {
outputValueY=1;
digitalWrite(ledPin7, HIGH);
}
else if (sensorValueY > 480 && sensorValueY {
outputValueY=2;
digitalWrite(ledPin8, HIGH);
}
else if (sensorValueY > 500 && sensorValueY {
outputValueY=3;
digitalWrite(ledPin9, HIGH);
}
else
{
outputValueY=4;
digitalWrite(ledPin10, HIGH);
}

// print the results to the serial monitor:
Serial.print(“sensorX = ” );
Serial.print(outputValueX);
// Serial.print(sensorValueX);
Serial.print(” & sensorY = ” );
Serial.println(outputValueY);
// Serial.println(sensorValueY);

// wait 100 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(100);

//turn the ledPins off
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
digitalWrite(ledPin9, LOW);
digitalWrite(ledPin10, LOW);
}

Schematic follows below!

One Response to “Livella Elettronica – Arduino – Electronic Level”

  1. Marco Says:
    novembre 19th, 2015 at 19:25

    Ciao Vito, complimenti per il progetto, molto interessante.
    Stavo provando a realizzare un progetto simile per verificare se un piano รจ in bolla. Vorrei sapere che tipo di sensore hai usato.
    Marco

Leave a Reply