Arduino: Potentiometer Diagrams & Code
percent = map(potValue 0
Aulas de Arduino uno
int sensorReading = analogRead(A0);. // print the sensor reading so you know its range. Serial.println(sensorReading);. // map the analog input range (in
SAM3X-Arduino Pin Mapping
SAM3X-Arduino Pin Mapping. Arduino Due pin mapping table. Due Pin. Number. SAM3X Pin Name. Mapped Pin Name. Max Output. Current (mA) Analog In 0.
Ground Power LED Internal Pin SWD Pin Digital Pin Analog Pin
Internal Pin. SWD Pin. Digital Pin. Analog Pin. Other Pin. Microcontroller's Port. Default. Last update: 16/12/2020. STORE.ARDUINO.CC/MEGA-2560-REV3.
CHAOSA: Chaotic map based random number generator on
The novel system is realized by the Arduino microcontroller. The quality of output sequence is evaluated by key Random bit extraction from the analog.
Arduino : Introduction & Programming
The Arduino Uno board contains 6 pins for. ADC. ? 10-bit analog to digital converter. ? This means that it will map input voltages.
Ground Power LED Internal Pin SWD Pin Digital Pin Analog Pin
Internal Pin. SWD Pin. Digital Pin. Analog Pin. Other Pin. Microcontroller's Port. Default. Last update: 13/10/2021. STORE.ARDUINO.CC/UNO-REV3.
Arduino® Nano 33 IoT
Jul 9 2022 NOTE: As opposed to other Arduino Nano boards
Arduino Programming Part 3
One function maps 10-bit analog input to 8-bit PWM output. ? Another function controls the motor speed. ? Using functions provides modular features that
Arduino Nano (V2.3)
Analog input channel 0 to 7. 27. +5V. Output or. Input. +5V output (from on-board regulator) or. +5V (input from external power supply).
Arduino Programming
Part 3
EAS 199A
Fall 2011
Arduino Programming Part 3: EAS 199A
Overview
Part I
Circuits and code to control the speed of a small DC motor.Use potentiometer for dynamic user input.
Use PWM output from Arduino to control a transistor. Transistor acts as variable voltage switch for the DC motor.Part II
Consolidate code into reusable functions.
One function maps 10-bit analog input to 8-bit PWM output.Another function controls the motor speed.
Using functions provides modular features that are useful for more complex control tasks, e.g. the desktop fan project. 2Arduino Programming Part 3: EAS 199A
Part 1: Control motor speed with a pot
Increase complexity gradually
1.Use a pot to generate a voltage signal
(a)Read voltage with analog input (b)Print voltage to serial monitor to verify2.Convert 10-bit voltage scale to 8-bit PWM scale
(a)Voltage input is in range 0 to 1023 (b)PWM output needs to be in the range 0 to 255 (c)Print voltage to serial monitor to verify3.Write PWM data to DC motor
4.Write a function to linearly scale the data
5.Write a function to update the motor
3Arduino Programming Part 3: EAS 199A
Potentiometer Circuit
Use the potentiometer from the Arduino Inventor's Kit 4Analog
input pin 5V V in V outArduino Programming Part 3: EAS 199A
Code to print potentiometer reading
// Function: read_potentiometer // Read a potentiometer and print the reading int sensor_pin = 3; // Wire sweeper of pot to // analog input pin 3 void setup()Serial.begin(9600);
void loop() int val; val = analogRead( sensor_pin );Serial.print("reading = ");
Serial.println( val );
5Arduino Programming Part 3: EAS 199A
DC Motor Control Circuit
6 +5V motorPin 330Add this to the
breadboard with the potentiometer circuitNPN TransistorSnubber Diode
Arduino Programming Part 3: EAS 199A
DC Motor Control Circuit
7 +5V motorPin 330Analog
input pin 5VArduino
Arduino Programming Part 3: EAS 199A
Subtle: Don't use integer values of 255 and
1023 here. Aggressive compilers pre-compute
the integer division of 255/1023 as zero.Control the DC motor with PWM Output
// Function: DC_motor_control_pot // Use a potentiometer to control a DC motor int sensor_pin = 3; int motor_pin = 5; // must be a PWM digital output void setup()Serial.begin(9600);
pinMode(motor_pin, OUTPUT) void loop() int pot_val, motor_speed; pot_val = analogRead( sensor_pin ); motor_speed = pot_val*255.0/1023.0; // Include decimal analogWrite( motor_pin, motor_speed); 8Arduino Programming Part 3: EAS 199A
Take Stock
You now have a working solution
Potentiometer creates a variable voltage input that is read by theArduino (analogRead)
Motor speed is controlled via PWM
Next step: Use functions to encapsulate code
Reuse code
Organize code: Isolated activities happen inside a function. 9Arduino Programming Part 3: EAS 199A
Part II: Create functions for reusable code
// Function: DC_motor_control_pot // Use a potentiometer to control a DC motor int sensor_pin = 3; int motor_pin = 5; // must be a PWM digital output void setup()Serial.begin(9600);
pinMode(motor_pin, OUTPUT) void loop() int pot_val, motor_speed; pot_val = analogRead( sensor_pin ); motor_speed = pot_val*255.0/1023.0; // Include decimal analogWrite( motor_pin, motor_speed); 10 Adjust motor speed Map input values to output scaleArduino Programming Part 3: EAS 199A
adjust_motor_speed takes care of the two main tasks: reading the potentiometer output sand setting the PWM signal to the transistor // Function: DC_motor_control_pot // Use a potentiometer to control a DC motor int sensor_pin = 3; int motor_pin = 5; // must be a PWM digital output void setup()Serial.begin(9600);
pinMode(motor_pin, OUTPUT) void loop() adjust_motor_speed( sensor_pin, motor_pin); ... // do other useful stuffFinal version of the loop() function
11Arduino Programming Part 3: EAS 199A
Using and Writing Functions
Arduino web site
Functions are reusable code modules:
Functions encapsulate details of tasks into larger building blocksWell-written functions can be reused
Functions can accept input (or not) and return output (or not)All Arduino sketches have at least two functions
‣setup: runs once to configure the system ‣loop: runs repeatedly after start-up is complete Users can add functions in the main sketch file, or in separate files 12Desktop fan: EAS 199A
The setup() Function
Consider the simple blink sketch
13 // Blink.pde: Turn on an LED for one second, then // off for one second. Repeat continuously. void setup() { pinMode(13, OUTPUT); void loop() { digitalWrite(13, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(13, LOW); // set the LED off delay(1000); // wait for a second No inputs"setup" is the name of the function"void" means Returns nothingDesktop fan: EAS 199A
A Function to Translate Linear Scales
Linear scaling from x values
to y values: y = f(x) where f is a linear mapping 14 x min x max x y y max y minIn words: Given x, x
min , x max , y min , and y max , compute yArduino Programming Part 3: EAS 199A
A Function to Translate Linear Scales
Enter the code at the bottom into your sketch
The code is not inside any other program block (like setup or void)How would you test that this function is working?
15 int int_scale(int x, int xmin, int xmax, int ymin, int ymax) int y; y = ymin + float(ymax - ymin)*float( x - xmin )/float(xmax - xmin); return(y);N.B. This code is essentially a reimplementation
of the built-in map function.See http://arduino.cc/en/Reference/Map
Arduino Programming Part 3: EAS 199A
A Function to Translate Linear Scales
16 int int_scale(int x, int xmin, int xmax, int ymin, int ymax) int y; y = ymin + float(ymax - ymin)*float( x - xmin )/float(xmax - xmin); return(y); returns an intname is int_scale first input is an int named "x" return the value stored in "y"Use float for
better precisionArduino Programming Part 3: EAS 199A
Functions are not nested
17 int int_scale(int x, int xmin, int xmax, int ymin, int ymax) void setup() void loop() // Contents of sketch, e.g. motor_control.pdeArduino Programming Part 3: EAS 199A
Functions call other functions
18 int int_scale(int x, int xmin, int xmax, int ymin, int ymax) return( y ); void setup() void loop() motor_speed = int_scale( pot_val, 0, 1023, 0, 255); // Contents of sketch, e.g. motor_control.pdeArduino Programming Part 3: EAS 199A
Functions call other functions
19 int int_scale(int x, int xmin, int xmax, int ymin, int ymax) return( y ); void setup() void loop() motor_speed = int_scale( pot_val, 0, 1024, 0, 255); // Contents of sketch, e.g. motor_control.pdeArduino Programming Part 3: EAS 199A
// Function: DC_motor_control_pot // Use a potentiometer to control a DC motor int sensor_pin = 3; int motor_pin = 5; // must be a PWM digital output void setup()quotesdbs_dbs4.pdfusesText_8[PDF] analog map vs digital map
[PDF] analog mapping in plc
[PDF] analyse d'un bilan financier pdf
[PDF] analyse des facteurs de motivation du personnel
[PDF] analyse factorielle cours
[PDF] analyse factorielle cours pdf
[PDF] analyse factorielle des correspondances + interprétation
[PDF] analyse factorielle des correspondances + interprétation pdf
[PDF] analyse factorielle des correspondances en anglais
[PDF] analyse factorielle des correspondances exercices corrigés
[PDF] analyse factorielle des correspondances python
[PDF] analyse factorielle des correspondances r
[PDF] analyse factorielle des correspondances spss
[PDF] analyse financière du bilan pdf