Skip to content

Instantly share code, notes, and snippets.

@crossan007
Created May 28, 2022 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crossan007/9bbc1900f859c98fc4795cbc5565d47c to your computer and use it in GitHub Desktop.
Save crossan007/9bbc1900f859c98fc4795cbc5565d47c to your computer and use it in GitHub Desktop.
# https://www.instructables.com/H-Bridge-Motor-Driver-for-Arduino-Using-Transistor/
# https://www.modularcircuits.com/blog/articles/h-bridge-secrets/h-bridges-the-basics/
substitutions:
devicename: water_dispenser
upper_devicename: water dispenser
globals:
- id: water_amount
type: double
initial_value: '0.0'
restore_value: no
- id: last_pulse_count_total
type: int
initial_value: '0'
restore_value: no
sensor:
- platform: pulse_counter
pin: GPIO4
id: flow_meter
update_interval: 100ms
unit_of_measurement: "ml/sec"
total:
id: total_pulses
filters:
- lambda: |-
id(water_amount) = (x - id(last_pulse_count_total)) * id(ml_per_pulse).state;
id(pulses_display).publish_state(x - id(last_pulse_count_total));
id(water_amount_display).publish_state(id(water_amount));
if (id(water_amount) > id(quantity).state) {
id(valve).turn_off();
}
return x;
- platform: template
id: water_amount_display
name: "Water amount"
unit_of_measurement: "ml"
- platform: template
id: pulses_display
name: "Pulses"
switch:
- platform: template
name: Valve
id: valve
optimistic: true
on_turn_on:
- lambda: |-
id(valve_open).turn_on();
id(last_pulse_count_total) = id(total_pulses).state;
id(water_amount) = 0.0;
id(water_amount_display).publish_state(id(water_amount));
- delay: 30ms
- output.turn_off: valve_open
on_turn_off:
- output.turn_on: valve_close
- delay: 30ms
- output.turn_off: valve_close
output:
- platform: gpio
pin: 16
id: valve_open
- platform: gpio
pin: 17
id: valve_close
binary_sensor:
- platform: gpio
name: button1
pin:
number: 32
inverted: true
mode:
input: true
pullup: true
filters:
- delayed_on: 10ms
on_click:
then:
- switch.turn_on: valve
number:
- platform: template
name: Dispense Quantity
id: quantity
min_value: 0
max_value: 2000
initial_value: 10
step: 5
optimistic: true
- platform: template
name: Calibration (Ml/pulse)
min_value: 0.45
max_value: 1.2
step: 0.001
id: ml_per_pulse
initial_value: .576
optimistic: true
<<: !include base_charles.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment