Simple Coding for Hall Effect/Servo Project.

Hi Guys, I previously posted another topic on the forum explain a university project I was planning - Posting again as my first post was primarily about the project . The project I am looking at would allow the Arduino to pick-up an anticipated (Sudden Deceleration) and a locked (Skidding) bike wheel, before telling a servo to rotate (For example) 180 degrees back and forth 5 or so times before waiting for another anticipated/locked wheel and repeating.

On my first post, I received some fantastic help into how the project could be coded.

const byte SENSOR_PIN = 2;
const byte LED_PIN = 13;
const unsigned long LOCKUP_THRESHOLD = 500;
const unsigned long LOCKUP_INDICATOR_TIME = 4000; // four seconds, modify as needed
unsigned long lastSensorTime;
const boolean ACTIVE_STATE = LOW; // change to match sensor
const boolean INACTIVE_STATE = HIGH; // change to match sensor
boolean sensorState = INACTIVE_STATE;

boolean previousSensorState;

void setup() 
{
  pinMode(SENSOR_PIN, INPUT_PULLUP); // change if pull-up isn't needed
  pinMode(LED_PIN, OUTPUT);
  lastSensorTime = millis();
}

void loop()
{
  previousSensorState = sensorState;
  sensorState = digitalRead(SENSOR_PIN);
  if (sensorState != previousSensorState && sensorState == ACTIVE_STATE)
  { 
    lastSensorTime = millis();
  }
  if (millis() - lastSensorTime >= LOCKUP_THRESHOLD)
  {
    lockupAction();
  }
 }

void lockupAction()
{
  digitalWrite(LED_PIN, HIGH);
  delay(LOCKUP_INDICATOR_TIME);

  // reset system to watch for next lockup
  digitalWrite(LED_PIN, LOW);
  sensorState = INACTIVE_STATE;
  lastSensorTime = millis();
}

Looking at the code I generally understand how it works (Complete Arduino/Code novice!), however I am wondering if any of you guys understand what I'm trying to do - The best/simplest way to code the project? Any advice would be fantastic!

Cheers, Tom

tom_donaldson: I am wondering if any of you guys understand what I'm trying to do - The best/simplest way to code the project?

tom_donaldson: before telling a servo to rotate (For example) 180 degrees back and forth 5 or so times before waiting for another anticipated/locked wheel and repeating.

I think there two obvious next steps in your project.

  1. Make sure the code works with your sensor. The code was written using an active low button. Make sure the code will work with the level your sensor outputs.

  2. Learn to control a servo. Get a servo to move the way you want and then have the "lockupAction()" function activate the servo movement.

Have you used the code you have so far on an Arduino?