I am working on designing a robotic car motor vehicle for kids' learning, using an Arduino Nano, VC02, an infrared sensor, and an ultrasonic sensor.
As an initial test, I successfully made the internal LED switch on and operated one motor with a voice command using an Arduino Uno. However, when I tried the same application with the Arduino Nano, it did not work as expected.
The issue with the Nano is that while the VC02 responds to my voice commands, no signals are sent to either the motor or the LED to function. I used the same connections and code that worked on the Uno. Below is the simple code I used to test the motor functionality with the Uno.
Do I need to make any adjustments to the code or setup to make it compatible with the Nano? I would appreciate any guidance or suggestions on what might be causing the issue.
#include <Servo.h>
unsigned int receivedValue = 0;
Servo myservo;
#define PIN_IN1 2
#define PIN_IN2 4
void setup() {
pinMode(PIN_IN1, OUTPUT);
pinMode(PIN_IN2, OUTPUT);
myservo.attach(9);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
Serial.println("Data From VC-02");
byte highByte = Serial.read();
byte lowByte = Serial.read();
receivedValue = (highByte << 8) | lowByte;
// Print the received value in HEX format
Serial.print("Received HEX value: 0x");
Serial.println(receivedValue, HEX);
}
if (receivedValue == 0xA190)
{
digitalWrite(PIN_IN1, HIGH);
digitalWrite(PIN_IN2, LOW);
}
else if (receivedValue == 0xA145) {
digitalWrite(PIN_IN1, LOW);
digitalWrite(PIN_IN2, LOW);
}
else {
}
delay(10);
receivedValue = 0;
}