Evaluate an analog value through the ADC on an Arduino
Aus DL8RDS Wiki
And after making a connection to /dev/ttyUSB0 with 9600 bit/s and handshake off, I was able to read the Hello by every second. So also the serial connection is damn simple. The next bit was even a bit harder: I want to read out the setting of a poti and send the value to the serial console. That's my first attempt to make a bridge from the real world into the digital world. Here's the setup:
The poti is a 1 kOhm.
And here's the code:
int potiPin = 0; int potiVal = 0; void setup() { Serial.begin(9600); int potiPin = 0; } void loop() { int zahl = 10; int potiVal = analogRead(potiPin); Serial.println("Poti-Wert:"); Serial.println(potiVal); Serial.println("-------------"); delay(1000); }
And now when I take a screwdriver and twist around the poti, I am getting different values in my minicom!!!
Poti-Wert: 541 ------------- Poti-Wert: 561 ------------- Poti-Wert: 653 ------------- Poti-Wert: 804 ------------- Poti-Wert: 857 ------------- Poti-Wert: 1018 ------------- Poti-Wert: 1023 ------------- Poti-Wert: 1019
Most remarkable is that the values range from 0 to 1023. So that's just a perfect basis to do further calculations.