// This code is based on the example code provided by the manufacturer of the TG633 Ingenious Machines Remote Control Building Kits For Kids.
#include <ESP8266WiFi.h> // include the WiFi library
#include <IRremoteESP8266.h> // include the IRremote library for ESP8266
#include <IRsend.h> // include the IRsend library for sending IR signals
// WiFi credentials
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// IR LED pin
const int IR_LED = D1; // IR LED connected to pin D1 on ESP8266
// IR remote codes for controlling the motors
unsigned int motor1_forward = 0x00FF629D; // code for motor 1 moving forward
unsigned int motor1_backward = 0x00FFA857; // code for motor 1 moving backward
unsigned int motor2_forward = 0x00FF22DD; // code for motor 2 moving forward
unsigned int motor2_backward = 0x00FFC23D; // code for motor 2 moving backward
// create an instance of IRsend
IRsend irsend(IR_LED);
void setup() {
// initialize serial communication for debugging
Serial.begin(9600);
// connect to WiFi network
WiFi.begin(ssid, password);
Serial.print("Connecting to ");
Serial.print(ssid);
// wait for WiFi connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// print WiFi connection details
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// check for incoming IR signals
if (irrecv.decode()) {
// print the received IR code for debugging
Serial.println(irrecv.decodedIRData.command);
// check if the received code is for motor 1 moving forward
if (irrecv.decodedIRData.command == motor1_forward) {
// send the IR code to the motor 1
irsend.sendNEC(motor1_forward);
// print a message for debugging
Serial.println("Motor 1 moving forward");
}
// check if the received code is for motor 1 moving backward
else if (irrecv.decodedIRData.command == motor1_backward) {
// send the IR code to the motor 1
irsend.sendNEC(motor1_backward);
// print a message for debugging
Serial.println("Motor 1 moving backward");
}
// check if the received code is for motor 2 moving forward
else if (irrecv.decodedIRData.command == motor2_forward) {
// send the IR code to the motor 2
irsend.sendNEC(motor2_forward);
// print a message for debugging
Serial.println("Motor 2 moving forward");
}
// check if the received code is for motor 2 moving backward
else if (irrecv.decodedIRData.command == motor2_backward) {
// send the IR code to the motor 2
irsend.sendNEC(motor2_backward);
// print a message for debugging
Serial.println("Motor 2 moving backward");
}
// resume receiving IR signals
irrecv.resume();
}
}
// This code is based on the example code provided by the manufacturer of the TG633 Ingenious Machines Remote Control Building Kits For Kids.