How to add hysteresis to threshold values?
Adding hysteresis behavior to your code is not difficult. You just need to store the state you're in and make the thresholds for transitioning into another state dependent on that.

You can use an enum to store the state:

enum BatteryStates {
  Red, Orange, Green
};


Then, instead of defining and checking against one threshold value, define two thresholds for each transition, separated by so much that you don't observe the undesired flip-flopping behavior.

For example, when transitioning from Green to Orange you could do something like this:

if ((state == Green) &amp;&amp; (battery &lt; 690))
  state = Orange;


And the other direction would use a slightly higher threshold

if ((state == Orange) &amp;&amp; (battery &gt; 700))
  state = Green;


so that small fluctuations of the voltage do not cause flip-flopping.

(Note that my code assumes

int battery = analogRead(BatteryVoltagePin);


The variable state should be declared and initialized like so:

enum BatteryStates state = Green;


Instead of an enum you could use a simple int and map each state to a number (e.g. red = 1, orange = 2, green = 3), but using enum makes the code easier to read and write. (In fact enum does use integer numbers.)

I might also use a switch statement instead of an if chain to implement the transitions, but that's a matter of taste.)