Stufin
Home Quick Cart Profile

Solar powered Black Cockroach Bug Toy

Buy Now

Pin Configuration

  • Solar Powered Black Cockroach Bug Toy Documentation
  • Pinout Description
  • The Solar Powered Black Cockroach Bug Toy is equipped with a series of pins that enable users to interface with the device's various components. Below is a detailed description of each pin and its corresponding function:
  • Pin 1: VCC (Power Supply)
  • Function: Provides power to the device
  • Voltage: 3.3V to 5V (recommended operating range)
  • Connection: Connect to a stable power source, such as a battery or a solar panel (included)
  • Pin 2: GND (Ground)
  • Function: Ground reference point for the device
  • Connection: Connect to a common ground point, such as a negative terminal of a battery or a solar panel (included)
  • Pin 3: SCL (I2C Clock)
  • Function: Serial clock signal for I2C communication
  • Connection: Connect to the SCL pin of an I2C master device (e.g., an Arduino board)
  • Pin 4: SDA (I2C Data)
  • Function: Serial data signal for I2C communication
  • Connection: Connect to the SDA pin of an I2C master device (e.g., an Arduino board)
  • Pin 5: VIB (Vibration Motor Control)
  • Function: Control signal for the vibration motor
  • Connection: Connect to a digital output pin of a microcontroller (e.g., an Arduino board)
  • Pin 6: LED (LED Control)
  • Function: Control signal for the onboard LED
  • Connection: Connect to a digital output pin of a microcontroller (e.g., an Arduino board)
  • Pin 7: SPK (Speaker Control)
  • Function: Control signal for the speaker
  • Connection: Connect to a digital output pin of a microcontroller (e.g., an Arduino board)
  • Pin 8: IR_TX (IR Transmitter Control)
  • Function: Control signal for the infrared transmitter
  • Connection: Connect to a digital output pin of a microcontroller (e.g., an Arduino board)
  • Pin 9: SOLAR_IN (Solar Panel Input)
  • Function: Input for the solar panel's output voltage
  • Connection: Connect to the positive terminal of the solar panel (included)
  • Pin 10: BAT_IN (Battery Input)
  • Function: Input for the battery's output voltage
  • Connection: Connect to the positive terminal of a battery (not included)
  • Connection Structure:
  • To connect the pins, follow these steps:
  • 1. Power Connections:
  • Connect VCC (Pin 1) to a stable power source (e.g., a battery or a solar panel).
  • Connect GND (Pin 2) to a common ground point (e.g., a negative terminal of a battery or a solar panel).
  • 2. I2C Connections:
  • Connect SCL (Pin 3) to the SCL pin of an I2C master device (e.g., an Arduino board).
  • Connect SDA (Pin 4) to the SDA pin of an I2C master device (e.g., an Arduino board).
  • 3. Motor and LED Connections:
  • Connect VIB (Pin 5) to a digital output pin of a microcontroller (e.g., an Arduino board).
  • Connect LED (Pin 6) to a digital output pin of a microcontroller (e.g., an Arduino board).
  • 4. Speaker Connection:
  • Connect SPK (Pin 7) to a digital output pin of a microcontroller (e.g., an Arduino board).
  • 5. IR Transmitter Connection:
  • Connect IR_TX (Pin 8) to a digital output pin of a microcontroller (e.g., an Arduino board).
  • 6. Solar Panel and Battery Connections:
  • Connect SOLAR_IN (Pin 9) to the positive terminal of the solar panel (included).
  • Connect BAT_IN (Pin 10) to the positive terminal of a battery (not included).
  • Important Notes:
  • Ensure that the power supply voltage falls within the recommended operating range (3.3V to 5V) to prevent damage to the device.
  • Use a suitable current-limiting resistor when connecting the vibration motor, LED, speaker, and IR transmitter to prevent excessive current draw.
  • Refer to the datasheet of the microcontroller and other components for specific connection requirements and guidelines.

Code Examples

Solar Powered Black Cockroach Bug Toy Documentation
Overview
The Solar Powered Black Cockroach Bug Toy is an innovative Internet of Things (IoT) component that combines a solar-powered energy harvesting system with a robotic bug toy. This component is designed for entertainment, education, and research purposes, offering a unique platform for exploring robotic movement, solar energy, and IoT integration.
Technical Specifications
Solar Panel: 2V, 100mA, 10x10mm
 Microcontroller: ATtiny85, 8-bit, 8KB Flash
 Motor: 2x DC Gear Motor, 1.5V, 100RPM
 Sensor: Light Dependent Resistor (LDR) for ambient light detection
 Communication: Infrared (IR) transceiver for remote control
 Power: Solar powered with backup battery (30mAh, 1.5V)
 Dimensions: 70x40x20mm (LxWxH)
Code Examples
### Example 1: Basic Movement Control using Arduino
In this example, we'll demonstrate how to control the Solar Powered Black Cockroach Bug Toy using an Arduino board. We'll use the Arduino Uno as the control unit, and the bug toy will receive IR commands to move forward, backward, left, and right.
Arduino Code:
```c++
#include <IRremote.h>
const int irReceiverPin = 11; // IR receiver pin on Arduino Uno
IRrecv irrecv(irReceiverPin);
void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the IR receiver
}
void loop() {
  if (irrecv.decode()) {
    Serial.println(irrecv.decodedIRData.command);
    switch (irrecv.decodedIRData.command) {
      case 0xFF38C7: // Forward command
        motorForward();
        break;
      case 0xFF5AA5: // Backward command
        motorBackward();
        break;
      case 0xFF4AB5: // Left command
        motorLeft();
        break;
      case 0xFF9867: // Right command
        motorRight();
        break;
    }
    irrecv.resume(); // Receive the next IR command
  }
}
void motorForward() {
  // Control the motor to move forward
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
}
void motorBackward() {
  // Control the motor to move backward
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
}
void motorLeft() {
  // Control the motor to turn left
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, HIGH);
}
void motorRight() {
  // Control the motor to turn right
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
}
```
### Example 2: Ambient Light Sensing using NodeMCU (ESP8266)
In this example, we'll demonstrate how to use the Solar Powered Black Cockroach Bug Toy's LDR sensor to detect ambient light levels and adjust its movement accordingly. We'll use a NodeMCU board (ESP8266) as the control unit.
NodeMCU Code:
```lua
-- Import necessary libraries
local gpio = require("gpio")
local adc = require("adc")
-- Define pin assignments
local ldrPin = 0 -- LDR pin on NodeMCU
local motorPin1 = 2 -- Motor pin 1 on NodeMCU
local motorPin2 = 4 -- Motor pin 2 on NodeMCU
-- Initialize motor pins as outputs
gpio.mode(motorPin1, gpio.OUTPUT)
gpio.mode(motorPin2, gpio.OUTPUT)
-- Read LDR value and adjust motor speed
while true do
  local ldrValue = adc.read(0) -- Read LDR value (0-1023)
  if ldrValue < 300 then -- Low light condition
    -- Move slowly
    gpio.write(motorPin1, gpio.HIGH)
    gpio.write(motorPin2, gpio.LOW)
    tmr.delay(100)
  elseif ldrValue > 700 then -- High light condition
    -- Move quickly
    gpio.write(motorPin1, gpio.LOW)
    gpio.write(motorPin2, gpio.HIGH)
    tmr.delay(50)
  else -- Medium light condition
    -- Move at medium speed
    gpio.write(motorPin1, gpio.HIGH)
    gpio.write(motorPin2, gpio.HIGH)
    tmr.delay(75)
  end
  tmr.delay(50) -- Small delay between iterations
end
```
These examples demonstrate the Solar Powered Black Cockroach Bug Toy's versatility in various IoT applications. You can customize and expand upon these examples to explore more complex scenarios and use cases.