Write me some MicroPython code to detect a object within 100cm, open a servo and trigger an LED Matrix
Budget: $30 – $250 AUD
Our mountain bike events see individual riders race against the clock on multiple trails in a staged race.
As part of racing, an individual rider will approach a stop sign.
The rider must come to a complete stop to ensure they are all starting at the same location and not getting any unfair advantage.
To control riders approaching the stop sign, we are creating a physical ‘control gate’ which is a physical rod (like wooden dowel) attached to a servo motor.
On this rod, we would like to mount the sonar sensor so we know when a rider is approaching.
The sonar sensor would detect a rider who is 100cm away.
We then wait for 5 seconds to ensure the rider has come to a complete stop.
Then the gate will swing open 90 degrees and stay open for 5 seconds so we know the rider has departed and then the gate will return to close (0 degrees)
Then a timer starts.
After 10 seconds, a row on the LED matrix will turn on.
After 20 seconds, the next row on the LED matrix will also turn on.
After 30 seconds, the next row on the LED matrix will also turn on.
After 40 seconds, the next row on the LED matrix will also turn on.
After 50 seconds, the next row on the LED matrix will also turn on.
This LED display helps the riders know how long it has been since the last rider has departed to create some ‘racing space’ between individual riders.
This LED display can be interrupted at anytime if a rider approaches. The sonar senor can detect a rider if it returns 2 readings less than 100cm within 2 seconds. I think this will ensure the rider has slowed or come to a stop at the gate.
Based on the above description, I believe the MicroPython coding will be something like:
- Gate set closed (0 degrees)
- Start LED Timer and turn each row on after 10 seconds
- If Sonar sensor detects two readings within 2 seconds (for error check?) less than 100cm away, count to 5 seconds
- After 5 seconds, open gate 90 degrees and wait 5 seconds
- Close gate
- Restart LED Timer
We do not need Bluetooth or wifi and they can be disabled to save battery. In future, we would like to add a physical button that when pushed causes the LED Matrix to flash red indicating the stage is closed and disable the gate operation.
Additionally in future, we would like the device to be connected via wifi, read a cell in a Google Sheet file which would remotely trigger the ‘stage closed’ LED Matrix Red Flashing.
Hardware
WEMOS D1 ARUDINO COMPATIBLE ESP8266
DUINOTECH 40 RGB LED MATRIX SHIELD (this has been chosen for ease and availability)
HC-SR04 SONAR SENSOR
UNKNOWN SERVO SPECIFICATIONS (probably can be any servo I believe)
As part of racing, an individual rider will approach a stop sign.
The rider must come to a complete stop to ensure they are all starting at the same location and not getting any unfair advantage.
To control riders approaching the stop sign, we are creating a physical ‘control gate’ which is a physical rod (like wooden dowel) attached to a servo motor.
On this rod, we would like to mount the sonar sensor so we know when a rider is approaching.
The sonar sensor would detect a rider who is 100cm away.
We then wait for 5 seconds to ensure the rider has come to a complete stop.
Then the gate will swing open 90 degrees and stay open for 5 seconds so we know the rider has departed and then the gate will return to close (0 degrees)
Then a timer starts.
After 10 seconds, a row on the LED matrix will turn on.
After 20 seconds, the next row on the LED matrix will also turn on.
After 30 seconds, the next row on the LED matrix will also turn on.
After 40 seconds, the next row on the LED matrix will also turn on.
After 50 seconds, the next row on the LED matrix will also turn on.
This LED display helps the riders know how long it has been since the last rider has departed to create some ‘racing space’ between individual riders.
This LED display can be interrupted at anytime if a rider approaches. The sonar senor can detect a rider if it returns 2 readings less than 100cm within 2 seconds. I think this will ensure the rider has slowed or come to a stop at the gate.
Based on the above description, I believe the MicroPython coding will be something like:
- Gate set closed (0 degrees)
- Start LED Timer and turn each row on after 10 seconds
- If Sonar sensor detects two readings within 2 seconds (for error check?) less than 100cm away, count to 5 seconds
- After 5 seconds, open gate 90 degrees and wait 5 seconds
- Close gate
- Restart LED Timer
We do not need Bluetooth or wifi and they can be disabled to save battery. In future, we would like to add a physical button that when pushed causes the LED Matrix to flash red indicating the stage is closed and disable the gate operation.
Additionally in future, we would like the device to be connected via wifi, read a cell in a Google Sheet file which would remotely trigger the ‘stage closed’ LED Matrix Red Flashing.
Hardware
WEMOS D1 ARUDINO COMPATIBLE ESP8266
DUINOTECH 40 RGB LED MATRIX SHIELD (this has been chosen for ease and availability)
HC-SR04 SONAR SENSOR
UNKNOWN SERVO SPECIFICATIONS (probably can be any servo I believe)