- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Trigonometric expressions in Arduino

Arduino provides 3 basic trigonometric functions: sin(), cos() and tan(). All other trigonometric expressions can be derived from these three functions.

All the three functions take in angle in radians (type float) as the input. They return a double.

For sin() and cos(), the value is between -1 and 1. The value for tan() has no such bounds.

## Example

The example code below illustrates the use of these functions −

void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println(); float pi = 3.14159; float angle_deg = 30; float angle_rad = angle_deg*pi/180; Serial.println(sin(angle_rad)); Serial.println(cos(angle_rad)); Serial.println(tan(angle_rad)); } void loop() { // put your main code here, to run repeatedly: }

## Output

The Serial Monitor output is −

sin(30°) =1/2, cos(30°) = sqrt(3)/2 = 0.86602, tan(30°) = 1/sqrt(3) = 0.57735. Thus, the values returned are correct.

It will be interesting to see the values printed for 90 degrees, because, tan(90°) is equal to infinity. Let’s try. The Serial Monitor output for the above code, with 30 replaced with 90 is shown below −

As you can see, it printed 7,88,898.12 for tan(90 degrees), which is a very high number. Also note that our pi was defined only till an accuracy of 5 decimal places. So the input to the function was not exactly 90 degrees, but a value very close to it.

- Related Questions & Answers
- Exponential expressions in Arduino
- Expressions for the Trigonometric Fourier Series Coefficients
- Trigonometric Functions in C#
- Trigonometric methods in Java
- Trigonometric Functions in Python
- Trigonometric Functions in Java
- Get the Trigonometric inverse sin in Python
- Get the Trigonometric inverse cosine in Python
- Get the Trigonometric inverse tangent in Python
- Arduino Uno vs Arduino Mega
- Arduino Uno vs Arduino Nano
- Arduino Uno vs Arduino Due
- Arduino Uno vs Arduino Leonardo
- Arduino Uno vs Arduino Micro
- Relation between Trigonometric & Exponential Fourier Series