Arduino Examples
Analog Read Serial and Read Analog Voltage
Reads an analog input on pin 0, prints the result to the serial monitor
CODE FROM ARDUINO.CC
Both of these examples use the same wiring and component (10k ohm Potentiometer), but the programs are different. Both use the UNO R3 Boards analog-to-digital converter.
I had trouble getting the Raspberry Pi Zero to run these two sketches, they did run but the read out was very slow and not showing the results equal to where the knob was on the potentiometer. The Raspberry Pi 3 was able to run these okay.
I had trouble getting the Raspberry Pi Zero to run these two sketches, they did run but the read out was very slow and not showing the results equal to where the knob was on the potentiometer. The Raspberry Pi 3 was able to run these okay.
Analog Read Serial:
In this program the analog-to-digital converter shows the resistance of the Potentiometer in a value between 0 to 1023 in the Serial Monitor (which you get by clicking on the magnifier on the upper right side of the Arduino IDE).
/* AnalogReadSerial Reads an analog input on pin 0, prints the result to the serial monitor. Graphical representation is available using serial plotter
(Tools > Serial Plotter menu) Attach the center pin of a potentiometer to pin A0,
and the outside pins to +5V and ground. This example code is in the public domain. */ // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // print out the value you read: Serial.println(sensorValue); delay(1); // delay in between reads for stability }
Analog Read Serial Output
Read Analog Voltage:
This time the analog-to-digital converter shows the resistance of the Potentiometer in volts from 0 to 5 volts in the Serial Monitor.
/* ReadAnalogVoltage Reads an analog input on pin 0, converts it to voltage,
and prints the result to the serial monitor. Graphical representation is available using serial plotter
(Tools > Serial Plotter menu) Attach the center pin of a potentiometer to pin A0,
and the outside pins to +5V and ground. This example code is in the public domain. */ // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float voltage = sensorValue * (5.0 / 1023.0); // print out the value you read: Serial.println(voltage); }
Read Analog Voltage Output
I think I will be coming back to the Potentiometer, when I have more understand of programming, and electronics.
No comments:
Post a Comment