#include #include LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display // Anschlüsse: // GND - GND // VCC - 5V // SDA - ANALOG Pin 4 // SCL - ANALOG pin 5 #include HX711 scale(A2, A1); long sensorValue; // Einlesewert vom Potentiometer long Rohwert; // vom HX711 gelieferter Rohwert int h; // Fallhöhe float g; long time_start, time_end; const int buttonPin = 8; // the number of the pushbutton pin int triggerPin = 2; // the number of the trigger pin for the solenoid int sensorPin = A0; // pin for reading the potentiometer // ===================== // ======= SETUP ======= // ===================== void setup() { Serial.begin(115200); scale.set_gain(128); // A-Kanal: gain = 64 oder 128; B-Kanal: fix 32 pinMode(buttonPin, INPUT); pinMode(triggerPin, OUTPUT); digitalWrite(triggerPin, LOW); Rohwert = scale.read(); lcd.begin(); // initialize the lcd // Print a message to the LCD. lcd.backlight(); lcd.setCursor(0,0); lcd.print("Erd-"); lcd.setCursor(0,1); lcd.print("beschleunigung"); delay(3000); lcd.setCursor(0,0); lcd.print(" "); lcd.setCursor(0,1); lcd.print(" "); } // ============================ // ======= HAUPTSCHLEIFE ====== // ============================ void loop() { lcd.setCursor(0,0); lcd.print("Eingabe Hoehe:"); lcd.setCursor(0,1); lcd.print("h = "); lcd.setCursor(8,1); lcd.print("mm"); while(digitalRead(buttonPin) == LOW) { sensorValue = analogRead(sensorPin); sensorValue = map(sensorValue,0,1023,0,9); lcd.setCursor(6,1); lcd.print(sensorValue); } delay(300); h = sensorValue * 1; while(digitalRead(buttonPin) == LOW) { sensorValue = analogRead(sensorPin); sensorValue = map(sensorValue,0,1023,0,9); lcd.setCursor(5,1); lcd.print(sensorValue); } delay(300); h = h + sensorValue * 10; while(digitalRead(buttonPin) == LOW) { sensorValue = analogRead(sensorPin); sensorValue = map(sensorValue,0,1023,0,9); lcd.setCursor(4,1); lcd.print(sensorValue); } delay(300); h = h + sensorValue * 100; Serial.print("h = "); Serial.print(h); Serial.println(" mm"); lcd.setCursor(0,0); lcd.print("h = "); lcd.print(h); lcd.print(" mm "); lcd.setCursor(0,1); lcd.print("press button "); while(digitalRead(buttonPin) == LOW) { } delay(300); // Start the experiment // ==================== digitalWrite(triggerPin, HIGH); lcd.setCursor(0,0); lcd.print("ball in position "); lcd.setCursor(0,1); lcd.print("press button "); while(digitalRead(buttonPin) == LOW) { } delay(1000); digitalWrite(triggerPin, LOW); time_start = millis(); while(scale.read() > 1.05 * Rohwert) // wait for the ball colliding with the scale { } time_end = millis(); g = 2 * h * 1000.0 /((time_end - time_start) * (time_end - time_start)); lcd.setCursor(0,0); lcd.print("g = "); lcd.print(g); lcd.print(" m/s2 "); lcd.setCursor(0,1); lcd.print("press button "); while(digitalRead(buttonPin) == LOW) { } delay(300); lcd.setCursor(0,0); lcd.print(" "); lcd.print(g); lcd.setCursor(0,1); lcd.print(" "); }