Search Code

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

This tutorial explores the SCA60C angle sensor, a cost-effective way to measure tilt and orientation in your robotics and electronics projects. The sensor provides an analog voltage output that corresponds to its angle, which an Arduino can read and convert into a precise degree measurement between 0 and 180 degrees. This project is perfect for adding position awareness to a wide range of applications.

SCA60C-tilt-Sensor-1

Here are a few practical ways you can use this sensor in your own builds:

  • Robotic Arm Control: Monitor the position of each joint to ensure precise and safe movement.
  • Leveling Systems: Create a self-leveling platform for cameras, solar panels, or other sensitive equipment.
  • Motion-Activated Alarms: Detect when a device or object is moved from its original, calibrated position.
  • Interactive Art: Build a piece that changes its behavior or display based on how it is tilted.
  • Orientation Feedback: Provide real-time visual feedback on a screen for a device's pitch or roll.
SCA60C_wiring-2

This guide will walk you through the sensor's operation, how to wire it to your Arduino, and how to use the provided code to read and act upon the angle data.

Hardware and Components

To follow along with this project, you will need the following components:

  • Arduino board (Uno, Nano, Mega, etc.)
  • SCA60C Angle Sensor module
  • Breadboard and jumper wires
  • Two LEDs (optional, for alarm demonstration)
  • Two 220-ohm resistors (optional, for LEDs)

The SCA60C sensor is a compact module that outputs a voltage proportional to its tilt angle. As shown in the video, the module also includes an onboard op-amp (LM393) and two potentiometers that can be used to set alarm thresholds, driving the D1 and D2 digital outputs. (in video at 03:20)

Wiring Guide

S02-11-Angle_Sensor_SCA60C_wiring

Wiring the SCA60C sensor is straightforward. Please refer to the diagram below for a visual guide.

Here is the step-by-step connection process:

  1. Power: Connect the VCC pin on the sensor to the 5V pin on your Arduino. Connect the GND pin to the Arduino's GND.
  2. Signal: Connect the Vout pin (the middle pin) to the Arduino's A0 analog input pin. This is the primary pin used for reading the angle. (in video at 05:25)
  3. Alarm Outputs (Optional): The module has two additional digital outputs, D1 and D2. If you wish to use the alarm features, connect these to the Arduino's A1 and A2 pins, respectively. (in video at 05:30)

If you do not need the alarm features, you can leave the D1 and D2 pins disconnected, freeing up the A1 and A2 analog pins for other sensors. (in video at 12:00)

Code Explanation

The provided code is designed to read the analog voltage from the sensor and convert it into an angle in degrees. The most important parts of the code for you to modify are the configuration variables at the top of the sketch.

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

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

const int d2Pin =A2;
int d2State =LOW;
int d2Delay =0;
SCA60C-tilt-Sensor-4

Here is a breakdown of each configurable variable:

  • anglePin: This defines the analog pin on the Arduino that is connected to the sensor's Vout pin. You can change this if you need to use a different analog pin.
  • angleCompensate: This is a crucial variable for calibration. The sensor outputs 0 degrees when it is perfectly flat. If your application requires the sensor to be mounted at an angle, you can add a degree offset here. For example, setting this to 20 will make the sensor read 0 degrees when it is physically tilted at 20 degrees. (in video at 06:24)
  • d1Pin and d2Pin: These define the analog pins used to read the state of the sensor's alarm outputs. If you are not using the alarm feature, you can ignore these.
  • d1Delay and d2Delay: These variables introduce a delay in milliseconds after an alarm is triggered. This can be useful for debouncing or for ensuring an alarm condition persists for a minimum amount of time. (in video at 06:48)

You can also modify the lables[] array to change the text printed on the Serial Monitor. For example, you could change "Angle" to "Robot Arm Position" to better suit your project. (in video at 07:08)

Live Project Demonstration

SCA60C_arduino_showing_angle

In the video, the sensor is demonstrated by moving it through its range of motion while the serial monitor displays the corresponding angle. The presenter shows how the sensor reads zero degrees when flat, and how it can measure up to 90 degrees in one direction and -90 degrees in the other. (in video at 08:05)

The demonstration also highlights the alarm feature. By adjusting the onboard potentiometers, the D1 and D2 outputs can be configured to trigger when the sensor is tilted away from its zero-degree position. The code reads these digital outputs and displays their state (HIGH or LOW) on the serial monitor, which can be used to trigger other actions in your project. (in video at 10:29)

SCA60C-tilt-Sensor--2-dimensions

Chapters

  • [00:00] Introduction to the SCA60C Angle Sensor
  • [00:52] Applications and Use Cases for Angle Sensing
  • [02:19] Understanding the SCA60C Module and its Components
  • [04:56] Wiring Guide for the SCA60C Sensor
  • [06:09] Code Explanation and Configuration Variables
  • [08:05] Live Demonstration of Angle Measurement and Calibration
  • [10:29] Demonstration of the D1 and D2 Alarm Features
  • [13:17] Conclusion

Images

SCA60C-tilt-Sensor-3
SCA60C-tilt-Sensor-3
SCA60C-tilt-Sensor--2-dimensions
SCA60C-tilt-Sensor--2-dimensions
SCA60C-tilt-Sensor-1
SCA60C-tilt-Sensor-1
SCA60C-tilt-Sensor-4
SCA60C-tilt-Sensor-4
S02-11-Angle_Sensor_SCA60C_wiring
S02-11-Angle_Sensor_SCA60C_wiring
SCA60C_arduino_showing_angle
SCA60C_arduino_showing_angle
SCA60C_wiring-2
SCA60C_wiring-2
553-Lesson 18, Robojax Arduino Step-by-Step Course: Using Tilt Angle Sensor SCA60C1
Language: C++
/*
 *  Robojax Arduino Step By Step Course
 * Tilt Angle Sensor SCA60C1 SCA60C N1000060
 * It displays the angle from 0 to 180 degrees.
 * 
  Please watch video instruction here https://youtu.be/hkhepVzWyWE
Download and resource page https://robojax.com/RJT874
Download and resource page https://robojax.com/RJT18


 

 * 
Written by Ahmad Shamshiri on Mar 17, 2020 at 20:20 
 
 * in Ajax, Ontario, Canada. www.robojax.com


If you found this tutorial helpful, please support me so I can continue creating 
content like this. 

 *  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been downloaded from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

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

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

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

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

void setup()

{

  Serial.begin(9600);          //  setup serial
  Serial.println("Robojax SCA60C Angle Sensor");

}



void loop(){
  //Robojax Tilt Angle Sensor
  	//Robojax Arduino Step By Step Course http://robojax.com/L/?id=338
  getAngle();
  d1Alarm();
  d2Alarm();
  
  
  // print out the value you read:
  Serial.print(lables[0]);// 
  Serial.print(":");
  Serial.print(angle);
  Serial.println("\xC2\xB0");//degree symbol
//  Serial.print("\t");
//  Serial.print(lables[1]);
//  Serial.print(":");  
//  Serial.print(d1State);
//  Serial.print("\t");
//  Serial.print(lables[2]);
//  Serial.print(":");
//  Serial.println(d2State);  
//  Serial.println("======");
  delay(100);
//Robojax Tilt Angle Sensor
}

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

/**************************************/
/*! 
    @brief  Get the state of the D1 alarm. HIGH if triggered.
    @param  no parameter
    @returns returns nothing
    Written by Ahmad Shamshiri on Mar 17, 2020 at 20:20 in Ajax, Ontario, Canada.
*/
/**************************************/
void d1Alarm()
{
  	//Robojax Arduino Step By Step Course http://robojax.com/L/?id=338
  //
  float vo = analogRead(d1Pin) * (5.0 / 1023.0);
  if(vo < 3.5)
  {
    d1State =HIGH;
    delay(d1Delay);    
  }else{
    d1State =LOW;    
  }

}//d1Alarm() end


/**************************************/
/*! 
    @brief  Get the state of the D1 alarm. HIGH if triggered.
    @param  no parameter
    @returns returns nothing
    Written by Ahmad Shamshiri on Mar 17, 2020 at 20:20 in Ajax, Ontario, Canada.
*/
/**************************************/
void d2Alarm()
{
  	//Robojax Arduino Step By Step Course http://robojax.com/L/?id=338
  //
  float vo = analogRead(d2Pin) * (5.0 / 1023.0);

  if(vo < 3.5)
  {
    d2State =HIGH;
    delay(d2Delay);    
  }else{
    d2State =LOW;    
  }  

}//d1Alarm() end

Things you might need

Resources & references

No resources yet.

Files📁

Datasheet (pdf)