Garage distance sensor

20250316_040957232_iOS

My latest project is creating a garage distance sesnor. The idea is that as you drive yoru car into the garage it will tell the distnace to the wall, so you can get the alignment just right. It does this in two ways, firstly via an LED display of the distance in mm from the and secondly from a Christmas tree style set of lights to give you a visual idea of whether you are in the zone.

Screenshot 2025-03-17 212404

The rough circuit diagram is shown above.

For this project I’m using at:

Adafruit VL53L1X Time of Flight Distance Sensor – ~30 to 4000mm – STEMMA QT / Qwiic

SparkFun Qwiic Alphanumeric Display – Pink

Breadboard Compatible Potentiometer (10k Ohm)

Arduino Uno R3

some resistors, LEDs and a switch.

The code is here:

https://github.com/directorcia/Azure/blob/master/Iot/Arduino%20Uno%20R3/Garage%20distance/main.cpp

and now that I have it working, at least in beta, I’ll detail a bit more about the development process so far and what I’d like to ultimately achieve in upcoming posts, so stay tuned.

Keyestudio Red and Green Module

A few articles back, while working on the Keyestudio Sun Follow kit, the LED module provided failed. Strangely, it was just the LED. In the end, I just soldered another LED into the board to get it working.

After some searching around it appears that you can buy direct from Keyestudios. Searching their site I found:

Screenshot 2025-02-17 125307

Red and Green LED module

So I bought two and I’m happy to say the arrived as expected. Nice.

Their site has a lot of really cool stuff and I’m going to check it out and maybe buy more based on the very positive experience I’ve had with their Sun Follower kit.

Keyestudio Sun Follower kit

Since the last post on the KS0172 I have completed a number of additional projects:

Light Intensity

Screenshot 2025-02-15 142946

Code = https://github.com/directorcia/Azure/blob/master/Iot/Keyestudio%20KS0172/Lesson_8/main.cpp

Servo motor

Screenshot 2025-02-15 143106

Code =

https://github.com/directorcia/Azure/tree/master/Iot/Keyestudio%20KS0172/Lesson_9.1

and

https://github.com/directorcia/Azure/blob/master/Iot/Keyestudio%20KS0172/Lesson_9.2/main.cpp

This has all been leading up to building this:

Screenshot 2025-02-15 142439

which I have also now completed. The code is here:

https://github.com/directorcia/Azure/blob/master/Iot/Keyestudio%20KS0172/Lesson%2011/main.cpp

I still need to get a

Polymer Lithium Ion Battery, 18650 Cell (3.7V 2600mAh)

so it can run stand alone rather than plugged into a USB port to provide power, however it does work! Yippee!

I think this kit is a great starter option and I would have been much better off commencing my IoT journey here rather than going hard core with just a single processor. The way the kit takes your through individual components and concepts, all building to the final sun follower was fantastic. The instructions were easy to follow, provide great information making it super simple to move through all the steps.

This was my first time actually using an Arduino development board and I can now understand why it is such a popular option. There is no soldering, all you need to do is plug and play. The connections are colour coded and easy to access and understand. Reflecting on how easy this kit an dteh Arduino controller is make me regret going down the route I took and the extra hassle, such as soldering pins, to get my initial projects to even work. Geeze, I did it the hard way.

The challenge is that unless you know someone skilled in IoT you won’t know where to start. However, starting with something like this is really the way to go I would suggest. It allows to grasp the concepts and see results quickly which no only reinforces learning but makes things far less frustrating due to something like a bad soldering joint. I just wish someone had recommended I start with a project like this rather than they way I did.

I’m now a big fan of the Arduino development board and will be looking ot utilise it in a few upcoming projects I have in mind. I think the Arduino is also going to let me resurrect my stalled Arducam Mega camera project. However, if you are looking to get into IoT then look no further than the Keyestudio DIY Solar Tracking Kit I suggest.

Why 2 connectors?

I’ve been planning a project which requires longer distance sensors. The Adafruit VL53L1X seems like it will do the job nicely. However, I was puzzled at what the two inbuilt connectors are on the board given there are also pin options?

Turns out these are Sparkfun qwiic or STEMMA QT connectors.

One STEMMA QT connector typically provides I2C communication (SCL, SDA) and power (VCC and GND), allowing the sensor to communicate with your microcontroller.

Top view of JST SH 4-pin to Premium Male Headers Cable next to US quarter for scale.

For the STEMMA QT cables, typically follow the Qwiic convention:

  1. Black for GND
  2. Red for V+
  3. Blue for SDA
  4. Yellow for SCL

Note the colors are slightly different for SDA/SCL but the pin order is the same

The second STEMMA QT connector is a duplicate of the first, giving you flexibility for different wiring setups or for easier daisy-chaining if you’re connecting multiple devices.

All of this means that I should be able to reduce the amount of soldering I need to do to get the next project operational.

Keyestudio KS0172–Humidity Sensor

I’ve had some previous experience with a temperature sensor on a few other boards:

Adafruit Huzzah temperature sensor

So this project seemed staright forward. The circuit diagram is:

Screenshot 2025-02-04 183750

and the code you will find here:

https://github.com/directorcia/Azure/blob/master/Iot/Keyestudio%20KS0172/Lesson_7/main.cpp

When I tried to use a generic DHT sensor library from the Platformio registry for the project wouldn’t work. I therefore needed to work out how to use thr provide library with Platformio. Turns out that is much easier than I thought!

  1. Inside your PlatformIO project, navigate to the lib/ directory.
  2. Create a new folder, e.g., MyLibrary/.
  3. Inside MyLibrary/, add your library files:
    lib/
    ├── MyLibrary/
    │ ├── src/
    │ │ ├── MyLibrary.h
    │ │ ├── MyLibrary.cpp
    │ ├── library.json (optional)
  4. In your src/main.cpp, include the library:
    #include <MyLibrary.h>
  5. PlatformIO will automatically detect and include the library.

This worked a treat and allowed my code to compile. Major learning there.

Keyestudio KS0172 – LCD display

Screenshot 2025-01-29 134844

Next on the list of projects with the Keyestudio KS0172 board is connecting an LCD display as shown above.

The code for this is here:

https://github.com/directorcia/Azure/blob/master/Iot/Keyestudio%20KS0172/Lesson_5/main.cpp

and the only trick was to add the LiquidCrystal_I2C library, which was easy enough to do in Platformio.

Screenshot 2025-01-29 135357

and the result is shown above.

Next was to configure a light sensor. The code for that is here:

https://github.com/directorcia/Azure/blob/master/Iot/Keyestudio%20KS0172/Lesson_6/main.cpp

Screenshot 2025-01-29 141327

During this process the LED on the add on board failed! Strange. I checked the port, the voltage and whole lot of other stuff, but as far as I can tell the LED itself failed! I therefore used the buzzer as substitute until I decided to ‘bodgy’ another LED I had laying around as a temporary substitute. Why? Well, this LED board is pretty handy for troubleshooting I’ve found.

lesson6

The result is as shown above, both sound and light when the light sensor falls below a certain level.

I can’t find a replacement for the LED board on its own. Seems it only comes with full kits. I’ll need to look at buying a similar LED at some stage and maybe swapping the faulty on out on the board. It will be rather fiddly but worth the effort going forward I reckon.

Keyestudio KS0172–Button

Screenshot 2025-01-28 125142

The next project with the Keyestudio KS0172 board is to connect a button as shown above and observe the effect in the terminal window. The code for this is here:

https://github.com/directorcia/Azure/blob/master/Iot/Keyestudio%20KS0172/Lesson_3.1/main.cpp

Next, is to have the button control the LED like so:

Screenshot 2025-01-28 125612

and the code for this is here:

https://github.com/directorcia/Azure/blob/master/Iot/Keyestudio%20KS0172/Lesson_3.2/main.cpp

and the result looks like:

lesson3-2

The next two projects use a buzzer to make sound like so:

Screenshot 2025-01-28 130331

the code for these two lessons is here:

https://github.com/directorcia/Azure/blob/master/Iot/Keyestudio%20KS0172/Lesson_4.1/main.cpp

and here

https://github.com/directorcia/Azure/blob/master/Iot/Keyestudio%20KS0172/Lesson_4.2/main.cpp

My own attempt with the help of AI is here:

https://github.com/directorcia/Azure/blob/master/Iot/Keyestudio%20KS0172/Lesson_4.3/main.cpp

although it doesn’t really sounds like ‘Smoke on the water” to me, but that is clearly a limit of the equipment not the programmer (ha)!.

Keyestudio KS0172 – Flashing LED

Now that I have the Keyestudio KS0172 board working time for some customisations of the flashing LED.

lesson1-2

First, make it flash faster. That is simply done by delay statement in the code here:

https://github.com/directorcia/Azure/blob/master/Iot/Keyestudio%20KS0172/Lesson_1.2/main.cpp

The lower the number the faster it flashes.

lesson1-3

Next, get the LED to fade in and out. The code for this is here:

https://github.com/directorcia/Azure/blob/master/Iot/Keyestudio%20KS0172/Lesson_2.2/main.cpp

This uses a new function I was not aware of:

The analogWrite function is used in Arduino programming to output a PWM (Pulse Width Modulation) signal to a specified pin. Here’s a detailed explanation:

Purpose

analogWrite is used to control the brightness of an LED or the speed of a motor by varying the duty cycle of the PWM signal.

Syntax

analogWrite(pin, value);

Parameters
  • pin: The pin number to which the PWM signal is sent. This must be a pin that supports PWM (usually marked with a ~ on Arduino boards).

  • value: The duty cycle of the PWM signal. It ranges from 0 to 255:
    • 0 means 0% duty cycle (always off).

    • 255 means 100% duty cycle (always on).

    • Values in between correspond to varying levels of on/off time.

This code creates a smooth fade-in and fade-out effect for the LED.

Keyestudio KS0172 Board Projects commence

I came across this kite recently:

Smart Solar Tracker System Tracking Starter Kit or Arduino

Smart Solar Tracker System Tracking Starter Kit For Arduino

Which I thought would be a good opportunity to jump back into things after all teh struggles I’ve had with the Arducam Mega 3MP. I need a few wins to lift my motivation, thus the purchase.

The brains of the kit is a Keyestudio KS0172:

The core processor of this board is ATMEGA328P-AU and ATMEGA16U2 is used as a UART-to-USB conversion chip.

It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16MHz crystal oscillator, a USB connection, a powerjack, 1 ICSP header, and a reset button. All you need to do is connect it to a computer via a USB cable and power it with an external power supply of DC 7-12V

Which seems much easier to interface.

Turns out this kit is actually a series of projects with the board, which is exactly what I wanted. Start simple and then extend.

First step was to get the board working with Platformio environment.

When I plugged the board into my PC it was automatically recognised as Arduino Uno as see above. Thus, when I set up Platformio I select Arduino Uno. This produced the following platformio.ini for me:

[env:uno]
platform = atmelavr
board = uno
framework = arduino

I then wired up the LED board per the instructions in the manual like so:

and uploaded the following code to the board:

https://github.com/directorcia/Azure/blob/master/Iot/Keyestudio%20KS0172/Lesson_1.1/main.cpp

The only change I needed to make to the code that came with the kit was to add:

#include <arduino.h>

to the top.

and I am very happy to report that it all worked as expected upon uploading the code to the boardand seen above.

Now onto the next project in the kit.