Ollie Smeenk
Published

Using a Potentiometer with SODAQ to measure an angle

You will learn about how an analog wind sensor could collect data, and to display information on the serial monitor of the IDE.

Full instructions provided1,170
Using a Potentiometer with SODAQ to measure an angle

Things used in this project

Hardware components

SODAQ Moja
×1
0.5W Solar Panel
×1
1aH battery pack
×1
Grove Rotary Angle Sensor
×1
Grove w/o Buckle Cable (any length)
×1

Story

Read more

Code

code.c

C/C++
code.c
#define ROTARY_ANGLE_SENSOR A0
#define ADC_REF 3.3 //reference voltage of ADC is 3v3
#define GROVE_VCC 5 //VCC of the grove interface is normally 5v
#define FULL_ANGLE 300 //full value of the rotary angle is 300 degrees
 
void setup()
{
 Serial.begin(9600);
 pinsInit();
}
 
void loop()
{
 int degrees; degrees = getDegree();
 Serial.println("The angle between the mark and the starting position:");
 Serial.println(degrees); delay(500);
}
 
void pinsInit()
{
 pinMode(ROTARY_ANGLE_SENSOR, INPUT);
}
 
int getDegree()
{
 int sensor_value = analogRead(ROTARY_ANGLE_SENSOR);
 float voltage;
 voltage = (float)sensor_value*ADC_REF/1023; 
 float degrees = (voltage*FULL_ANGLE)/GROVE_VCC; return degrees;
}

Credits

Ollie Smeenk
8 projects • 6 followers
Business-oriented Tinkerer! Ready to engage in any project for- and not for profit!

Comments