Question

In: Electrical Engineering

Write a program in Arduino that, when it takes in a voltage range (0 to 5...

Write a program in Arduino that, when it takes in a voltage range (0 to 5 volts), gives a corresponding servo motor angle with a range from 0 to 180 degrees.

Solutions

Expert Solution

To give voltage input we will use a potentiometer that has a range (0-5v), by turning the knob the input voltage will vary. We will display the corresponding servo motor angle for every position change in potentiometer

The Arduino Uno has a 10-bit analog to digital converter. So the analog input values for the range 0 to 5 volt is converted into corresponding decimal values from 0 to 1023 ( 10-bit means 210 values). In the program, we map the values between 0 – 1023 to 0° – 180°. Thus the angle of servo proportionally increments and decrements with the increase and decrease in input value. That is when the knob is at the center position the servo arm will be at 90o.

Arduino Code

#include <Servo.h> //including servo motor libraries
Servo servo1; //creating a servo object to control servo
int potin
void setup()
{
servo1.attach(9); //attaching the signal pin of servo to pin9 of arduino
Serial.begin(9600); //send and receive at 9600baud

}

void loop()
{
potin = analogRead(A0);   //reading potentiometer values at pin A0       
potin = map(potin, 0, 1023, 0, 180);    //mapping voltage values to angles
servo1.write(potin);      //command to servo motor
Serial.print("Angle");
Serial.println(potin); //printing the angle
}

I am attaching image also.


Related Solutions

Consider the "Successive Approximation" based ADC with a 5-bit converter and a voltage range of 0...
Consider the "Successive Approximation" based ADC with a 5-bit converter and a voltage range of 0 to 5.0 volts. Show how it would approximate an incoming analog voltage value of 1.723 volts using a drawing of volts vs. discrete time steps associated with sampling. Show each approximation step (upper and lower bound voltage limits), show final A/D Output in Hex and show Vmin-max and the actual error in this approximation as a voltage and as a percentage of the actual...
Write a Console Java program that inserts 25 random integers in the range of 0 to...
Write a Console Java program that inserts 25 random integers in the range of 0 to 100 into a Linked List. (Use SecureRandom class from java.security package. SecureRandom rand = new SecureRandom(); - creates the random number object rand.nextInt(100) - generates random integers in the 0 to 100 range) Using a ListItreator output the contents of the LinkedList in the reverse order. Using a ListItreator output the contents of the LinkedList in the original order.
Write a Console Java program that inserts 25 random integers in the range of 0 to...
Write a Console Java program that inserts 25 random integers in the range of 0 to 100 into a Linked List. (Use SecureRandom class from java.security package. SecureRandom rand = new SecureRandom(); - creates the random number object rand.nextInt(100) - generates random integers in the 0 to 100 range) Using a ListItreator output the contents of the LinkedList in the original order. Using a ListItreator output the contents of the LinkedList in the reverse order.
Write the following in C language for Arduino: Write a program that turns on the LED...
Write the following in C language for Arduino: Write a program that turns on the LED at 25%, 50%, 75%, 100%, and then 0% brightness with a one second delay in between each change. Remember you are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine the values for...
Write a program that reads a file consisting of students’ test scores in the range 0–200....
Write a program that reads a file consisting of students’ test scores in the range 0–200. It should then determine the number of students having scores in each of the following ranges: 0–24, 25–49, 50–74, 75–99, 100–124, 125–149, 150–174, and 175–200. Output the score ranges and the number of students. (Run your program with the following input data: 76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200,...
Write the following in C language for Arduino: Write a program that increases the LED brightness...
Write the following in C language for Arduino: Write a program that increases the LED brightness in five steps with each press of the button. Remember you are going to using a digital input and the "digitalRead" command. You are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine...
334) An Arduino analog input voltage is 4.320 volts. The Arduino PWM output pin drives a...
334) An Arduino analog input voltage is 4.320 volts. The Arduino PWM output pin drives a low-pass filter, which converts the PWM signal back to an average-DC voltage. Arduino specifications include: I/O voltage ranges of 0 to 5VDC; 10-bit A/D; and 8-bit D/A PWM output. The analog voltage DC input results in an analog output DC volage at the low-pass filter. Determine (Vout - Vin). Arduino functions include: analogRead(), map(), and analogWrite(). The analogRead() and map() use integer I/O.
I got a little problem when i was trying to write a program that takes a...
I got a little problem when i was trying to write a program that takes a hexadecimal number and convert it to a binary number. It just don't give me the right answer. Here's my code: #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> int main(int argc, char *argv[]) { unsigned long int i; i=0xffff; char buffer[65]; sprintf(buffer, "%lud", i); long int x = 0; while (buffer[x]) {    switch (buffer[x]) { case '0': printf("0000"); break; case '1': printf("0001"); break;...
Write a program to run on your Arduino and PortMaster board that will sequentially turn on...
Write a program to run on your Arduino and PortMaster board that will sequentially turn on and off the LED segments, so it resembles Cylon eyes (https://youtu.be/UajcgzK2shQ). Use the millis() construct shown in lecture rather than delay(). The traverse from one side to the other should take about 1 second.
Consider a 12-bit ADC with an analog input voltage range of 0 to 3 volts. a)...
Consider a 12-bit ADC with an analog input voltage range of 0 to 3 volts. a) Compute the ADC precision, ADC ranges for input and output, and ADC resolution. b) What is the binary value computed by the ADC for an analog input voltage of 1.0 volt? c) Write an ADC0_In function in C that uses busy-wait synchronization to sample the ADC. The function reads the ADC output, and returns the 12-bit binary number. Assume the ADC has already been...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT