An interesting and funny toy on the microcontroller was invented and made by the Master. This is a spider that is at rest in the dark, but if a ray of light falls on it, it tries to escape. To make such a toy, the master used a minimum of details.
-Microcontroller Seeeduino XIAO;
-Vibromotor;
-Light sensor;
-Resistors (for legs);
-Source of power;
Of the tools you need soldering accessories and wire cutters.
Let's see how the device works.
For power supply, the microcontroller needs 3.3 V. When assembling, you need to correctly position the parts, taking into account balancing.
The master makes legs from resistors.
After the assembly, you need to download the code.
const int lightPin = 2;
const int motor = 3;
int lightState = 0;
void setup () {
pinMode (motor, OUTPUT);
pinMode (lightPin, INPUT);
}
void loop () {
lightState = digitalRead (lightPin);
if (lightState == HIGH) {
digitalWrite (motor, HIGH);
}
else {
digitalWrite (motor, LOW);
}
}
All is ready. Now you need to install the spider on a flat surface, turn on the power and turn off the light. When the light beam is directed at the photoresistor, the vibromotor starts to work, and the spider slides to the side on its thin legs.