In this build, we'll explore how to use the CodeCell's onboard proximity sensor to detect depth gestures and control two FlatFlaps, varying their angles based on the proximity values. This project demonstrates a unique way to create interactive robots, actuators, motors or light that respond to hand movements.
The CodeCell is equipped with a VCNL4040 proximity sensor that can measure distances up to 20 cm. By using an infrared light, the sensor detects objects within its range, measuring the reflection of emitted IR light to approximate distance. This allows you to create responsive behaviors based on how close an object is, making it ideal for interactive gestures.
Depth gestures are based on the proximity data from the CodeCell's onboard sensor. By moving your hand or other objects closer or further from the sensor, you can create dynamic inputs that drive various actions. In this project, the proximity data is used to control the angle of two FlatFlaps, which are connected to two DriveCells (H-bridge drivers).
In this example, the CodeCell continuously reads proximity data and adjusts the angle of two FlatFlaps based on how close the object is. As the object moves closer or further, the angle of the FlatFlaps changes, demonstrating a simple yet effective method for depth gesture-based control.
The two FlatFlaps, are soldered to two DriveCells (H-bridge drivers), which are pin to pin compatible with the CodeCell. These components are then connected on 3D printed mount, to create a cute little Flappy-Bot! Don't forget to add a googly-eye to give it more personality!
Below is the example code to get you started. Ensure your CodeCell is properly connected via USB-C, and the FlatFlaps are connected to the two DriveCells. Follow the comments in the code to understand each step.
#include <CodeCell.h>
#include <DriveCell.h>
#define IN1_pin1 2
#define IN1_pin2 3
#define IN2_pin1 5
#define IN2_pin2 6
DriveCell FlatFlap1(IN1_pin1, IN1_pin2);
DriveCell FlatFlap2(IN2_pin1, IN2_pin2);
CodeCell myCodeCell;
void setup() {
Serial.begin(115200); // Set Serial baud rate to 115200. Ensure Tools/USB_CDC_On_Boot is enabled if using Serial.
myCodeCell.Init(LIGHT); // Initializes Light Sensing
FlatFlap1.Init();
FlatFlap2.Init();
FlatFlap1.Tone();
FlatFlap2.Tone();
}
void loop() {
if (myCodeCell.Run()) {
// Runs every 100ms
uint16_t proximity = myCodeCell.Light_ProximityRead();
Serial.println(proximity);
if (proximity < 100) {
// If proximity is detected, the FlatFlaps flap
FlatFlap1.Run(1, 100, 400);
FlatFlap2.Run(1, 100, 400);
} else {
// Adjust FlatFlap angle based on proximity
proximity = proximity - 100;
proximity = proximity / 10;
if (proximity > 100) {
proximity = 100;
}
FlatFlap1.Drive(0, proximity);
FlatFlap2.Drive(0, proximity);
}
}
}
This project shows how to use the CodeCell's proximity sensor for depth gestures, driving the angles of FlatFlaps based on object distance. Experiment with the code, customize the parameters, and bring your own flappy bot to life!
Be the first to know about new projects and get exciting deals!
© 2024 Microbots.