Created
September 10, 2021 19:33
-
-
Save danic85/59dbd911374ee9803d3a8c826ff965e7 to your computer and use it in GitHub Desktop.
Arduino Smart Servo (continuous servo voltage monitor)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------------------------------- // | |
// Arduino Smart Servo (continuous servo voltage monitor) | |
// Uses a uses a shunt resistor to create a voltage divider that the arduino can monitor. | |
// When the voltage passes a threshold the servo pauses for a second before continuing. | |
// https://www.instagram.com/p/CTXWAH9jmJE/ | |
// Tested on September 2020 | |
// Author: Dan Nicholson (github.com/danic85) | |
// ---------------------------------------------------------------- // | |
#include <Servo.h> | |
int sensorPin = A0; | |
int sensorValue; | |
Servo myServo; | |
int servoPin = 2; | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(9600); | |
pinMode(INPUT, A0); | |
myServo.attach(servoPin); | |
myServo.writeMicroseconds(60); | |
delay(1000); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
sensorValue = analogRead(sensorPin); | |
Serial.println(sensorValue); | |
delay(15); | |
if (sensorValue > 50) { | |
myServo.detach(); | |
delay(1000); | |
myServo.attach(servoPin); | |
myServo.writeMicroseconds(60); | |
delay(1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment