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.

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 – 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.