How to Measure Tilt Angle Using a SCA60C Angle Sensor and Take Action Based on the Angle

How to Measure Tilt Angle Using a SCA60C Angle Sensor and Take Action Based on the Angle

Mastering Angle Measurement with the SCA60C Tilt Sensor and Arduino

In a detailed tutorial, robotics expert Ahmad Shamshiri of Robojax introduces the VTI Technologies SCA60C tilt sensor, a versatile and inexpensive module for measuring angles. This article, written on March 17, 2020, in Ajax, Ontario, Canada, is based on his video tutorial. This sensor is an excellent tool for a wide range of applications, especially in robotics where knowing the precise orientation of a component is often critical.

tilt angle sensor

This article will walk you through the features of the SCA60C module, how to wire it to an Arduino, and how to use the provided code to get it up and running.

Sensor Overview

The core of this module is the SCA60C angle sensor, which can measure angles from 0 to 180 degrees. It accomplishes this by outputting an analog voltage that changes based on its tilt. This voltage can be read by a microcontroller like an Arduino and converted into a precise angle. The sensor boasts a resolution of one degree, meaning it cannot measure fractional degrees.

Beyond simple angle measurement, the module includes a handy alarm feature. It has two onboard LEDs and corresponding digital outputs (D1 and D2) that can be triggered when the sensor deviates from a pre-set "flat" position. This is managed by an LM393 comparator chip and can be calibrated using two small potentiometers.

As noted in the video, these modules are widely available from online retailers like AliExpress, Amazon, and eBay.

Wiring the SCA60C to an Arduino

Connecting the sensor to your Arduino is simple. The video provides a clear demonstration at 00:05:07.

  • VCC: Connect this to the 5V pin on your Arduino.
  • GND: Connect this to any GND (Ground) pin on the Arduino.
  • VO (Voltage Out): This is the analog output that provides the angle reading. Connect it to an analog input pin on your Arduino. The provided code uses pin A0.
  • D1 Out & D2 Out (Optional): These are for the alarm functions. If you wish to use them, connect them to two other analog pins. The sample code uses A1 for D1 and A2 for D2. If you don't need the alarm feature, you can leave these disconnected to save pins for other uses.

Diving into the Arduino Code

The provided code is well-structured and easy to understand. It reads the sensor, processes the data, and displays it on the serial monitor.

Global Variables & Setup

At the beginning of the sketch, essential variables are defined:

const int anglePin =A0;
int angle =0;
const int angleCompensate =0;

const int d1Pin =A1;
int d1State =LOW;
int d1Delay =0;

const int d2Pin =A2;
int d2State =LOW;
int d2Delay =0;

char *lables[]={"Angle","Alarm D1","Alarm D2"};

The angleCompensate variable is particularly powerful. As shown at 00:08:49 in the video, you can change this value to recalibrate the sensor's "zero" point. For example, if you mount the sensor vertically and want that to be your 0-degree reference, you can set angleCompensate to 90 or -90. This provides immense flexibility for custom installations.

The setup() function simply initializes serial communication so you can view the output:

void setup()
{
  Serial.begin(9600);
  Serial.println("Robojax SCA60C Angle Sensor");
}

Core Functions

The magic happens in the getAngle() function:

void getAngle()
{
   angle =map(analogRead(A0), 96, 927, -90, 90) + angleCompensate;
}

This single line reads the raw analog value from pin A0 and uses the map() function to convert it. The values 96 and 927 represent the raw analog readings that correspond to the sensor's -90 and +90 degree limits. The function scales the input value into this degree range and then adds the angleCompensate value for calibration.

The d1Alarm() and d2Alarm() functions are used to read the state of the alarm pins. As demonstrated at 00:11:00, when the sensor is tilted enough to trigger an alarm LED, the corresponding digital output pin's voltage drops. This code reads that voltage, and if it falls below a 3.5V threshold, it sets the corresponding state variable (e.g., d1State) to HIGH. You can use this state change in your main loop to trigger other actions.

void d1Alarm()
{
  float vo = analogRead(d1Pin) * (5.0 / 1023.0);
  if(vo < 3.5)
  {
    d1State =HIGH;
    delay(d1Delay);    
  }else{
    d1State =LOW;    
  }
}

Putting It All Together

The main loop() function orchestrates everything:

void loop(){
  getAngle();
  d1Alarm();
  d2Alarm();

  Serial.print(lables[0]);
  Serial.print(":");
  Serial.print(angle);
  Serial.println("\xC2\xB0");

  delay(100);
}

In each cycle, it calls the functions to get the angle and check the alarms. It then neatly prints the current angle to the serial monitor, followed by a degree symbol. A 100-millisecond delay keeps the output readable and prevents flooding the serial port.

By following this guide and the excellent visual demonstration in the Robojax video, you can easily incorporate the SCA60C tilt sensor into your next Arduino project, opening up new possibilities for control and interaction.


Video Chapters

  • - Introduction to the SCA60C Angle Sensor
  • - Use Cases for Angle Sensing in Robotics
  • - Explanation of the Module Hardware
  • - Explanation of Module Pins
  • - Wiring to an Arduino
  • - Code Explanation
  • - Live Demonstration of Angle Measurement
  • - How to Use 'angleCompensate' to Calibrate
  • - Demonstration of the Alarm Feature
  • - Using the Sensor Without the Alarm Pins
307-Basic code to control the direction of rotation of a motor with two relays
Language: C++
Copied!

Resources & references

Files📁

No files available.