Такого робота, который умеет ползать по верёвке, можно собрать из LEGO и мотор-редуктора. А чтобы роботом можно было управлять при помощи хлопков в ладоши — нужно только добавить ему «слух» в виде модуля микрофона и контроллера Arduino Nano.
Видео с инструкцией по сборке робота
В качестве драйвера двигателя используется L298N, а модуль микрофона — электретный микрофон с усилителем на MAX4466.
Код прошивки для Arduino
/*
Zipline robot's speed control with clapping
The idea:
In this code, we want to control the speed of our zipline robot with clapping
so that the faster you clap the faster it goes. To do so, we added a microphone
to the project. By measuring the loudness of the environment's sound, we determine
whether the robot must stop or go.
The circuit:
- In this circuit, an Arduino nano is used. Any other types of Arduino
can be used of course but do not forget to change the pin configurations
if you want to change the circuit on your preference.
Visit Tart Robotics blog for more information:
https://www.tartrobotics.com/blog
*/
#define micPin A6
#define motorPinA 9
#define motorPinB 10
#define motorPinPWM 11
void setup() {
// Initialize Arduino pins to outputs
pinMode(motorPinA, OUTPUT);
pinMode(motorPinB, OUTPUT);
pinMode(motorPinPWM, OUTPUT);
}
unsigned int sample, clapTime = 0;
void loop() {
unsigned long samplingBeginning = millis();
unsigned int loudness = 0;
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
// Sample microphone data
while (millis() - samplingBeginning < 100) {
sample = analogRead(micPin);
// Measure min and max value of the signal
if (sample > signalMax)
signalMax = sample;
else if (sample < signalMin)
signalMin = sample;
}
loudness = signalMax - signalMin;
// Referesh the clapTime if a clap is detected
if (peakToPeak > 300)
clapTime = millis();
// Run the motor if a clap is detected recently
if (millis() - clapTime < 200)runTheMotor();
else stopTheMotor();
}
// Motor driver pin configuration to run
void runTheMotor() {
digitalWrite(motorPinA, HIGH);
digitalWrite(motorPinB, LOW);
analogWrite(motorPinPWM, 255);
}
// Motor driver pin configuration to stop
void stopTheMotor() {
digitalWrite(motorPinA, HIGH);
digitalWrite(motorPinB, HIGH);
analogWrite(motorPinPWM, 0);
}
Комментарии (0)
RSS свернуть / развернутьТолько зарегистрированные и авторизованные пользователи могут оставлять комментарии.